| name | strategic-compact |
| description | Suggests manual context compaction at logical workflow breakpoints to preserve context through task phases rather than losing it to arbitrary auto-compaction |
Strategic Compact Skill
Suggests manual /compact at strategic points in your workflow rather than relying on arbitrary auto-compaction.
When to Activate
- Running long sessions that approach context limits (200K+ tokens)
- Working on multi-phase tasks (research โ plan โ implement โ test)
- Switching between unrelated tasks within the same session
- After completing a major milestone and starting new work
- When responses slow down or become less coherent (context pressure)
Why Strategic Compaction?
Auto-compaction triggers at arbitrary points:
- Often mid-task, losing important context
- No awareness of logical task boundaries
- Can interrupt complex multi-step operations
Strategic compaction at logical boundaries:
- After exploration, before execution โ Compact research context, keep implementation plan
- After completing a milestone โ Fresh start for next phase
- Before major context shifts โ Clear exploration context before different task
How It Works
The suggest-compact.js hook runs on Stop events and:
- Tracks message count โ Increments a counter in session state on each stop
- Threshold detection โ Suggests compaction at a configurable threshold (default: 50 messages)
- Periodic reminders โ Reminds every 25 messages after threshold
The hook outputs suggestions to stderr so they appear as non-blocking notices.
Compaction Decision Guide
Use this table to decide when to compact:
| Phase Transition | Compact? | Why |
|---|
| Research โ Planning | Yes | Research context is bulky; plan is the distilled output |
| Planning โ Implementation | Yes | Plan is in TodoWrite or a file; free up context for code |
| Implementation โ Testing | Maybe | Keep if tests reference recent code; compact if switching focus |
| Debugging โ Next feature | Yes | Debug traces pollute context for unrelated work |
| Mid-implementation | No | Losing variable names, file paths, and partial state is costly |
| After a failed approach | Yes | Clear the dead-end reasoning before trying a new approach |
What Survives Compaction
Understanding what persists helps you compact with confidence:
| Persists | Lost |
|---|
| CLAUDE.md instructions | Intermediate reasoning and analysis |
| TodoWrite task list | File contents you previously read |
| Files on disk (instincts, state) | Multi-step conversation context |
| Git state (commits, branches) | Tool call history and counts |
| Skill definitions | Nuanced user preferences stated verbally |
Best Practices
- Compact after planning โ Once plan is finalized in TodoWrite, compact to start fresh
- Compact after debugging โ Clear error-resolution context before continuing
- Don't compact mid-implementation โ Preserve context for related changes
- Read the suggestion โ The hook tells you when, you decide if
- Write before compacting โ Save important context to files or memory before compacting
- Use
/compact with a summary โ Add a custom message: /compact Focus on implementing auth middleware next
Token Optimization Patterns
Context Composition Awareness
Monitor what's consuming your context window:
- CLAUDE.md files โ Always loaded, keep lean
- Loaded skills โ Each skill adds 1-5K tokens
- Conversation history โ Grows with each exchange
- Tool results โ File reads, search results add bulk
Duplicate Instruction Detection
Common sources of duplicate context:
- Same rules in both global and project CLAUDE.md
- Skills that repeat CLAUDE.md instructions
- Multiple skills covering overlapping domains
Configuration
Environment variables:
COMPACT_THRESHOLD โ Messages before first suggestion (default: 50)