frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

Claude Code's API billing depends on how often the cache expires

1•MaxBozhenko•7m ago
Hello, HN! I’m Max, CTO at Hystax. We use Claude a lot in our development work, and we’re also trying to make coding agents cheaper to run. We built the open-source Kompressor for compressing identical tool outputs that agents constantly resend. In our Codex tests, we noticed a real cost reduction of 22.7%. But testing it with Claude Code, we found something completely different. In Claude Code, the cache plays a more crucial role than compression.

Claude Code marks its messages with caching points. As a result, almost every request consists of a long cached prefix and a new, truncated final part. Based on practical experience with Opus 5.5, reading from the cache appears to cost $0.20 per million tokens, accounting for about 92–95% of the tokens charged for prompts. Meanwhile, a five-minute cache entry costs $5, which is 25 times more expensive than reading from the cache. When an agent needs to run a build or a longer training cycle, they face the problem of the cache expiring. The next request then has to write the prefix to the cache again. We saw this 33 times in a cycle of 89-task runs without compression. As a result, 927,000 tokens were rewritten, which is approximately one-third of the volume billed in full.

Until now, we’ve deliberately left the Claude Code text uncompressed because overwriting any byte within a cached prefix would very likely cause it to become invalid. But here’s what we came up with instead:

– Compress only the uncached part. On the first transmission, only the new part is compressed. Everything already cached stays byte-for-byte unchanged. Fragments shorter than 4,000 characters are sent in full, since compressing each fragment would be much more expensive than sending the entire dialogue as is.

– Keep the cache active while the tools are running; don’t let it expire. While the agent waits for a tool response (model building/training), Kompressor resends the last request every 4.5 minutes with max_tokens: 1, so Anthropic re-reads the cached dialogue, and the five-minute timer restarts. Pings stop on the agent’s next request, after ~50 min, on the first failed attempt, or if a ping finds nothing in the cache.

– Switch to the one-hour cache only when necessary. After the first pause longer than 5 min, Kompressor requests a one-hour cache for that conversation.

We ran Claude Code on the Opus 5.5 model through the Terminal-Bench 2.1 benchmark (89 tasks) and calculated the cost based on Anthropic's actual billing, including pings. The cost per run decreased from $35.35 to $28.30 (-20%). The percentage of tasks solved by the agent without compression was 89.9%, and 90.6% when using Kompressor. The number of tokens lost due to cache expiration decreased from 927,000 to 13,000.

But there’s a caveat: the agent never solves the same task twice in exactly the same way, and the entire difference came down to just 4 out of the 89 tasks. We expect these savings to persist from run to run: about 11% from keeping the cache up to date, and a few more percentage points from compression. This effect is most noticeable on tasks where the agent waits a long time – more than five minutes – for a command to execute: model training, compilation, and long simulations. In those cases, costs decreased by 34%. To try Kompressor, see the GitHub repo below. Setup is in the README. The default configuration already includes compression of new text only and a switch to an hourly cache on long pauses; “keep-warm” is off (the only request that the proxy sends on its own). To enable, add to your config:

     [proxy.providers.anthropic] 
     cache_keep_warm = true
and then run:

    kompressor wrap claude 
The benchmark above was run with all these settings enabled.

Here are cost calculations: https://optscale.ai/blog/claude-code-prompt-caching If you run long tasks in Claude Code, how often does the cache expire while a tool is still running? Have you seen this with other providers too?

ExecuTorch WebGPU: PyTorch Models on the GPU, in the Browser

https://pytorch.org/blog/executorch-webgpu-pytorch-models-on-the-gpu-in-the-browser/
1•wondersky•17s ago•0 comments

Show HN: Applygate, stop coding agents from running Terraform destroy in prod

https://github.com/Flurit/applygate
1•sumantth•1m ago•0 comments

Zero-Initialisation Shenanigans

https://napcakes.nekoweb.org/posts/zero-init/
1•dverlaeckt80•3m ago•0 comments

Electric Ship Batteries Promise Compact, Cooler Power

https://spectrum.ieee.org/electric-ship-batteries
1•rbanffy•3m ago•0 comments

Jane Street – Our software engineering interviews are changing (a little)

https://blog.janestreet.com/software-engineering-interviews-are-changing-a-little/
1•maitland•4m ago•0 comments

Testing a Trash Can Faraday Cage

https://www.jefftk.com/p/testing-a-trash-can-faraday-cage
1•torutofu•5m ago•0 comments

Labs Suck

https://buttondown.com/TYFYFL/archive/labs-suck/
1•speckx•6m ago•0 comments

Four weeks of list prices from 10 research peptide stores

https://peptidebureau.com/peptide-price-and-law-report.html
1•peptidebureau•6m ago•0 comments

New Super Magnets Turbocharge the Large Hadron Collider

https://spectrum.ieee.org/large-hadron-collider-superconducting-magnets
1•rbanffy•6m ago•0 comments

Compromised GitHub accounts push CI secret stealer to repositories

https://www.aikido.dev/blog/compromised-github-accounts-push-ci-secret-stealer-to-tens-of-thousan...
1•jamilbk•7m ago•0 comments

Claude Code's API billing depends on how often the cache expires

1•MaxBozhenko•7m ago•0 comments

Show HN: Upstar, GitHub projects ranked by velocity in each topics

https://upstar.dev/
1•armelmatio•7m ago•0 comments

OPG set to revise timeline and cost of first SMR unit

https://www.world-nuclear-news.org/articles/opg-to-revise-timeline-and-cost-of-first-smr-unit
1•PaulHoule•7m ago•0 comments

Nvidia CEO Jensen Huang resigns after reports of extramarital relationships

https://www.nbcnews.com/tech/tech-news/nvidia-ceo-jensen-huang-resigns-reports-extramarital-relat...
6•sonabinu•8m ago•1 comments

Pixelate the World

https://googlemapsmania.blogspot.com/2026/10/pixelate-world.html
1•surprisetalk•9m ago•0 comments

Show HN: MergeMax, a monthly ranking of public merged PRs on GitHub

https://mergemax.dev
1•diancodes•12m ago•0 comments

Ask HN: Can I still earn money on ANT IPO?

1•roschdal•12m ago•0 comments

Nvidia CEO Jensen Huang resigns after reports of second affair deepened scandal

https://www.bbc.co.uk/news/live/c6zjry11v8w1t
19•cognoboffin•13m ago•2 comments

Skipping Cloud SDKs: How ScopeDB Accesses Object Storage with Apache OpenDAL

https://opendal.apache.org/blog/2026/11/11/scopedb-on-opendal/
3•tison•13m ago•0 comments

Jensen Huang resigns as Nvidia CEO immediately

https://www.reuters.com/live/nvidia-live-board-meets-fate-ceo-jensen-huang-after-affair-reports-2...
33•ksec•13m ago•9 comments

Jensen Huang Resigns as CEO, Colette Kress Named Interim

https://www.bloomberg.com/news/live-blog/2026-11-11/nvidia-turmoil-board-to-weigh-ceo-jensen-huan...
6•jbredeche•15m ago•0 comments

Jensen Huang resigns as chief executive after affair allegations

https://www.ft.com/content/b4a0f3d9-f075-47ea-9a85-77cdade9a06f
2•zomtorg•15m ago•0 comments

Jensen Huang resigning effective immediately

https://www.stocktitan.net/news/NVDA/nvidia-announces-ceo-03al5m45ne1p.html
12•chrisss395•17m ago•9 comments

NVIDIA Announces CEO Transition

https://nvidianews.nvidia.com/news/nvidia-announces-ceo-transition
243•lldb•17m ago•120 comments

Anduril says its first satellite can see adversaries maneuver in orbital night

https://arstechnica.com/space/2026/11/anduril-demos-night-vision-sensor-for-tracking-satellites-i...
1•Brajeshwar•19m ago•0 comments

Cameras in space could help spot invasive plants on Earth

https://www.economist.com/science-and-technology/2026/11/11/cameras-in-space-could-help-spot-inva...
1•Brajeshwar•19m ago•0 comments

Silicon Valley Podcast Hosts Try to Understand Why Regular People Are Mad

https://www.404media.co/silicon-valley-podcast-hosts-try-to-understand-why-regular-people-are-mad/
1•Brajeshwar•19m ago•1 comments

Independent Curl – Procedural GPU Patterns

https://catlikecoding.com/godot/procedural-gpu-patterns/11-independent-curl/
1•ibobev•19m ago•0 comments

The difference between undefined behavior and ill-formed C++ programs

https://devblogs.microsoft.com/oldnewthing/20240802-00/?p=110091/
2•ibobev•19m ago•0 comments

Trump proposed a 'secret weapon' to police colleges. It will soon become reality

https://text.npr.org/nx-s1-6027967
2•mooreds•20m ago•0 comments