Largest first context shedding

From ychampion/cskill-agents · View interactive version

Largest first context shedding is an AI agent skill from the GitHub repository ychampion/cskill-agents. When a single API-level user message trips the per-message tool-result budget, drop the largest fresh results first so the model still receives the frozen context at the tightest budget point.

How to use this skill

Skill file

SKILL: Largest First Context Shedding

Domain: tool-result-budget

Trigger: Apply when one outbound user message exceeds the tool-result budget and you must decide which fresh results to replace first.

Source Pattern: Distilled from reviewed per-message budgeting and tool-result persistence implementations.

Core Method

Gather eligible tool-result candidates per API-level message, keep track of the frozen size contributed by already-seen results, and sort the fresh candidates in descending size order. Subtract each candidate from the running total until the total drops beneath the budget. Replace only the selected large entries with persisted preview messages while leaving smaller or previously seen blocks untouched so the largest tokens are shed first.

Key Rules

Example Application

A user turn emits four tool-result blocks totaling 120k characters while the per-message budget is 50k. Select the two largest fresh results for persistence first, replace them with previews, and keep the smaller blocks inline if they still fit.

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.