context-optimizer — Claude Code command: setup and use
The context-optimizer command checks context window fill rates in Claude Code and helps cut token waste before responses degrade.
MIT ★ 2,966 updated 2026-09-29
/plugin marketplace add rohitg00/pro-workflow
/plugin install pro-workflow@pro-workflowWhat context-optimizer does
The command diagnoses current session usage against explicit thresholds. If context crosses 70%, it suggests compacting before output quality drops. Beyond 90%, it triggers immediate compaction because Claude starts repeating itself, losing project specifics, or failing tool calls.
The inspection covers external tooling and instructions. It checks that you keep fewer than 10 MCP servers and fewer than 80 tools active at once. It also verifies that your root CLAUDE.md stays below 60 to 150 lines, advising you to offload package specifics to nested files and local settings to CLAUDE.local.md.
Running heavy search tasks in the main session rapidly burns context budget instead of delegating to subagents.
What it helps with
- audit active token consumption in long coding sessions
- trim unused MCP servers and excessive tool definitions
- split bloated
CLAUDE.mdfiles into modular configs - configure proactive auto-compaction via
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE
Example prompts for the agent
- /context-optimizer
- Run /context-optimizer to check token usage before our next task
How to install context-optimizer
1Plugin marketplace
/plugin marketplace add rohitg00/pro-workflow/plugin install pro-workflow@pro-workflow2Manually: put the files in place
.claude/commands/context-optimizer.mdCall it with /context-optimizer. For all projects use ~/.claude/commands/
Manually: put the files in place
~/.codex/prompts/context-optimizer.mdCall it with /prompts:context-optimizer. Codex marks this format deprecated in favour of skills
Manually: put the files in place
.github/prompts/context-optimizer.prompt.mdManually: put the files in place
.gemini/commands/context-optimizer.tomlGemini stores commands as TOML: the prompt text goes into the prompt field
Questions about context-optimizer
How to install context-optimizer in Claude Code?
Run /plugin marketplace add rohitg00/pro-workflow and then /plugin install pro-workflow@pro-workflow. Alternatively, place the file directly into .claude/commands/context-optimizer.md.
What does context-optimizer do?
It evaluates your context window usage, audits loaded MCP tools, checks instruction file length, and guides compaction steps to maintain response quality.
What are the signs of context degradation?
Warning signs include repeated answers, forgotten earlier decisions, generic responses without project specifics, and unexpected tool call failures.
Source text
context-optimizer.md · MIT
---
description: Diagnose context usage and reduce unnecessary token consumption.
---
# /context-optimizer - Optimize Token Usage
Diagnose and fix context window problems.
## Process
1. **Check current usage:**
- If > 70% → compact now before quality degrades
- If > 90% → compact immediately, you're in the "dumb zone"
2. **Run optimization checks:**
**MCP audit:**
```bash
/mcp
```
- Keep <10 MCPs enabled, <80 tools total
- Disable what you're not actively using
**CLAUDE.md size:**
- Root CLAUDE.md should be < 60 lines, < 150 max
- Move package-specific info to package-level files
- Move personal preferences to CLAUDE.local.md
3. **Apply fixes based on findings:**
| Problem | Fix |
|---------|-----|
| High context usage | `/compact` with focus on current task |
| Too many MCPs | Disable unused servers |
| Bloated CLAUDE.md | Split into modular files |
| Heavy exploration in main session | Delegate to subagents |
| Vague prompts causing broad searches | Scope prompts with paths and constraints |
4. **Set proactive auto-compaction** if not already configured:
```json
{
"env": {
"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "50"
}
}
```
5. **Report** current state and what was optimized.
## Signs of Degraded Context
- Claude repeats itself or forgets earlier decisions
- Responses become generic, lose project-specific knowledge
- Tool calls fail for reasons that worked earlier
## Quick Fixes
| Action | Saves | When |
|--------|-------|------|
| `/compact` | 30-50% context | Task boundaries |
| Disable unused MCPs | ~5% per MCP | Switching domains |
| Subagent delegation | Keeps main clean | Heavy search/read tasks |
| Fresh session via `/resume` | 100% reset | Unrelated work |
---
**Trigger:** Use when sessions feel slow, context is degraded, running out of budget, or before starting a long task.
© Rohit Ghumare · MIT · rohitg00/pro-workflow