--- name: strategic-compact description: Guide for when and how to run /compact effectively — preserving critical context while freeing token budget. Use at phase transitions, before large implementations, or when context is bloated. disable-model-invocation: true --- # Strategic Compact Evaluate whether `/compact` should be run now, and if so, prepare for it. ## Context Current conversation state: !`echo "Working directory: $(pwd)" && echo "Git branch: $(git branch --show-current 2>/dev/null)" && echo "Modified files: $(git diff --name-only 2>/dev/null | wc -l | tr -d ' ')" && echo "Staged files: $(git diff --cached --name-only 2>/dev/null | wc -l | tr -d ' ')"` ## When to Compact Use this decision table: | Trigger | Should Compact? | Priority | |---------|----------------|----------| | Phase transition (planning → implementation) | Yes | High | | Starting a new major feature | Yes | High | | After completing a large task (before next) | Yes | Medium | | Context feels sluggish or repetitive | Yes | Medium | | Mid-implementation (code partially written) | **No** — finish first | - | | Debugging an active issue | **No** — need full context | - | | Waiting for user input | Maybe — depends on context size | Low | ### Do NOT compact when: - You're in the middle of writing code (partial state will be lost) - You're debugging and need the full error trail - You have uncommitted understanding of complex relationships - The user just gave important instructions that aren't saved to files ## Pre-Compact Checklist Before running `/compact`, ensure critical context survives: ### 1. Save state to files Information that exists only in conversation will be lost. Save to appropriate places: - **Implementation plan** → Update or create a task list - **Decisions made** → Record in `RECOMMENDATIONS.md` or ADR - **Current phase/status** → Verify `docs/phases-plan.md` is current - **Known issues** → Document in code comments or issues ### 2. Commit work in progress ```bash # Check for uncommitted changes git status # If meaningful changes exist, commit them git add -A && git commit -m "wip: [what was in progress]" ``` ### 3. Verify anchors Ensure these files are up-to-date (they'll be re-read after compact): - `RULES.md` — project conventions - `RECOMMENDATIONS.md` — current decisions and constraints - `docs/phases-plan.md` — phase status ### 4. Write a compact summary Create a brief note of what survives compaction vs. what's re-derivable: **Survives** (in files): - Project rules and recommendations - Code changes (committed) - Documentation updates **Lost** (conversation-only): - Reasoning chains and trade-off discussions - Rejected approaches and why - Nuanced context from user messages ## After Compact After `/compact` runs: 1. Re-read `RULES.md` and `RECOMMENDATIONS.md` 2. Check task list for current progress 3. Review `git log --oneline -5` for recent context 4. Resume work from the task list ## Token Optimization Tips - **Before compact**: Write meaningful commit messages — they're your post-compact memory - **File references**: Use `file:line` references instead of pasting code blocks - **Avoid re-reading**: Once you've read a file, note the key facts — don't re-read it - **Trim conversation**: If the user asks a tangential question, answer it concisely without pulling in the full project context