context-budget

Reviewed at commit d788110 New version, not yet reviewed

Caution: Loads and runs the Agent SDK package from the opened project's node_modules during an audit when the plugin's own copy is not installed.

Measures a Claude Code session's fixed startup context payload per item at a pinned binary version, including per-tool attribution of the built-in tool pools…

What we checked

Shows a live breakdown of what fills your context window in a pane or above the prompt, and asks before Claude edits a Claude Code settings file. Its audit starts short headless Claude Code sessions to measure startup context per tool, keeps results in the plugin data folder, and may load the Agent SDK from your project. It sends nothing anywhere.

Review details

Static review of the source at the pinned commit; not run. Caution: in takeSnapshot, measure.mjs builds sdkCandidates = [--sdk-dir, process.cwd()] and findSdkEntry uses createRequire anchored in each directory to resolve @anthropic-ai/claude-agent-sdk, then imports the resolved entry with dynamic import() and calls its query(); Node resolution walks up node_modules from each anchor. The skill passes --sdk-dir ${CLAUDE_PLUGIN_DATA}/sdk, which is empty unless the user ran the offered npm install, and the engine runs with the project as working directory, so by default a copy of the package in the opened project's node_modules (or a parent directory's) is loaded and executed on every audit snapshot, attribute or measure-only run. The only gate is the generic Bash permission for node measure.mjs, whose command line does not reveal this, and the audit skill is model-invocable; the working-directory fallback is mentioned only in the internal reference/engine.md table, not in the README or skill text. Full re-review of a new version (the diff since 9519cda was too large for a delta review). The function-hook module register.tsx registers the /context-budget command on session.start (and again on the first prompt.submit after a session.end, without reading the prompt), refreshes the breakdown on session.measure only while the pane or band is shown, and draws it through ui.render (Pane and AbovePrompt) from $.session.usage({ breakdown: 'summary' }); it uses $.command.register, $.ui.toast/open/close/panes, and plugin state atoms for the display mode and the last view. A command PreToolUse hook (matcher Write|Edit|NotebookEdit) runs hooks/settings-write-ask.mjs with node: it reads the tool payload, runs git rev-parse to find the main checkout, and returns permissionDecision ask when the target is a Claude Code settings file (user settings.json, project .claude/settings(.local).json, managed-settings); it fails open and can be switched off with the settings_write_ask_enabled option. The audit skill (model-invocable, no allowed-tools, so each Bash call asks) runs lib/state-key.sh (git remote and root, hashed) and skills/audit/scripts/measure.mjs, which resolves claude on PATH or --binary, spawns headless sessions with prompt /context (through @anthropic-ai/claude-agent-sdk when it resolves from --sdk-dir or the current project's node_modules, else claude -p /context with --disallowedTools per denied tool, 180 s timeout), reads the claude binary to grep catalogue key names, and writes snapshots, an append-only ledger and reports under ${CLAUDE_PLUGIN_DATA}/audit/<state-key>/ (token counts, tool names, binary path, cwd). A full sweep starts one headless session per tool. The skills only print an unpinned npm install of the Agent SDK into the plugin data folder as an offer for the user to approve or run; nothing installs it automatically. The fix path edits only project .claude/settings(.local).json with Edit/Write after the user approves the exact diff, and only prints user-global edits. The setup skill is user-only, check-only, and pre-approves only node --version, claude --version and command -v probes. Changes since the previous review: the SessionStart node-check hook (sh plus powershell -ExecutionPolicy Bypass) and the check skill were removed, measure.mjs gained a read-only snapshot --measure-only mode, setup now reports Agent SDK presence, and the rest is refactoring, docs and evals. Read in full: manifests, hooks.json, register.tsx, parts.tsx, types, settings-write-ask.mjs, measure.mjs, state-key.sh, the audit and setup SKILL.md files and the code diff since 9519cda; levers.json, engine.md and report.md prompts by targeted search (all links are code.claude.com docs); the test scripts (levers.test.sh, measure.test.sh) were skimmed, as nothing in the plugin runs them. lib/prerequisites.mjs/.sh/.ps1, prerequisites.json and probes/audit.json are not loaded by this plugin's hooks or skills at this commit (checked in the clone); reference/plugin-reconfiguration.md is prose the setup skill prints from. The Agent SDK and the Claude Code CLI were not reviewed.

What it uses
  • Reads your prompts: no
  • Sees tool calls: yes
  • Blocks or changes tool calls: yes
  • Reads or writes files: yes
  • Runs programs on your machine: yes
  • Calls the model (uses tokens): no
  • Sends data over the network: no
  • Stores data: yes
  • Shows something on screen: yes
Hooked events

Measures a Claude Code session's fixed startup context payload per item at a pinned binary version, including per-tool attribution of the built-in tool pools that /context reports only as totals, derived by A/B deny differencing. Falls back from an SDK meter to a headless /context parser, then to an error rather than a wrong number. Keeps a before/after ledger per lever. Shows a live context breakdown in a pane or above the prompt. Report-only by default; fix applies one approved project trim.

Made this mod? Add a badge to your README

modsforClaude badge for context-budget

Paste this into your README. The badge says reviewed once the current version has been reviewed, and links readers to this page.

[![Listed on modsforClaude](https://modsforclaude.com/badge/context-budget.svg)](https://modsforclaude.com/mods/context-budget/)

← All mods