Token budgeted compaction with reinjection

From ychampion/cskill-agents · View interactive version

Token budgeted compaction with reinjection is an AI agent skill from the GitHub repository ychampion/cskill-agents. Keep compaction budgets under control by compacting incrementally and reinjecting truncated attachments only when the reasoning surface remains stable.

How to use this skill

Skill file

SKILL: Token Budgeted Compaction With Reinjection

Domain: compaction

Trigger: Use when session history is growing toward the API limit and you need a safe way to trim older context while still reinjecting critical artifacts like skill metadata.

Source Pattern: Distilled from reviewed session memory, compaction, and context-budgeting implementations.

Core Method

Run compaction in capped batches tied to a per-skill token budget: truncate each skill/document to <= 5k tokens, enforce an overall skill budget (25k tokens), bubble up warnings when budgets are hit, and only reinject the trimmed content when downstream turns request it. Keep a reusable helper that resets the per-skill counters after a compact run so the next turn starts from a clean slate.

Key Rules

Example Application

When a Claude Code conversation runs long, apply this skill to compact turns by triming per-skill summaries down to 5k tokens, track the remaining budget, warn when the budget is exhausted, and include the reinjected skill attachments alongside the next query so the model has the context it needs.

Anti-Patterns (What NOT to do)

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.