mcp-token-optimizer
v0.2.0Finds what burns Claude Code tokens and stops it: idle sessions, unused or chatty MCP servers, overs
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
optimize_report
Find what is burning Claude Code tokens on this machine and what to do about it: sessions with oversized contexts, file reads and MCP servers that flood the context, unused MCP servers, idle sessions, subagent and model mix.
| Parameter | Type | Description |
|---|---|---|
contextThreshold | number | Context size that warrants /compact (default 150000) |
hours | number | Look-back window (default 24) |
list_sessions
Running Claude Code processes on this machine with uptime, CPU, busy/idle status, current context size and recent token spend.
| Parameter | Type | Description |
|---|---|---|
hours | number |
stop_sessions
Stop Claude Code sessions by pid, or every session idle for longer than idleHours. Dry run by default. Sends SIGTERM (transcripts are kept, `claude --resume` reopens them) and never stops the session that runs this tool.
| Parameter | Type | Description |
|---|---|---|
dryRun | boolean | Default true |
idleHours | number | |
pids | array |
audit_mcp_servers
Every MCP server Claude Code loads (user, local, project .mcp.json, plugins, plus claude.ai connectors and built-ins seen in transcripts) with how often its tools ran and how much output they put into context.
| Parameter | Type | Description |
|---|---|---|
hours | number | Look-back window (default 168) |
project | string | Only this project's local/.mcp.json servers |
disable_mcp_servers
Turn MCP servers off for new Claude Code sessions without losing their config: plugins and .mcp.json servers via Claude Code's own disable lists, user/local servers by parking their entry for restore_mcp_servers. Dry run by default; backs up the config before writing.
| Parameter | Type | Description |
|---|---|---|
servers * | array | |
dryRun | boolean | Default true: show the change without writing it |
measure_mcp_definitions
Start each configured MCP server the way Claude Code does, list its tools, and measure how many tokens their names, descriptions and input schemas take. Runs the servers' configured commands; results are stored for optimize_report.
| Parameter | Type | Description |
|---|---|---|
project | string | Only this project's local/.mcp.json servers, plus user and plugin servers |
servers | array | Only these server names (default: every enabled server) |
timeoutSeconds | number | Per server (default 20) |
install_hooks
Add a Claude Code hook (UserPromptSubmit, and SessionStart on resume) that warns you when a session's context passes a threshold (default 200000), then again every further 100k, with the per-message plan cost when calibrated, plus a PostToolUse hook that warns when one tool result adds a lot of context. Leaves other hooks untouched; backs up settings.json. Dry run by default.
| Parameter | Type | Description |
|---|---|---|
dryRun | boolean | Default true |
lang | string | Warning language (default en) |
threshold | number | |
toolThreshold | number | Tokens one tool result must add before PostToolUse warns (default 10000) |
install_statusline
Set Claude Code's status line to show context size, the 5-hour and 7-day plan meters with time to reset, the plan cost per message, a warning when the pace reaches the limit before the reset, and the foreign-usage alarm. It also stores each fresh plan reading for claude-usage-guard. Keeps an existing status line unless force. Dry run by default.
| Parameter | Type | Description |
|---|---|---|
dryRun | boolean | Default true |
force | boolean | Replace a status line someone else set |
lang | string | |
threshold | number | Context size that turns the context yellow (red at twice it) |
uninstall_statusline
Remove the status line install_statusline set, and only that one. Dry run by default.
| Parameter | Type | Description |
|---|---|---|
dryRun | boolean | Default true |
uninstall_hooks
Remove the context-warning hooks install_hooks added, and nothing else. Dry run by default.
| Parameter | Type | Description |
|---|---|---|
dryRun | boolean | Default true |
restore_mcp_servers
Turn back on MCP servers disabled with disable_mcp_servers. Dry run by default. With no servers given, lists what is parked.
| Parameter | Type | Description |
|---|---|---|
dryRun | boolean | Default true: show the change without writing it |
servers | array |