[Feature Request] Enhance /compact with structured context preservation sections
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
The default /compact summary produces a chronological narrative that captures what happened but loses critical actionable context:
| Missing Element | Impact |
|----------------|--------|
| Compact counter | Can't track multi-compact sessions |
| Immediate next action | Claude doesn't know what to do next (buried in narrative) |
| Settled decisions | Decisions get re-debated, wasting time |
| Dead ends | Failed approaches get retried |
| Trust anchors | Working components get questioned |
| User preferences | Preferences get forgotten, user has to repeat |
| Task queue | Remaining work unclear |
| Breakthroughs | Key insights lost in prose |
Users have built elaborate infrastructure (PostgreSQL databases, Gemini API extraction, external scripts) to capture this context - all of which breaks because PreCompact hooks don't fire on manual /compact (#13572).
The Discovery
The /compact command already accepts custom instructions! Running /compact [text] guides the summarizer to include specified sections.
I've been using this successfully across multiple compact cycles:
/compact In addition to the default summary, explicitly include these sections at the END:
0) COMPACT NUMBER - This is compact #[N].
1) IMMEDIATE NEXT ACTION - [Specific imperative].
2) SETTLED DECISIONS - [Decisions with rationale]
3) DEAD ENDS - [What failed and WHY]
4) TRUST ANCHORS - [What's verified working]
5) USER PREFERENCES - [How user wants things done]
6) TASK QUEUE - [Remaining work with dependencies]
7) BREAKTHROUGHS - [Key insights and why they matter]
Result: All 8 sections appear accurately in post-compact context. The next Claude instance has explicit, structured access to critical context.
Proposed Solution
Make these structured sections part of the default /compact behavior, or provide a flag like /compact --structured or /compact --preserve-context.
The summarizer should automatically extract and explicitly list:
- Session counter - For multi-compact tracking
- Continue by - Clear next action (imperative, not narrative)
- Settled decisions - With brief rationale (don't revisit)
- Dead ends - What failed and why (don't retry)
- Trust anchors - Verified working (don't question)
- User preferences - PERMANENT markers for lasting preferences
- Task queue - Remaining work with dependencies
- Breakthroughs - "Aha!" moments, paradigm shifts, key insights
Why This Matters
- Eliminates infrastructure burden - No PostgreSQL, no Gemini extraction, no external scripts
- Works with manual /compact - Doesn't depend on broken PreCompact hooks
- Claude IS the extraction engine - AI analyzing its own session is more accurate than external parsing
- Prevents common post-compact failures:
- Re-debating settled decisions
- Retrying failed approaches
- Losing user preferences
- Missing immediate next action
- Forgetting key breakthroughs
Alternative Solutions
- Fix PreCompact/PostCompact hooks for manual
/compact(#13572, #3537) - Still valuable but more complex - Document the custom instructions approach - Users can manually add instructions (current workaround)
- Configurable default instructions - Let users set default
/compactinstructions in settings.json
Priority
High - Significant impact on productivity
Feature Category
Core functionality - Context preservation
Use Case Example
Before (default /compact):
"The user asked about X, then we discussed Y, and decided to use Z approach..."
After (structured /compact):
[Standard summary] COMPACT #3 IMMEDIATE NEXT ACTION: Run test suite in src/tests/ SETTLED DECISIONS: - Use PostgreSQL over SQLite (rationale: concurrent access needed) - Claude-analysis over Gemini extraction (rationale: simpler, no external deps) DEAD ENDS: - WebSocket approach failed - browser security restrictions TRUST ANCHORS: - Auth flow verified working (tested 3x) USER PREFERENCES: - VERBATIM means NO TRUNCATION (PERMANENT) - Open files in TextMate for review TASK QUEUE: - Implement caching layer - Write integration tests BREAKTHROUGHS: - "Custom /compact instructions add explicit sections!" - Eliminates need for external extraction
Additional Context
I've been using this approach successfully and it completely eliminated my need for the PostgreSQL/Gemini extraction pipeline I had built. The workaround works, but it would be much better as a first-class feature.
Related issues:
- #13572 - PreCompact hook not triggered on manual /compact
- #3537 - No PostCompact hook
- #3349 - Custom pre/post compact commands
- #7359 - /compact options (different focus - selective deletion vs structured preservation)
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗