Works with the AI Agents you already use

    Token Diet Context

    by Scrimal

    1

    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

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Token Diet Context

    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

    CheckResultStatusImpact on API Cost
    KV Prefix Stability96.4% matchINTACT (exit 0)Top prefix preserved — provider KV cache stays hot (90% token discount).
    Compaction (compact)1,840 → 420 tokCOMPRESSEDFolded 4 finished milestones into a single summary at 0 LLM tokens.
    Budget Gate (budget)420 / 1,000 tokPASS (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

    1. Load .start/pinned.compact.md as your session anchor and append new logs strictly to the bottom ## Session Log section.
    2. Wire hooks/pi.md (or your pre-turn hook) to run token_diet.py verify so 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 bloated pinned.md state 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) without tiktoken, enforcing hard token ceilings with CI exit codes (0 OK, 1 WARN, 2 FAIL).

    What's Inside

    1. scripts/token_diet.py — Standalone zero-dependency CLI (compact, budget, verify) with atomic file writes and CI exit codes (0/1/2).
    2. references/diet_contract.md — Copy-paste session state layout (pinned_template) engineered for maximum KV-cache hit rates.
    3. 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. 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. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

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

    Terminal / Shell
    Read Files
    Write Files

    File Scopes

    .start/**
    scripts/**
    references/**
    hooks/**

    100% local & offline. Runs stdlib token_diet.py on local session handoff files (.start/**) with zero network calls.

    Listed4 days ago
    Updated2 days ago

    What's inside

    Frequently Asked Questions

    Token Diet Context solves the 'context collapse' problem where long-running AI sessions become slow and expensive due to redundant logs and repetitive notes. It uses a deterministic Python guard to enforce strict token budgets and stabilize the KV cache for faster, cheaper inference.

    This is a framework-agnostic Python guard that works with any LLM supporting KV-caching, including GPT-4 and Claude. It operates as a zero-dependency script, making it compatible with both custom Python agents and established orchestration frameworks.

    You receive SKILL.md (the progressive-disclosure & KV-cache protocol), scripts/token_diet.py (zero-dependency CLI with compact, budget, and verify commands + exit codes 0/1/2), references/diet_contract.md (an append-only pinned.md template engineered for prefix stability), and hooks/pi.md for automated pre-turn checks.

    Unlike soft prompting, which agents often ignore as context grows, this skill uses a hard-coded Python script to monitor and prune data before it reaches the LLM. It acts as a physical 'circuit breaker' that prevents the agent from even seeing bloated or redundant information.

    Setup takes under two minutes: copy the append-only layout from references/diet_contract.md into your pinned.md session file, then run token_diet.py compact and verify (or wire hooks/pi.md) to keep your prompt prefix immutable and within budget.

    The included script uses a deterministic character-based approximation for token counting to ensure zero-dependency performance. While not an exact match for model-specific encoders like tiktoken, it is calibrated to provide a safe buffer that prevents context overflow across all major providers.

    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.