claude-code - 💡(How to fix) Fix [FEATURE] Add OnCompaction hook event to reload context after memory compaction [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#46974Fetched 2026-04-13 05:44:51
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Timeline (top)
labeled ×2commented ×1
RAW_BUFFERClick to expand / collapse

Feature Request

Add a new hook event (e.g. OnCompaction or PostCompaction) that fires when Claude Code compresses/compacts the conversation context.

Problem

After context compaction, Claude frequently loses adherence to rules defined in CLAUDE.md files (both personal ~/.claude/CLAUDE.md and project-level). Instructions that were being followed correctly earlier in the session stop being respected after compaction occurs. There is currently no way to detect or respond to compaction events.

Proposed Solution

Add a hookable event that fires after context compaction completes. This would allow users to:

  1. Force re-reading of CLAUDE.md files so rules are re-injected into the active context
  2. Re-inject critical instructions or reminders that may have been lost
  3. Log when compaction occurs for debugging session quality issues

Use Case

Users with detailed personal settings (~/.claude/CLAUDE.md) and project instructions rely on these being consistently followed throughout a session. Long sessions that trigger compaction silently degrade instruction adherence, with no mechanism to detect or correct it.

Even without the hook, ensuring CLAUDE.md content survives compaction intact would address the root issue — but a hook would give users a general-purpose tool for maintaining session quality.

extent analysis

TL;DR

Implementing a hook event, such as OnCompaction or PostCompaction, would allow users to re-inject rules and instructions after context compaction, ensuring adherence to CLAUDE.md files.

Guidance

  • Identify the specific rules and instructions that are being lost after compaction to determine the best approach for re-injecting them.
  • Consider the trade-offs between automatically re-reading CLAUDE.md files versus providing a hook for users to implement custom logic.
  • Evaluate the potential impact of frequent compaction events on session quality and user experience.
  • Investigate whether existing logging mechanisms can be leveraged to detect compaction events, even without a dedicated hook.

Example

No specific code example is provided, as the issue focuses on the need for a new hook event rather than a specific implementation.

Notes

The proposed solution assumes that the loss of rule adherence is directly related to context compaction. However, other factors may contribute to this issue, and further investigation may be necessary to confirm the root cause.

Recommendation

Apply a workaround, such as periodically re-reading CLAUDE.md files or implementing a custom logging mechanism to detect compaction events, until a dedicated hook event is available. This approach allows users to maintain session quality while a more permanent solution is developed.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING