Keep Claude Code context small

Downshift by Tiago Vilas Boas. Updated

Downshift here is a Go tool for AI coding agents, not the React downshift autocomplete library and unrelated to any car transmission.

TL;DR

Every tool result stays in the context that later requests resend. Downshift keeps it small in two ways: the compactor cuts clean command output to a PASS/FAIL summary and keeps failures and the exit code byte for byte, and routing sends mechanical subagent work to a smaller model. The report estimates tokens removed from output using bytes and reports routed tokens separately; quality on your own tasks is yours to check.

The problem: tool results are resent

Every command Claude runs adds its output to the context, and every later request resends it. A passing test run can print thousands of tokens that say one thing: it passed. Wide exploration adds more. Anthropic's cost page says vague prompts trigger broad scanning, and specific ones let Claude work with minimal reads.

What Anthropic suggests

  • Code intelligence plugins: a single go-to-definition call replaces a grep followed by reading several files.
  • Skills: a codebase overview skill gives Claude the structure without exploring.
  • Specific prompts, and plan mode before a complex change.

Try these first. They are documented and need no extra binary. Downshift does not replace them; it covers command output and subagent models.

The compactor: clean output becomes a summary

downshift compactor runs an allowlisted command with no shell, recognises its output format and cuts a clean run to a short PASS/FAIL summary. The exit code is always the program's own. A format it does not recognise passes through unchanged.

downshift compactor -- go test ./...

On Claude Code, downshift setup installs a plugin that rewrites allowlisted commands for you. It rewrites supported command shapes that your permission rules do not deny; some compound forms are supported and others stay unchanged. Guards fail closed for rm, mysql, redis-cli, psql and gcloud. exec false in the config, or DOWNSHIFT_EXEC=0, turns it off. OpenCode also supports rewriting through its bridge; integration varies elsewhere, and you can wrap a supported command directly.

What the compactor never hides

  • Warnings and stack traces keep their full output.
  • A non-zero exit keeps its output, with one exception: a failed go test, vitest or playwright run loses only the lines of tests that passed.
  • Any stderr byte keeps a run raw, except for the families whose report is on stderr (Jest, Vitest, go test, git commit, git push).

Failing runs keep every failure

For go test, vitest and playwright test, every failure line is kept byte for byte and in order: the FAIL blocks, assertions, expected and received values, diffs, code frames, stack frames and the summary. One line at the top says how many passing lines were cut.

ToolWhat is cut
go testok package lines, --- PASS lines and the === RUN headers of passing tests
vitest 3, 4 and 5files marked as passed, and passed tests and suites in a file that failed
playwright test (list reporter)lines of tests that passed at their first attempt

The run stays raw when the output is not one the parser fully understands: another reporter, a missing failure section, more than one run header, CRLF, invalid UTF-8, output over 2 MB, or a result that would not be shorter. Doubt keeps the original output.

Model routing per subagent

The other lever is the model a subagent runs on. The orchestrator chooses model and effort for each delegation, and Downshift applies the choice inside the policy you declared. A decisive TRIVIAL or SIMPLE task with no risk category moves down to the small tier by default (routing.by_class false turns that off), a pinned model is kept, and when Downshift cannot read the request the requested model stays. It never raises a tier on its own. This does not shrink the main session; it changes how many tokens a delegated task uses on the model that runs it.

Seeing the effect

downshift session shows the current session, downshift stats the history, and downshift report leads with compaction savings per harness, with token estimates based on bytes. After that it shows routed tokens per completed task and rework per routing verdict; a verdict is flagged once a group reaches 20 completed tasks. The product reports tokens and tier names, not prices.

What is measured and what is not

On the real transcripts used as test fixtures (vitest 3.2.7, 4.1.12 and 5.0.5, and @playwright/test 1.64.1; 10 to 15 tests, 4 failing) a failed run came out 3% to 6% smaller. Almost all of those bytes are the failures, which are kept on purpose. A Vitest transcript of a file that could not be imported lost two lines, about 0.1%. Clean runs shrink far more, but the size depends on how many tests passed.

A compactor run

Wrap any allowlisted command and compare it with the raw run on your own repository.

downshift compactor -- go test ./...
downshift report --period=7d

Source: docs/features/compaction.md in the Downshift repository

Frequently asked questions

Does the compactor hide failures?

No. A clean run is cut to a summary. A failed go test, vitest or playwright run keeps every failure line byte for byte and in order, and the exit code is always the program's own. Anything it does not recognise passes through unchanged.

Is the compactor on by default?

On Claude Code, downshift setup installs a plugin that rewrites allowlisted commands to the compactor. DOWNSHIFT_EXEC=0 or exec false in the config turns it off. OpenCode also supports automatic rewriting through its bridge; elsewhere, behavior varies and you can wrap supported commands directly with downshift compactor --.

Does routing change what the main session reads?

No. Routing only changes the model of a subagent spawn. The main session context is unchanged, so it stays your job to keep prompts specific and to compact output.

Install

Run downshift setup --dry-run first to preview every change. downshift setup --undo restores your backups.

curl -fsSL https://raw.githubusercontent.com/tiagovilasboas/downshift-ai/main/install.sh | sh && downshift setup

Claude Code plugin

/plugin install downshift --marketplace tiagovilasboas/downshift-ai

Sources

  1. Anthropic docsmeasured
    code.claude.com/docs/en/costs
    code intelligence plugins, skills, specific prompts, plan mode (fetched 2026-10-19)
  2. Downshift repomeasured
    docs/features/compaction.md
    compactor behaviour, failing runs, fixtures
  3. Downshift repomeasured
    docs/features/routing.md
    per-subagent routing precedence
  4. Downshiftunverified
    answer quality with a smaller context
    not measured