Feature: Pre-compaction hooks and context usage detection

Resolved 💬 3 comments Opened Feb 1, 2026 by jamie8johnson Closed Feb 4, 2026

Summary

Claude Code should provide a way to detect when context compaction is approaching, and allow users to define triggered actions (hooks) that run before compaction occurs.

Use Case

When working on complex multi-session projects, users often need to preserve state in external files (like PROJECT_CONTINUITY.md) before context compaction happens. Currently, this requires:

  1. Manually noticing the context percentage is high
  2. Asking Claude to "update tears" (save state)
  3. Hoping the update completes before compaction

This is error-prone and leads to lost context.

Proposed Solution

  1. Detection API: Expose the current context usage percentage or a "compaction imminent" signal
  2. Hooks: Allow users to define pre-compaction hooks in settings (similar to existing hooks):

``json
{
"hooks": {
"preCompact": [
{"command": "claude", "args": ["--prompt", "Update PROJECT_CONTINUITY.md with current state"]}
]
}
}
``

Alternative: System Reminder

If hooks are too complex, a simpler solution would be a system-reminder that triggers at (e.g.) 90% context usage, reminding Claude to save state to designated files.

Benefits

  • Reduces context loss during long sessions
  • Enables seamless multi-session workflows
  • Gives users control over what gets preserved

View original on GitHub ↗

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