Skip to main content

Optimize Cost

Tasks

Turn on context optimization and compression to cut the tokens each request consumes, then confirm the savings in the Context Savings dashboard.

Enable context optimization

  1. Navigate to Settings → Context Optimization.

  2. Use the master toggle to enable context optimization. Individual settings below can be adjusted independently once it's on.

  3. Enable Noise filtering to strip ANSI escape codes, progress bars, and terminal noise from Bash and shell tool responses before they are forwarded to the LLM. This has no effect on non-terminal tool output.

  4. Enable Response deduplication to suppress exact duplicate tool responses within a session using a content-hash cache. Repeated occurrences of the same result are replaced with a short reference instead of the full text.

  5. Set Brevity injection to one of:

    • Off — disabled
    • Auto — applied when context pressure is detected
    • Always — applied to every request
  6. Optionally set a Custom brevity prompt to override the built-in instruction. Leave blank to use the default: "Be concise. Omit preamble and trailing summaries. Prefer code over prose."

note

Brevity injection is the highest-leverage technique for most teams — a single setting that reduces output tokens on every request it applies to.

Enable compression

  1. Navigate to Settings → Compression.

  2. Use the master toggle to enable compression. When enabled, the settings below control behavior.

  3. Set Default mode — the compression level applied to all tool responses. ML (model-based) achieves ~90–95% size reduction by summarizing content semantically. Additional modes may be available depending on your workspace configuration.

  4. Enable Code-aware (AST) compression to compress source code responses using an AST-aware pass that strips function bodies and retains signatures, imports, and structure. This requires the Compression Service to be reachable from your workspace.

  5. Set Threshold — the minimum response size in bytes before compression is attempted. Responses smaller than this value are returned unmodified. Default: 4096 bytes.

  6. Enable Also compress local/built-in tool results to additionally compress results from tools that run inside your coding agent itself — Bash, Read, Grep, Edit, WebFetch, and similar — which never pass through an MCP server and would otherwise bypass compression entirely. Off by default, since it rewrites outbound LLM requests rather than isolated MCP responses.

note

Compression is a preview feature. Results vary by tool and content type. Monitor the Context Savings dashboard after enabling to confirm the savings are being applied as expected. See Context Optimization for how modes, rule precedence, context-pressure escalation, and lossless retrieval of compressed originals work.

Review your savings

After enabling either feature, go to Cost → Context Savings and confirm the savings are landing:

  1. Check the token reduction rate and estimated cost saved for the period — if they stay at zero, the techniques you enabled aren't matching your traffic.

  2. Open Savings by Technique to see which methods contribute the most, and Top Sessions by Savings to find the developers and workflows that benefit — and those where further tuning would help.

See also