Compresses and reorganizes the active context window when it gets too large. Audits what is consuming space, summarizes resolved work, archives completed tasks, and reloads only what is needed for the current task.
As a Claude Code session grows, the context window accumulates noise: full file reads, long error logs, resolved debugging threads, repeated explanations, and completed task discussions. This noise crowds out the space needed for current work and makes Claude's responses less focused. This skill systematically compresses that noise without losing anything important.
/compact — optimizing first means compact preserves higher-quality informationIdentify what is currently taking up context. Look for:
Output: a ranked list of the top 5 context consumers with estimated size.
Summarize long outputs into the minimum facts needed to continue working:
src/api/route.ts:45 — missing return type. Fixed by adding : Promise<Response>."await getSession(). Committed in abc1234."src/lib/db.ts — exports createClient(), getUser(id), updateUser(id, data). Connection via env var DATABASE_URL."Rule: The compression must contain enough information to reproduce the decision or avoid the error. If it cannot, keep more detail.
Move resolved work out of active context and into persistent memory files:
.claude/memory/session-[date].md) with the compressed summariesFormat for archived entries:
### [timestamp] [Task name]
- **What:** [One sentence description]
- **Decision/Fix:** [The key fact to preserve]
- **Location:** [File path or commit hash if relevant]
Once archived, reference the memory file by path. Do not re-paste the content.
Keep only what is needed for the task immediately ahead:
Everything else is either archived (Step 3) or can be re-read on demand. The active context after reload should feel minimal and purposeful.
Report what was recovered:
Context Optimizer — Results
---------------------------
Audited: [N] major context consumers identified
Compressed: [N] long outputs summarized (saved ~X% context)
Archived: [N] resolved tasks moved to memory
Reloaded: [N] items kept for current task
Status: Context reduced from ~X% to ~Y%
Memory: Saved to [file path]
These items must survive any optimization pass:
When in doubt, archive rather than discard.
/context-optimizerRuns the full 5-step optimization process: audit, compress, archive, reload, confirm.
Typical duration: 2–4 minutes for a well-established session.
Best used: Before starting a new phase of work, after a long debugging session, or before running /compact.
/context-optimizer --auditAnalysis only. Runs Step 1 (Audit) and reports findings without making any changes.
Output includes:
Best used: When you want to understand the state of the context before deciding whether to optimize.
/context-optimizer --audit first if you are unsure whether optimization is needed/token-saver to identify when to optimize and what the priority actions are/pipeline-state to checkpoint pipeline progress before archiving the session context/context-optimizer, run /compact to further compress what remains in the conversation history/auto-learn output and can be reviewed or edited manually