Skip to main content
command CX Codex

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

Install into Claude Code · Plugin marketplace All methods and platforms ↓
/plugin marketplace add rohitg00/pro-workflow
/plugin install pro-workflow@pro-workflow
Open on GitHub

What 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.md files 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-workflow

2Manually: put the files in place

.claude/commands/context-optimizer.md

Call it with /context-optimizer. For all projects use ~/.claude/commands/

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

Similar slash commands

All slash commands for Agent setup: memory, context, orchestration →

From the same set83

The whole set →
incremental-verify incremental-verify keeps the agent on one failing test at a time: the smallest change that passes it, then a commit, before the next behavior starts. CX Codex +1 ★ 2,966repo stars token-efficiency token-efficiency cuts token burn in Claude Code by removing conversational filler, enforcing read-before-write, and stopping unwanted refactoring loops. CX Codex +1 ★ 2,966repo stars scout scout examines a codebase before implementation and rates readiness across five dimensions. Use it to see whether the task is ready to start or needs more investigation. CX Codex ★ 2,966repo stars core-rules core-rules — a rule file for your project: commit checks, Git habits, context discipline and the way the agent replies. Paste it into CLAUDE.md or keep it standalone. CX Codex +1 ★ 2,966repo stars module-map The module-map skill builds a compact map of an unfamiliar codebase area, covering entry points, core modules, data flow, and callers. Use it when you need to get oriented. CX Codex +1 ★ 2,966repo stars parallel Run multiple Claude Code sessions in parallel with isolated git worktrees. Ideal for working on features, testing, and code review simultaneously without file conflicts. CX Codex +1 ★ 2,966repo stars session-handoff session-handoff generates a structured handoff document capturing git state, open tasks, decisions, and a resume prompt for your next session. CX Codex +1 ★ 2,966repo stars replay-learnings The replay-learnings skill searches project memory and similar sessions for lessons tied to a new task. Run it before coding to bring earlier corrections into view. CX Codex +1 ★ 2,966repo stars

Project sponsors

Companies that keep this analytics open