Skip to main content

CacheSurgeon

Active Prefix-Cache Surgeon, Net-Savings TTL Warmer, Reversible Secret Vault, and Tool-Call Firewall for Autonomous AI Agents.

Stop paying 10× for broken prompt caches, idle 5-minute TTL rebuilds, runaway coding-agent loops, and accidental .env secret leaks.


Why CacheSurgeon Exists

Passive LLM gateways (LiteLLM, Portkey, Bifrost) forward broken prompts untouched. Autonomous coding agents (Codex, Claude Code, Cursor, Horizon Zero, OpenHands) resend 50K–200K tokens on every turn—meaning a single reordered tool JSON key or per-second timestamp in line 1 of the system prompt destroys 100% of prompt caching.

CacheSurgeon operates in flight in < 2 ms:

Stage What It Does Real Impact
01. Prefix-Cache Surgeon + X-Ray Deterministically sorts tool arrays & JSON keys, relocates volatile system timestamps/trace IDs to the trailing user turn, and injects Anthropic cache_control breakpoints. 40–87% cloud bill cut; 0% → 98.7% cache hit & 64× speedup verified on local MLX.
02. Net-Savings TTL Warmer Tracks active Anthropic 5-min / OpenAI TTL windows and pings only when cold_rebuild_cost > 2× ping_cost, reporting transparent Gross − Ping = Net savings. Prevents 10× cold cache rebuild spikes after short code-review pauses.
03. Reversible Secret & PII Vault Scrubs AWS, OpenAI, Stripe, Anthropic, Google, GitHub, Slack, JWT, PEM, DB URLs, and PII into opaque tokens (__CS_AWS_ACCESS_KEY_01__) before cloud egress. Zero raw credentials leave your VPC or touch SQLite audit logs.
04. Tool-Call / MCP Firewall Inspects model-emitted OpenAI tool_calls and Anthropic tool_use blocks before local execution, blocking rm -rf, DROP TABLE, curl | bash, SSH key reads, and force-pushes to main. Pre-execution CISO guardrail with structured compliance logs.
05. Loop Breaker & Safe Failover Fingerprints repeating failing tool loops (warn / autonomous pivot / HTTP 429 hard trip), enforces hard USD session budgets, and defaults to same-family safe downgrade on upstream 429. Eliminates OWASP LLM10 Denial-of-Wallet surprises.

30-Second Quickstart

pip install git+https://github.com/jsumpter415/cachesurgeon.git
cachesurgeon start --port 8787

Open the live Power-Grid Telemetry Cockpit at http://127.0.0.1:8787 (click Simulate Agent Attack & Leak to see all 5 stages fire immediately without needing an API key).

Connect Any Coding Agent (1 Env Var)

# OpenAI / Codex / Cursor / Product Behavior Investigator
export OPENAI_BASE_URL="http://127.0.0.1:8787/v1"

# Anthropic / Claude Code
export ANTHROPIC_BASE_URL="http://127.0.0.1:8787"

# Local Ollama (accelerated through CacheSurgeon)
export OLLAMA_BASE_URL="http://127.0.0.1:8787/v1"

Deploy On-Premise via Docker

docker compose up -d

Export Expense-Ready Executive ROI Receipt

cachesurgeon receipt --out monthly-roi.html

Public Landing Site (site/)

The static marketing & interactive surgical operating theater site lives in site/ (zero build step, zero framework bloat) and ships with .github/workflows/pages.yml for 1-click GitHub Pages deployment (or drop straight onto Cloudflare Pages / Netlify).

Offline Ed25519 Licensing (Air-Gapped Friendly)

# Vendor: generate signing keypair once
cachesurgeon license keygen

# Vendor: mint a signed customer key (no DRM phone-home required)
cachesurgeon license issue --private-key "<PRIV_B64>" --tier team --org "Acme Corp" --seats 25

Pair CacheSurgeon with our open-source Antigravity & Codex forensic debugging plugin, Product Behavior Investigator (v1.1.0):

  • Product Behavior Investigator traces user-visible failures across client, edge, API, and rollout cohorts to the first broken contract with a 6-heading Evidence Report.
  • CacheSurgeon runs underneath it to cut multi-turn investigation token bills 40–87%, scrub .env/log secrets before cloud egress, and block destructive tool calls.

Development & Tests

pip install -e ".[dev]"
pytest -v

Metadata

Release files for cachesurgeon 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cachesurgeon 0.1.0
File Size Uploaded Provenance Actions
cachesurgeon-0.1.0.tar.gz 64.9 kB With provenance Details for cachesurgeon-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cachesurgeon 0.1.0
File Interpreter ABI Platform Actions
cachesurgeon-0.1.0-py3-none-any.whl Python 3 none any Details for cachesurgeon-0.1.0-py3-none-any.whl

Total release size: 125.2 kB

Release files / cachesurgeon-0.1.0.tar.gz

Download URL cachesurgeon-0.1.0.tar.gz
Size 64.9 kB
Tags Source
SHA-256 checksum
How to use checksums
06d5e80af595bcacf6a38220ae5a1fbcb6a39f77d801c0cbb77f340892839a09
BLAKE2b-256 checksum
How to use checksums
5c26ade46a26e51d82dcf4145f92d48e24603208f3d5491ab634347015459b1d
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 Dec 1, 2026.

Transparency log

Release files / cachesurgeon-0.1.0-py3-none-any.whl

Download URL cachesurgeon-0.1.0-py3-none-any.whl
Size 60.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed016c593322fd4440b02f8c75a2d73b4de2c98ca6d0892b0afa6a3331efddd0
BLAKE2b-256 checksum
How to use checksums
3b9fe6a06a34578f1dea1966d436930e58f4eb55c2890ba3dcfa637d60ef3516
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 Dec 1, 2026.

Transparency log

Security for cachesurgeon 0.1.0

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.

Select from 2 files

Attestation for cachesurgeon-0.1.0.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 Dec 1, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page