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 fills the context window until Claude Code 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.0 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: errors and the lines related to the command stay, runs of similar lines collapse into one line and a count, and JSON lists keep every item.

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. 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
Fraction of a long output to keep (never below --min-keep, 1000 tokens).
--tool / --never =
Add a tool to compress, or exempt one. Repeatable.
--mcp = off
Also compress every MCP tool's output.
--json = off
Also compress JSON output. 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.9+ 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 long shell, search and web output, and leave JSON alone.
  • It pays off most on long logs whose useful line isn't at the end: CI runs, linters, builds. 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 output over about 30 KB to a file and shows the model a 2 KB preview; the proxy works on the output that reaches the model in full, plus web results and the MCP tools you opt in.
  • 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 adds about 7,100 tokens to every request; 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 proxy, claude -p starts in auto permission mode instead of default. Since 0.11.1, llmslim wrap claude starts print-mode runs in default mode unless you choose one.
  • 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 444 real sessions, if all shell, search and web output had cost nothing, the bill would have been 13.8% lower. Re-reading long context is the bigger cost; Claude Code's /autocompact setting controls it.

8. Performance metrics

MetricUncompressedLLMSlimImpact
Failing CI run, about 12 KB of log (real Claude Code, Haiku 5.5, 10 runs per arm)$0.0061 billed per run$0.004132% cheaper, every run fixed the cause
Lint run: 3 errors among about 260 warnings$0.0056$0.004521% cheaper
Fix a failing test, running pytest -v$0.0036$0.0035Within noise: the agent already trims test output with tail
Pooled over 8 tasks, 0.11.0 settings-5% to +5%. Shortened JSON cost about twice as much on one task, so it is off by default since 0.11.1
Final request of an agent loop with thinkingOriginal output resent: HTTP 400Proxy's version resent: HTTP 200Thinking is bound to what the model saw; the replay keeps it valid

Frequently asked questions

Troubleshooting

Further reading