mcp-token-optimizer

v0.2.0
io.github.GuardBee/mcp-token-optimizer Checked 1 hour ago Published 11 days ago

Finds 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.

ParameterTypeDescription
contextThresholdnumberContext size that warrants /compact (default 150000)
hoursnumberLook-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.

ParameterTypeDescription
hoursnumber

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.

ParameterTypeDescription
dryRunbooleanDefault true
idleHoursnumber
pidsarray

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.

ParameterTypeDescription
hoursnumberLook-back window (default 168)
projectstringOnly 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.

ParameterTypeDescription
servers *array
dryRunbooleanDefault 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.

ParameterTypeDescription
projectstringOnly this project's local/.mcp.json servers, plus user and plugin servers
serversarrayOnly these server names (default: every enabled server)
timeoutSecondsnumberPer 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.

ParameterTypeDescription
dryRunbooleanDefault true
langstringWarning language (default en)
thresholdnumber
toolThresholdnumberTokens 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.

ParameterTypeDescription
dryRunbooleanDefault true
forcebooleanReplace a status line someone else set
langstring
thresholdnumberContext 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.

ParameterTypeDescription
dryRunbooleanDefault true

uninstall_hooks

Remove the context-warning hooks install_hooks added, and nothing else. Dry run by default.

ParameterTypeDescription
dryRunbooleanDefault 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.

ParameterTypeDescription
dryRunbooleanDefault true: show the change without writing it
serversarray