This release is a pre-release and may not be stable for production use.
cacheplan
Diagnose LLM prompt caching, forecast what each setting would cost, and plan the fix.
Prompt caching can cut input cost by more than half, or raise it by a quarter. Which one
you get depends on how your application builds its prompts and how fast requests arrive.
cacheplan reads a log of your requests and tells you, per application:
- where and why the reusable prefix breaks (a timestamp in the system prompt, tools in a different order, new turns inserted before content that was already sent);
- what each option would cost: caching off, automatic caching, planned breakpoints, with the 5-minute or the 1-hour lifetime, from a local model of the provider's caching rules;
- what to do: the cheapest simple option, where to put the breakpoints, and whether a small prompt change would unlock more;
- whether the forecast is right: an optional replay against the live API, one output token per request.
It runs locally, has no dependencies, and needs no API key except for the live check. Status: early alpha. Anthropic Messages API only.
Install
pip install --pre cacheplan
Use
cacheplan report requests.jsonl
Example output, abridged (LangChain's ReAct agent template):
react-template
17 requests, ~113,000 input tokens (estimate)
Layout changing content at the top of the prompt
Reusable 2% of input tokens repeat an earlier prefix as written
Pace median 4 s between requests; 6% of pauses over 5 minutes
Option Read Cost vs no caching
Caching off 0% 100% <- recommended
Automatic caching, 5-minute 0% 125%
Planned breakpoints, 5-minute 0% 100%
Prompt fix + breakpoints, 5-minute 62% 53%
Recommendation: leave caching off as the prompts stand.
With the prompt fix in the findings: 53%. It changes what the model reads,
so compare answer quality before adopting it.
Findings
CP001 system value <<system_time>> changes between requests; everything after it,
including the conversation history, cannot be reused
fix: move it to the latest user message, or make it change rarely
No log yet? Record one. The proxy writes request bodies only; headers, and so your API key, never reach the file.
cacheplan capture --out requests.jsonl --app my-app
# in the shell that runs your application:
# ANTHROPIC_BASE_URL=http://127.0.0.1:8787
| Command | What it does |
|---|---|
report LOG |
Diagnosis, forecast and recommendation per application. --json, --no-content, --fail-on CP001,CP002. |
diagnose LOG -v |
Every prefix break: where, what changed, how many tokens sit behind it. |
verify LOG --model M --yes |
Replays the recommended options against the live API and prints forecast next to measured. |
gaps LOG |
How the forecast changes as pauses between requests grow. |
check LOG --min-reusable 0.5 |
For pipelines: exit status 1 when too little of the prompt is reusable. |
capture --out LOG |
Logging proxy. |
rules |
Rule ids. |
--learn-from OTHER.jsonl learns the breakpoint plan from one log and scores another, for
an out-of-sample forecast.
Log formats
One JSON object per line; formats can be mixed in one file:
- a
cacheplan captureline; - a raw Anthropic request body;
- a promptcachelint trace record.
What it found so far
Measured on 23 November 2026 with one model, short sessions. Cost is input cost relative to the same prompts sent without caching.
| Application | Layout | Automatic caching | cacheplan | Source |
|---|---|---|---|---|
| LangChain ReAct agent template | timestamp in the system prompt | 125% | 51% with the prompt fix | live API |
| Aider | finished turns inserted mid-prompt | 125% | 66% with planned breakpoints (Aider's own caching: 67%) | live API, plan learned on a different session |
| Claude Code | append-only conversation | 27% | 27%: nothing to change | local model |
The local model's forecast was within two points of the live measurement in every comparison.
Limits
- Small evidence base. Three applications, one or two short sessions each.
- The forecast is a model. It follows the documented caching rules; token counts are
estimated at three characters per token. Use
verifybefore acting on a close call. - The minimum cacheable length varies by model. The default is 1,024 tokens; set
--min-tokensfor yours. - The prompt fix changes what the model reads. It never drops content, but its effect on answer quality is not measured. Treat it as a suggestion to implement and test yourself.
- The 1-hour lifetime has had one live check. The request was accepted and the read share matched the forecast; its price is taken from the documentation.
- Plans are learned from the log you give it. A short or unrepresentative log gives a
poor plan. Use
--learn-fromto test on a second log. - Anthropic only. OpenAI and others are planned.
Related tools
promptcachelint and
cachelint explain why a prompt cache missed, and both
support OpenAI as well. cacheplan overlaps with them on diagnosis and adds the forecast,
the breakpoint plan, the lifetime choice and live verification.
Development
pip install -e ".[dev]"
python -m pytest -q
Licence: Apache-2.0.
Metadata
Release files for cacheplan 0.1.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cacheplan-0.1.0a1.tar.gz | 42.5 kB | With provenance | Details for cacheplan-0.1.0a1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cacheplan-0.1.0a1-py3-none-any.whl | Python 3 | none | any | Details for cacheplan-0.1.0a1-py3-none-any.whl |
Total release size: 75.4 kB
Release files / cacheplan-0.1.0a1.tar.gz
| Download URL | cacheplan-0.1.0a1.tar.gz |
|---|---|
| Size | 42.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6cbe593ee8d2cfb492b90d8e3e49c272fe912e7cb416a048056020734c8676e5
|
|
BLAKE2b-256 checksum How to use checksums |
19f37d121d9b033ff50966895e1144a85c6acb822f6917d60a1c25381fdd5ae6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logRelease files / cacheplan-0.1.0a1-py3-none-any.whl
| Download URL | cacheplan-0.1.0a1-py3-none-any.whl |
|---|---|
| Size | 32.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3a91768d808cd8c2f06c4d3623222d419a934c5ba1bf2d3196e836df9bb0e3b5
|
|
BLAKE2b-256 checksum How to use checksums |
aa7ce213d2199414a191d4215a2afefa6acf9beb9166eafceb16bded13d0643c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logSecurity for cacheplan 0.1.0a1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for cacheplan-0.1.0a1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.