Repository navigation
ScaleDown proxy mode: real per-turn token savings + true compaction (v0.5.0) - #9
Merged
Merged
Conversation
Hooks can only append to the context window, so they cannot reduce tokens or replace Claude's compaction (PreCompact can't override the summary — anthropics/claude-code#24965). The old pre-compact hook was built on a non-existent contract and never actually ran. Add a local proxy (`dietcode claude` / `dietcode proxy`) that sits in the request path and rewrites the outgoing /v1/messages payload via progressive compaction: a per-session running ScaleDown summary stands in for older turns, extended only at occasional compaction steps (most turns make zero ScaleDown calls). This genuinely shrinks context and keeps Claude's native auto-compaction from firing. Response is streamed back untouched; every path is fail-open. - src/proxy/{transform,server,store}.ts — progressive compaction, HTTP forwarder, session state + reversibility cache (cache-safe, fail-open) - bin/proxy.ts — `dietcode proxy` (foreground) + `dietcode claude` wrapper - src/tools/retrieve.ts — sd_retrieve MCP tool to pull back compacted originals - setup: opt-in `claude`→`dietcode claude` alias (recommended), removed on uninstall - status line: shows "DietCode compaction off" when not running via the proxy - neutralize the broken pre-compact hook and its false savings accounting - proxy compaction threshold defaults to 50k tokens - Claude Code only; Codex/Cursor installs unaffected - no new dependencies (built-in node:http + global fetch) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Co-Authored-By: DietCode <ai@scaledown.ai>
varchanaiyer
approved these changes
Jun 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Hooks can only append to the context window — they can't rewrite the history Claude re-sends each turn, and
PreCompactcan't replace Claude's summary (anthropics/claude-code#24965). So the oldpre-compact.ts(built on a non-existentmessages_to_compactcontract) never ran, and a hook-injected summary would only cost tokens. Real savings require sitting in the request path.What
A local proxy —
dietcode claude(wrapper, recommended) ordietcode proxy(foreground) — that Claude Code talks to viaANTHROPIC_BASE_URL. On each/v1/messagesrequest it rewrites the outgoing payload via progressive compaction:SCALEDOWN_PROXY_COMPACT_THRESHOLD(default 50k). Most turns make zero ScaleDown calls.sd_retrievetool for the original.Also in this PR
setup: opt-in (recommended)claude→dietcode claudealias; removed ondietcode uninstall. No recursion (wrapper spawns the real binary).DietCode compaction offwhen a session is not running through the proxy.pre-compact.tsand its false savings accounting.sd_retrieveMCP tool.Notes
node:http+ globalfetchonly. The onlypackage.jsonchange is a newdietcode-proxybin entry.src/proxy/{transform,store,server}(progressive behavior, cache-stability, auth passthrough, fail-open).Deferred to a later release
Classification-driven tool routing in the proxy (the current
UserPromptSubmitintent hint is dead code —{prompt}isn't a valid hook output). Plan captured; not in this PR.🤖 Generated with Claude Code