-
-
Notifications
You must be signed in to change notification settings - Fork 397
feat: add plan file context injection with toggle (#180) #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: add plan file context injection with toggle (#180) #251
Conversation
- Add CLAUDE_MEM_CONTEXT_SHOW_LAST_PLAN setting (default: false) - Implement getMostRecentPlanFile() to read latest plan from ~/.claude/plans/ - Inject plan content into context when toggle is enabled - Add setting validation and UI type support Closes thedotmack#180
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds the ability to inject the most recent plan file from ~/.claude/plans/ into the context when enabled via a new setting CLAUDE_MEM_CONTEXT_SHOW_LAST_PLAN. The implementation follows the existing pattern used for CLAUDE_MEM_CONTEXT_SHOW_LAST_SUMMARY and CLAUDE_MEM_CONTEXT_SHOW_LAST_MESSAGE.
Key Changes
- Added new toggle setting
CLAUDE_MEM_CONTEXT_SHOW_LAST_PLAN(defaults tofalse) - Implemented plan file discovery and content injection in context generator
- Extracts plan title from H1 heading for display
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/ui/viewer/types.ts | Added CLAUDE_MEM_CONTEXT_SHOW_LAST_PLAN property to Settings interface |
| src/shared/SettingsDefaultsManager.ts | Added default value for new setting (false) in SettingsDefaults interface and DEFAULTS object |
| src/services/worker/http/routes/SettingsRoutes.ts | Added new setting to allowed keys list and boolean validation |
| src/services/context-generator.ts | Implemented getMostRecentPlanFile() helper function and integrated plan content injection into context output, plus minor indentation formatting improvements |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/services/context-generator.ts
Outdated
| .map((f: string) => ({ | ||
| name: f, | ||
| path: path.join(plansDir, f), | ||
| mtime: statSync(path.join(plansDir, f)).mtime.getTime() | ||
| })) |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The statSync call is being made twice for each file - once in the map function to get the full path and again to retrieve mtime. This can be optimized by first constructing the full path, then calling statSync once per file. Consider restructuring to avoid the redundant filesystem calls.
| .map((f: string) => ({ | |
| name: f, | |
| path: path.join(plansDir, f), | |
| mtime: statSync(path.join(plansDir, f)).mtime.getTime() | |
| })) | |
| .map((f: string) => { | |
| const fullPath = path.join(plansDir, f); | |
| const stat = statSync(fullPath); | |
| return { | |
| name: f, | |
| path: fullPath, | |
| mtime: stat.mtime.getTime() | |
| }; | |
| }) |
|
|
||
| // Extract title from H1 heading | ||
| const titleMatch = content.match(/^#\s+(.+)$/m); | ||
| const title = titleMatch?.[1] || mostRecent.name.replace('.md', ''); |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern /^#\s+(.+)$/m will match the first H1 heading anywhere in the file, but it could match a heading with trailing whitespace. Consider trimming the captured title with .trim() to ensure clean titles, like: const title = titleMatch?.[1]?.trim() || mostRecent.name.replace('.md', '');
| const title = titleMatch?.[1] || mostRecent.name.replace('.md', ''); | |
| const title = titleMatch?.[1]?.trim() || mostRecent.name.replace('.md', ''); |
Address Copilot review suggestion - restructure map function to avoid redundant filesystem calls by only calling statSync once per file instead of twice.
Summary
Implements feature request from #180 - adds the ability to include the most recent plan file from
~/.claude/plans/in the context injection.Changes
Backend - Settings Infrastructure
CLAUDE_MEM_CONTEXT_SHOW_LAST_PLANsetting (default:false)Backend - Context Generator
getMostRecentPlanFile()helper function to read the latest.mdfile from~/.claude/plans/Backend - Settings API
Frontend - UI Types
CLAUDE_MEM_CONTEXT_SHOW_LAST_PLANto Settings interfaceHow It Works
CLAUDE_MEM_CONTEXT_SHOW_LAST_PLANin settings (via~/.claude-mem/settings.jsonor future UI toggle)SessionStart, context-generator reads~/.claude/plans/directory.mdfile (by modification time) is selectedExample Output
Testing
Closes #180