Feature request: pre-compact hook or include last N interactions in compact summary
Summary
When a context compact occurs, the summary generated often loses the most recent conversation exchanges (the last 3-4 questions and answers). This makes it difficult to resume work seamlessly after a compact.
Problem
Currently:
- The compact summary is a high-level overview of the conversation
- The most recent exchanges (which are often the most relevant for continuing work) are summarized or lost
- Users have to manually recover context from the transcript file
Proposed Solutions
Option A: Pre-compact hook (preferred)
Allow users to define a hook that executes before a compact occurs. This would enable:
- Saving session state to a file
- Extracting recent exchanges for later reference
- Any custom pre-compact cleanup
Example configuration in settings.json:
{
"hooks": {
"pre-compact": "python3 /path/to/save_session_state.py"
}
}
Option B: Include last N interactions verbatim in compact summary
Automatically include the last 3-5 user/assistant exchanges verbatim (not summarized) at the end of the compact summary. This preserves the immediate context needed to continue work.
Example format in compact summary:
[... existing summary ...]
## Recent Exchanges (verbatim)
**User**: [last question]
**Assistant**: [last answer]
**User**: [previous question]
**Assistant**: [previous answer]
Use Case
When working on complex coding tasks, the most recent exchanges often contain:
- Specific file paths being discussed
- Decisions just made
- The exact task in progress
- Questions waiting for answers
Losing this context forces users to re-explain or re-discover what was happening.
Workaround Currently Used
After a compact, manually reading the transcript file:
tail -30 <transcript_file> | python3 -c "import sys,json; ..."
This works but is manual and error-prone.
Environment
- Claude Code CLI
- macOS / Linux
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗