Works with the AI Agents you already use
Token Diet Context
by Scrimal
Cut your AI agent's API bill by up to 80%: deterministic zero-token context compaction + KV prefix-cache verifier (token_diet.py verify) that stops cache-busting prompt edits.
$7.99
Token Diet Context
Example session with this skill installed
My API spend spiked on the last 10 turns. Check if pinned.md broke our KV prefix cache, compact it under 1,000 tokens, and verify the budget.
- Read your context and instructions
- Compiled the token diet context
I audited pinned.md against the previous session snapshot and compressed the bloated history without touching the immutable prefix header.
Token Diet & KV-Cache Audit
| Check | Result | Status | Impact on API Cost |
|---|---|---|---|
| KV Prefix Stability | 96.4% match | INTACT (exit 0) | Top prefix preserved — provider KV cache stays hot (90% token discount). |
Compaction (compact) | 1,840 → 420 tok | COMPRESSED | Folded 4 finished milestones into a single summary at 0 LLM tokens. |
Budget Gate (budget) | 420 / 1,000 tok | PASS (exit 0) | 580 tokens freed for active code diffs. |
$ python scripts/token_diet.py verify .start/pinned.prev.md .start/pinned.md
KV PREFIX: INTACT (96.4% shared prefix) | exit 0
$ python scripts/token_diet.py compact pinned.md --out .start/pinned.compact.md
$ python scripts/token_diet.py budget .start/pinned.compact.md --max 1000
[OK] Budget check passed: 420/1000 tokens (exit 0)
Next Steps
- Load
.start/pinned.compact.mdas your session anchor and append new logs strictly to the bottom## Session Logsection. - Wire
hooks/pi.md(or your pre-turn hook) to runtoken_diet.py verifyso an accidental edit to the top header never silently breaks your KV cache again.
Connects securely to your tools. The creator never sees your data.
About this skill
You start a coding session, edit one line at the top of your CLAUDE.md or session notes, and suddenly your Anthropic/OpenAI API bill jumps 10x—because mutating the prefix invalidated your provider's KV Prefix Cache and forced a full context re-read on every single turn.
Meanwhile, built-in /compact commands burn extra LLM tokens just to summarize your notes and often erase the exact architectural invariants you needed. Token Diet Context solves both problems deterministically at zero LLM token cost—battle-tested on a 70.5M-token, 460+ step run for just $1.43/day.
Why It Pays for Itself on Day One
- Protects Your KV Prefix Cache (
verify): Compares byte-for-byte prefix stability between session turns (INTACT >= 90%,PARTIAL_SHIFT,BROKEN < 70%) so your cached prompt tokens stay at a 90% discount instead of resetting to full price. - Zero-Token Deterministic Compaction (
compact): Compresses bloatedpinned.mdstate files locally using stdlib Python—no LLM summarization call, no hallucinated deletions. - Append-Only State Architecture: Splits session memory into an immutable top header (
Goal,Invariants,Decisions) and an append-only bottom log so the prefix hash never shifts mid-session. - Multilingual Token Budget Gate (
budget): Accurately estimates both English/code (~4 chars/token) and Cyrillic/CJK (~1.5 chars/token) withouttiktoken, enforcing hard token ceilings with CI exit codes (0OK,1WARN,2FAIL).
What's Inside
scripts/token_diet.py— Standalone zero-dependency CLI (compact,budget,verify) with atomic file writes and CI exit codes (0/1/2).references/diet_contract.md— Copy-paste session state layout (pinned_template) engineered for maximum KV-cache hit rates.hooks/pi.md— Ready-to-wire hook config for automated budget and prefix-stability checks.
Token counts use calibrated character-ratio heuristics (~4 chars/token for ASCII/code, ~1.5 for non-ASCII) rather than model-specific BPE tokenizers, giving fast zero-dependency estimates within ~10–15% of exact counts.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 2 days ago
- Software
Python 3.10+
Zero external dependencies (no tiktoken required) and zero network requests. Runs locally on your session Markdown files with atomic writes.
Permissions
File Scopes
100% local & offline. Runs stdlib token_diet.py on local session handoff files (.start/**) with zero network calls.
What's inside
Frequently Asked Questions
New in LLM Ops
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for LLM Ops.