code-context-engine icon indicating copy to clipboard operation
code-context-engine copied to clipboard

feat: increase output token savings ratio

Open rajkumarsakthivel opened this issue 6 months ago • 1 comments

Problem

Output compression currently maxes out at ~75% savings (max level). Users want higher output savings since output tokens cost 5x more than input tokens (Opus: $75/1M vs $15/1M).

Current state

Level Savings Method
off 0% None
lite ~20% Remove filler/hedging/pleasantries
standard ~65% Drop articles, fragments, short synonyms
max ~75% Caveman style

These are style directives appended to tool responses. The model follows them voluntarily.

Ideas to increase output savings

  1. Diff-only mode — For code changes, instruct the model to return only the diff (unified or edit format), not full file rewrites. A 500-line file change that touches 5 lines currently costs ~500 lines of output. Diff-only would cost ~15 lines.

  2. Structured responses — Force JSON/YAML output for structured answers (file lists, search results, status checks). Skip prose entirely when the answer is data.

  3. Response deduplication — If the model repeats code that was already in the context (echo-back pattern), detect and suppress it.

  4. Adaptive compression — Track which responses the user actually reads vs skips. Increase compression on response types that get skipped.

  5. Token budget directive — Add a max_output_tokens hint to the compression directive so the model self-limits.

Priority

Diff-only mode (#1) likely has the highest impact since code output is where most output tokens go in coding sessions.

rajkumarsakthivel avatar May 16 '26 10:05 rajkumarsakthivel

Fixed in release/v0.4.21 (commit c46b7c0).

Implemented: Diff-only code output rules added to all compression levels. The model is now instructed to show only changed lines with minimal context instead of full file rewrites.

Updated savings: lite 25%, standard 70%, max 80%.

Remaining ideas (future work):

  • Structured responses (JSON for data answers)
  • Response deduplication (suppress echo-back)
  • Adaptive compression (track what users read)
  • Token budget directive

rajkumarsakthivel avatar May 16 '26 10:05 rajkumarsakthivel