Agent should auto-save expensive research to memory files before context compaction
Problem
When Claude Code performs long, token-intensive research tasks (e.g., web searches, document analysis, terminology comparison across multiple sources), the results exist only in the conversation context. When the context window fills up and gets compacted/summarized, all the detailed research is lost — only a brief summary survives.
The agent has access to a persistent memory/ directory specifically designed for cross-session knowledge retention, but it does not proactively save research results there.
Real-world example
I asked Claude to research Japanese game development terminology across Unity, RPG Maker, Wolf RPG Editor, and SRPG Studio before translating Construct 3 localization files. This took over 1 hour of web searches, document fetching, and comparative analysis, consuming a significant amount of tokens.
The research produced valuable results — a detailed terminology comparison table with sources. However:
- Only a 6-line summary was written into the code (
LANG_RULESdictionary) - The detailed comparison table, sources, and reasoning were not saved to
memory/ - When context was compacted, all details were lost
- When I later asked about a specific term ("Destroy"), the agent had to redo the research from scratch, wasting more tokens
Root cause
The auto-memory guidelines say "save stable patterns confirmed across multiple interactions" — this framing is too conservative and causes the agent to under-value expensive one-time research that is equally worth preserving.
Expected behavior
When the agent performs substantial research (multiple web searches, document fetches, cross-referencing), it should:
- Proactively save detailed findings to
memory/files — not just use them in the moment - Prioritize saving when research has consumed significant tokens (e.g., >5 web search/fetch calls)
- At minimum, save before context gets large enough that compaction is likely
Suggested improvement
Add guidance in the auto-memory system prompt:
When you perform research involving multiple web searches or document analysis (>5 search/fetch calls), proactively save the structured results to a topic-specific memory file. Don't wait for the user to ask — treat expensive research output as an asset worth preserving.
Environment
- Claude Code CLI
- Model: Claude Opus 4.6
- Platform: Windows 11
🤖 Generated with Claude Code
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗