agentsclimarketplace

Token budgeted compaction with reinjection

Skill ychampion/cskill-agents/agents/codex/skills/token-budgeted-compaction-with-reinjection

Agent skills for coding CLIs, multi-agent runtimes, context engines, MCP extensions, and terminal tooling. Instead of using claude code's source code, give your agent skills to create your own!

Install
npx -y skills add ychampion/cskill-agents --skill token-budgeted-compaction-with-reinjection

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

What its author says it does

Copied from the file, not written here

Keep compaction budgets under control by compacting incrementally and reinjecting truncated attachments only when the reasoning surface remains stable.

SKILL.md

2.3 KB, as published. Nobody here has run it

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

  • Truncate at most the allowed per-skill token amount and track how many tokens were retained; this becomes the compact summary that can be reinjected later.
  • Reserve a shared skills token budget and subtract each truncated skill from it; stop truncating once the budget is exhausted and emit a warning so the user knows some instructions were dropped.
  • Reinjection occurs during the next turn only after the compact boundary moves; do not ring the same trimmed skill multiple times in one turn.
  • Emit attachments for reinjected content so the downstream model can fetch specific sections rather than re-running the entire compact logic.

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)

  • Don't truncate skills arbitrarily without tracking their token costs; you need to know which instructions survived to explain compaction decisions to the user.
  • Don't reinject the same trimmed data repeatedly in the same turn; the budget is about the current turn, so reinject only after a new compact boundary has been established.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.