Memory Processor
Process changed files and update relevant CLAUDE.md sections following official guidelines.
Guidelines
MANDATORY: All rules below must be followed exactly. Violations produce incorrect CLAUDE.md content.
@../shared/references/guidelines.md
Algorithm
Parse context: Read context provided by memory-updater agent:
- Changed files with categories
- File content summaries
- Detected dependencies
- Git context (commits, diffs)
- Target CLAUDE.md files
Categorize changes: Map files to CLAUDE.md sections using the tables in "Section Names" below. Match changed files to their update triggers.
Analyze impact: Determine what needs updating:
- New build commands added?
- Architecture changed (new dirs, renamed components)?
- New coding patterns detected?
- Dependencies added/removed?
Verify and update content: Before modifying documented content, verify accuracy:
Key distinction - conventions vs patterns:
conventions: Explicit rules humans decided (naming, imports, formatting)
patterns: Implicit patterns AI detected from recurring code structures
Removal verification:
- Read the relevant CLAUDE.md section to get currently documented items
- For each item that appears missing from changed files:
- Use Grep to search the codebase for that item
- Search in relevant directories excluding node_modules, vendor, .git
- If item exists elsewhere: keep it documented
- If item is not found anywhere: mark for removal
Stale command detection:
- Compare documented commands against commands that actually executed successfully
- If documented command differs from successful execution, update to match what worked
- Examples:
- Documented:
python pytest | Actually worked: python -m pytest → Update
- Documented:
npm test | Actually worked: npm run test → Update
- Documented:
pytest tests/ | Actually worked: uv run pytest → Update
- Source: Successful Bash tool executions from session context or git commit history
Examples:
- Pattern:
@decorator removed → search grep -r "@decorator" src/
- Convention:
async/await style removed → search for async function or await
- Architecture:
utils/ directory deleted → verify no utils/ references remain
- Build command:
npm run dev removed from package.json → verify script is gone
Update CLAUDE.md: Modify relevant sections:
- Preserve AUTO-MANAGED markers
- Never touch MANUAL sections
- Apply content rules (specific, concise, structured)
Validate: Ensure updates follow guidelines:
- No generic instructions added
- Specific and actionable content
- Proper markdown formatting
Marker Syntax
CLAUDE.md uses HTML comment markers for selective updates:
<!-- AUTO-MANAGED: section-name -->
Content that will be automatically updated
<!-- END AUTO-MANAGED -->
<!-- MANUAL -->
Content that will never be touched
<!-- END MANUAL -->
Section Names
Root CLAUDE.md Sections
| Section |
Purpose |
Update Triggers |
project-description |
Project overview |
README changes, major refactors |
build-commands |
Build, test, lint commands |
package.json, Makefile, pyproject.toml |
architecture |
Directory structure, components |
New dirs, renamed files, structural changes |
conventions |
Naming, imports, code standards |
Pattern changes in source files |
patterns |
AI-detected coding patterns |
Repeated patterns across files |
git-insights |
Decisions from git history |
Significant commits |
best-practices |
From official Claude Code docs |
Manual updates only |
Subtree CLAUDE.md Sections
| Section |
Purpose |
Update Triggers |
module-description |
Module purpose |
Module README, major changes |
architecture |
Module structure |
File changes within module |
conventions |
Module-specific conventions |
Pattern changes in module |
dependencies |
Key module dependencies |
Import changes, package updates |
Token Efficiency
- Keep sections concise - bullet points, not paragraphs
- Use imports (
@path/to/file) for detailed specs
- Follow Content Rules above (< 500 lines, stay current)
Output
Return a brief summary:
- "Updated [section names] in [CLAUDE.md path] based on changes to [file names]"
- "Removed [pattern] from [section] - no longer used in codebase"
- "No updates needed - changes do not affect documented sections"
1---2name: memory-processor3description: Process file changes and update CLAUDE.md memory sections. Use when the memory-updater agent needs to analyze dirty files, update AUTO-MANAGED sections, verify content removal, or detect stale commands. Invoked after file edits to keep project memory in sync.4---5
6# Memory Processor
7
8Process changed files and update relevant CLAUDE.md sections following official guidelines.
9
10## Guidelines
11
12**MANDATORY**: All rules below must be followed exactly. Violations produce incorrect CLAUDE.md content.
13
14@../shared/references/guidelines.md
15
16## Algorithm
17
181. **Parse context**: Read context provided by memory-updater agent:
19 - Changed files with categories
20 - File content summaries
21 - Detected dependencies
22 - Git context (commits, diffs)
23 - Target CLAUDE.md files
24
252. **Categorize changes**: Map files to CLAUDE.md sections using the tables in "Section Names" below. Match changed files to their update triggers.
26
273. **Analyze impact**: Determine what needs updating:
28 - New build commands added?
29 - Architecture changed (new dirs, renamed components)?
30 - New coding patterns detected?
31 - Dependencies added/removed?
32
334. **Verify and update content**: Before modifying documented content, verify accuracy:
34
35 **Key distinction - conventions vs patterns:**
36 - `conventions`: Explicit rules humans decided (naming, imports, formatting)
37 - `patterns`: Implicit patterns AI detected from recurring code structures
38
39 **Removal verification:**
40 - Read the relevant CLAUDE.md section to get currently documented items
41 - For each item that appears missing from changed files:
42 - Use Grep to search the codebase for that item
43 - Search in relevant directories excluding node_modules, vendor, .git
44 - If item exists elsewhere: keep it documented
45 - If item is not found anywhere: mark for removal
46
47 **Stale command detection:**
48 - Compare documented commands against commands that actually executed successfully
49 - If documented command differs from successful execution, update to match what worked
50 - Examples:
51 - Documented: `python pytest` | Actually worked: `python -m pytest` → Update
52 - Documented: `npm test` | Actually worked: `npm run test` → Update
53 - Documented: `pytest tests/` | Actually worked: `uv run pytest` → Update
54 - Source: Successful Bash tool executions from session context or git commit history
55
56 **Examples:**
57 - Pattern: `@decorator` removed → search `grep -r "@decorator" src/`
58 - Convention: `async/await` style removed → search for `async function` or `await`
59 - Architecture: `utils/` directory deleted → verify no `utils/` references remain
60 - Build command: `npm run dev` removed from package.json → verify script is gone
61
625. **Update CLAUDE.md**: Modify relevant sections:
63 - Preserve AUTO-MANAGED markers
64 - Never touch MANUAL sections
65 - Apply content rules (specific, concise, structured)
66
676. **Validate**: Ensure updates follow guidelines:
68 - No generic instructions added
69 - Specific and actionable content
70 - Proper markdown formatting
71
72## Marker Syntax
73
74CLAUDE.md uses HTML comment markers for selective updates:
75
76```markdown
77<!-- AUTO-MANAGED: section-name -->
78Content that will be automatically updated
79<!-- END AUTO-MANAGED -->
80
81<!-- MANUAL -->
82Content that will never be touched
83<!-- END MANUAL -->
84```
85
86## Section Names
87
88### Root CLAUDE.md Sections
89
90| Section | Purpose | Update Triggers |
91|---------|---------|-----------------|
92| `project-description` | Project overview | README changes, major refactors |
93| `build-commands` | Build, test, lint commands | package.json, Makefile, pyproject.toml |
94| `architecture` | Directory structure, components | New dirs, renamed files, structural changes |
95| `conventions` | Naming, imports, code standards | Pattern changes in source files |
96| `patterns` | AI-detected coding patterns | Repeated patterns across files |
97| `git-insights` | Decisions from git history | Significant commits |
98| `best-practices` | From official Claude Code docs | Manual updates only |
99
100### Subtree CLAUDE.md Sections
101
102| Section | Purpose | Update Triggers |
103|---------|---------|-----------------|
104| `module-description` | Module purpose | Module README, major changes |
105| `architecture` | Module structure | File changes within module |
106| `conventions` | Module-specific conventions | Pattern changes in module |
107| `dependencies` | Key module dependencies | Import changes, package updates |
108
109## Token Efficiency
110
111- Keep sections concise - bullet points, not paragraphs
112- Use imports (`@path/to/file`) for detailed specs
113- Follow Content Rules above (< 500 lines, stay current)
114
115## Output
116
117Return a brief summary:
118- "Updated [section names] in [CLAUDE.md path] based on changes to [file names]"
119- "Removed [pattern] from [section] - no longer used in codebase"
120- "No updates needed - changes do not affect documented sections"