Feature request: pre-compact hook or include last N interactions in compact summary

Resolved 💬 3 comments Opened Jan 27, 2026 by genro Closed Jan 30, 2026

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:

  1. The compact summary is a high-level overview of the conversation
  2. The most recent exchanges (which are often the most relevant for continuing work) are summarized or lost
  3. 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

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗