feat: PreCompact Hook Integration for Context Preservation #73
Labels
No labels
good first issue
has-pr
help wanted
idea
priority
critical
priority
high
priority
low
priority
medium
status
blocked
status
in-progress
status
needs-review
status
ready
type
bug
type
docs
type
enhancement
type
feature
type
refactor
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
customable/claude-mem#73
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Implement PreCompact hook support to preserve context before Claude Code's automatic compaction, enabling intelligent context re-injection after compaction occurs. Additionally, investigate the potential to block compaction entirely using exit code 2.
Problem Statement
Claude Code automatically compacts conversation context when the token limit is reached. This causes:
Currently, claude-mem has no visibility into when compaction occurs and cannot preserve or restore context around this event.
Key Discovery: Compaction Blocking May Be Possible
The claude-flow cache-optimizer project claims:
This contradicts the official documentation which states PreCompact hooks cannot block compaction. This needs investigation:
If compaction CAN be blocked, this changes the implementation strategy significantly.
Proposed Solution
Phase 0: Investigation (Priority)
Phase 1: PreCompact Hook (Reactive Approach)
If blocking is NOT possible, implement reactive preservation:
Phase 1b: Compaction Blocking (If Possible)
If exit code 2 works, implement intelligent blocking:
Hook Input (from Claude Code)
Implementation Details
Worker Endpoint:
POST /api/hooks/pre-compactActions:
transcript_pathPost-Compaction Recovery:
On the next
UserPromptSubmit, detect if a recent compaction occurred and inject:/compactTechnical Background
PreCompact Hook - Official vs Discovered Behavior
Official Documentation says:
claude-flow claims:
This discrepancy needs verification.
Hook Blocking Matrix (Official)
Related Projects & Research
Future Enhancements (Phase 2)
Preventive Context Management
Implement proactive context optimization:
Performance potential (from claude-flow benchmarks):
Acceptance Criteria
hooks.json/api/hooks/pre-compactimplementedReferences