Skip to main content
Back to integrations
Anthropic
Local & EdgeCoding agent proxy

LLMSlim + Claude Code

Run Claude Code through a local proxy that shrinks long tool output once and resends the same bytes every turn, so prompt caching and thinking keep working.

Claude Code resends the whole conversation on every turn, so a long test log or search result is paid for again and again and adds to the context Claude Code eventually compacts. llmslim wrap claude starts a local proxy and runs Claude Code through it. The first time the model is about to see a long shell, search or web result, LLMSlim shortens it, keeping errors, failures and the lines related to the command. It stores that version and sends exactly the same bytes on every later request, so nothing the model has already seen ever changes. File reads and edits are never touched.

1. Installation and setup

No model is called and nothing new leaves your machine: Claude Code sends the same requests it always did, only shorter. Your API key or Claude login is forwarded to Anthropic as usual and never stored.

terminalbash
pip install "llmslim[proxy]"   # llmslim 0.11.1 or newer

Run Claude Code through the proxy, then see what it saved:

terminalbash
llmslim wrap claude
llmslim proxy stats

2. Architecture & execution flow

1

llmslim wrap claude starts the proxy on a free localhost port and runs Claude Code with ANTHROPIC_BASE_URL pointing at it. Every request is forwarded to Anthropic with its headers; responses stream back untouched.

2

Tool output the model has not seen yet (everything after its last turn) from Bash, PowerShell, Grep, Glob, WebFetch, WebSearch or Monitor, over 1,500 tokens, is shortened once: lines that look like errors, failures or warnings come first, then the lines related to the command, and runs of similar lines collapse into one line and a count. Output that is one whole JSON document is left alone unless you pass --json.

3

The decision is stored under the tool call id and the text. Whenever Claude Code resends that output, the stored text goes out instead, byte for byte, so the cached prefix and Claude's thinking signatures stay valid.

4

Read, Edit and Write output, unknown tools and anything seen before the proxy started are never changed. A file printed through the shell (cat, head) counts as shell output. MCP tools are opt-in, because some return live state such as a browser snapshot.

3. Runnable example and its output

terminalbash
llmslim wrap claude -- -p "Run the tests and tell me what fails"

What Claude receives for a 10,545-token pytest log (156 tokens):

outputtext
[LLMSlim shortened this tool output from 10,545 to about 117 tokens, keeping errors and the lines most related to the call. Run a narrower command to see more.]
tests/test_api.py::test_endpoint_0 PASSED [0%]
... [410 similar lines]
tests/test_api.py::test_endpoint_411 PASSED [68%]
tests/billing/test_refund.py::test_rounding_half_even FAILED - AssertionError: Decimal('10.05') != Decimal('10.04')
tests/test_api.py::test_endpoint_412 PASSED [68%]
... [286 similar lines]
tests/test_api.py::test_endpoint_699 PASSED [116%]
=== 1 failed, 700 passed in 41.27s ===

The failing test, its assertion and the summary line stay; 698 passing lines collapse into two counts. If the model needs more, it can run a narrower command.

4. Options

Keyword arguments, shown as name = default.

--min-tokens = 1500
Leave output at or below this many tokens alone.
--keep-ratio = 0.35
Upper bound on the share of a long output kept (the budget is never below --min-keep, 1000 tokens); collapsing repeated lines often keeps much less (median 21% in our benchmark).
--tool / --never =
Add a tool to compress, or exempt one. Repeatable.
--mcp = off
Also compress every MCP tool's output.
--json = off
Also compress output that is one whole JSON document. Off by default: agents given shortened JSON spent extra turns fetching the fields that were cut.

5. Deployment best practices

Install llmslim[proxy] in any Python 3.10+ environment and start Claude Code with llmslim wrap claude instead of claude. Keep ~/.llmslim/proxy.db for as long as a session lasts: it holds the bytes the proxy replays. llmslim proxy stats shows the tokens it kept out of your requests.

6. Key optimization tips

  • Leave the defaults on first: they only touch shell, search and web output over 1,500 tokens, and leave output that is one whole JSON document alone.
  • In our benchmark it paid off most on mid-sized logs whose useful lines sit in the middle: a simulated CI run (26-32% cheaper) and a lint run (17-21% cheaper). Build logs were not tested. For test runs agents already trim the output themselves.
  • Exempt a tool with --never if you rely on its exact output, for example a custom script whose output you copy from.
  • Opt data-only MCP tools in one by one, for example --tool mcp__github__list_issues.

7. Limitations

  • Claude Code already saves shell output over about 30,000 characters to a file and shows the model a 2 KB preview. The proxy only shortens shell, search and web output (and MCP tools you opt in) that reaches the model in full at over 1,500 tokens.
  • Anthropic Messages API only for now; Codex and other OpenAI-format agents are planned.
  • With a custom base URL, Claude Code turns off Remote Control. It also turns off tool search, which added about 7,100 tokens to every request in our runs with no MCP servers, and more with each MCP server; llmslim wrap claude turns it back on (ENABLE_TOOL_SEARCH=true) since 0.11.1, and you should set it yourself if you run llmslim proxy on its own.
  • Through a local proxy, claude -p started in auto permission mode instead of default in all our runs. Since 0.11.1, llmslim wrap claude starts print-mode runs in default mode unless you choose one. Interactive sessions were not tested; pass --permission-mode default yourself if it matters.
  • With a custom base URL, Claude Code skips a Team or Enterprise organization's server-managed settings. Don't use the proxy where those settings must apply.
  • On real sessions, tool output is a small part of a Claude Code bill: in a replay of the maintainer's transcripts (32 sessions and 412 subagent runs, mostly Opus 5.5, at list prices), all shell, search and web output costing nothing would have cut the bill by 13.4%. Re-reading long context was the bigger cost; Claude Code's /autocompact setting decides when it compacts.

8. Performance metrics

MetricUncompressedLLMSlimImpact
Simulated failing CI run, about 12 KB of log, the cause in the middle (real Claude Code, Haiku 5.5, default permission mode, 10 runs per arm)$0.0061 billed per run$0.004132% cheaper (26% in auto mode, 30% on 0.11.1); every run fixed the cause
Lint run: 3 errors among 240 warnings$0.0056$0.004521% cheaper (17% in auto mode)
Fix a failing test, running pytest -v$0.0036$0.0035Within noise: the agent already trims test output with tail
Pooled over 8 small synthetic tasks (0.11.0 compression, JSON included, tool search on)+5.3% in default permission mode (the primary result), -5.1% in auto mode. Shortened JSON cost about twice as much on one task, so it is off by default since 0.11.1
Thinking after a shortened tool output (one API agent-loop check, Haiku 5.5)Original output sent instead: HTTP 400Shortened version replayed: HTTP 200Thinking is bound to what the model saw; the replay keeps it valid (400 is the default for accounts created on or after 31 Aug 2026)

Frequently asked questions

Troubleshooting

Further reading