Summary
When the inner Claude subprocess is about to be killed (idle eviction, /stop, restart), it has no opportunity to save what it learned during the session. Interactive Claude Code sessions do this automatically via auto-memory, but the inner Claude runs in stream-json mode where auto-memory does not function.
A "save prompt" sent before shutdown would give the inner Claude a chance to persist important context to MEMORY.md, replicating the auto-memory save behavior for the headless subprocess.
Proposed approach
Before killing the subprocess, send a final message like:
"Save anything worth remembering from this session to your memory file, then respond with DONE."
Wait for the response (with a short timeout), then proceed with the kill.
Considerations
- Requires sending a message to a subprocess that's about to be killed
- Need to wait for the save to complete before killing (short timeout)
- Must handle the case where the subprocess is unresponsive (timeout and kill anyway)
- The
/stop path needs the kill to be fast - the save prompt adds latency
- Idle eviction is the most natural place for this (the subprocess is about to die anyway, no user waiting)
- Could be limited to idle eviction only, skipping
/stop (which implies urgency)
Depends on
Priority
Low. This is an enhancement for long-term memory building. The explicit memory system (CLAUDE.md + MEMORY.md + history) handles the core use case.
Summary
When the inner Claude subprocess is about to be killed (idle eviction,
/stop, restart), it has no opportunity to save what it learned during the session. Interactive Claude Code sessions do this automatically via auto-memory, but the inner Claude runs in stream-json mode where auto-memory does not function.A "save prompt" sent before shutdown would give the inner Claude a chance to persist important context to MEMORY.md, replicating the auto-memory save behavior for the headless subprocess.
Proposed approach
Before killing the subprocess, send a final message like:
Wait for the response (with a short timeout), then proceed with the kill.
Considerations
/stoppath needs the kill to be fast - the save prompt adds latency/stop(which implies urgency)Depends on
Priority
Low. This is an enhancement for long-term memory building. The explicit memory system (CLAUDE.md + MEMORY.md + history) handles the core use case.