context-compact
Skill0 starsChanged 9 days agoMITView on GitHub
Manage long-session context using available usage signals and focused reads, and adapt (read less, delegate to subagents, recommend /compact) so long sessions stay cheap and fast. Use automatically before starting a task on a long conversation, after reading large files, or whenever context feels heavy — triggers: "context", "compact", "/compact", "token", "token usage", "context size", "heavy/cluttered/long context", "keep it light" (in any language the user speaks). Implements the auto-compact concept (budget → fill ratio → mode → adapt), the same idea as an adaptive context engine.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- edenbuilds/agentlooptheir own version, first seen Oct 13, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- edenbuilds/agentloop★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository34 other files it gives its agents.
- chatgpt/AGENTS.mdAGENTS.md
- opencode/AGENTS.mdAGENTS.md
- zcode/AGENTS.mdAGENTS.md
- claude/CLAUDE.mdCLAUDE.md
- agent-doc-authoringSkill
- agent-experienceSkill
- ai-image-promptsSkill
- api-behavior-flowSkill
- architecture-and-performanceSkill
- behavioral-testingSkill
- behavior-auditSkill
- browser-tabs-uiSkill
- code-qualitySkill
- design-principlesSkill
- design-to-deliverySkill
- design-validationSkill
- e2e-test-authoringSkill
- engineering-reviewSkill
- excalidrawSkill
- external-ai-consultSkill
- google-omni-videoSkill
- llm-agent-tool-disciplineSkill
- parallel-subagentsSkill
- qa-test-scenariosSkill
- reliable-executionSkill
- research-and-reuseSkill
- server-security-hardeningSkill
- session-handoffSkill
- shadcn-librarySkill
- sudo-handoffSkill
- task-intakeSkill
- tauri-v2-docsSkill
- test-failure-triageSkill
- user-behavior-flowSkill
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 11 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈11
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 39
Do not trigger for trivial single-file lookups on a fresh session.
- Distinctive: line 43
Use client-reported usage/window size when available.
- Distinctive: line 47
Check the budget signal: Use the active client's reported context window and usage, if available.
- Distinctive: line 48
Assess working-set pressure: If reported usage is unavailable, inspect practical signals: repeated large reads, losing relevant state, or …
- Very specific: line 56
Optional absolute cap: When client-reported context exceeds 500K tokens and that cap is relevant to the actual model, recommend /compact …
- Distinctive: line 59
Sensitive-work exception: Do NOT recommend compaction during data-loss-risk, security, irreversible-operations, or state-heavy debugging …
- Distinctive: line 82
When you summarize/drop a file, never later quote its exact code as if it is still loaded — re-read only the needed lines.
- Distinctive: line 105
Never deliver a handoff during sensitive work (see Workflow step 7).
- Distinctive: line 106
If the user declines, keep working in constrained mode — don't nag repeatedly.
- Distinctive: line 131
After compacting, the session should feel lighter: the next user turn should show a smaller working set (fewer large reads).
- Distinctive: line 133
When the client reports high pressure, a supported compaction recommendation occurs at a safe boundary.
- Distinctive: line 134
If reported usage crossed an applicable cap, note whether supported compaction was recommended or deferred for safety.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Context Compact
Purpose
Prevent context bloat using reported usage when exposed or concrete working-set pressure when not, and adapt reading and
delegation behavior before it becomes a problem. When fill gets high,
compact what you can and tell the user to run /compact (or /clear when
the task is done).
When to use
Trigger automatically when any of these holds:
- The conversation is long (10+ turns) or the user mentions "context", "compact", "/compact", "token"/"token usage", "context size", "heavy/cluttered/long context", or asks to "keep it light" — in any language the user speaks.
- About to read a file you suspect is large (> 300 lines) or whose size you don't know yet.
- Right after reading a large file while the task continues.
- The user mentions token usage, cost, or session speed.
- Exploration is complete and implementation is about to start, when actual pressure makes that a useful safe handoff point (see Rules).
Do not trigger for trivial single-file lookups on a fresh session.
Preconditions
- Use client-reported usage/window size when available. If neither is exposed, context usage is unknown; do not manufacture token counts or fill percentages.
Workflow
- Check the budget signal. Use the active client's reported context window and usage, if available. Never assume every model supports 600K/1M or that file byte counts measure the active context.
- Assess working-set pressure. If reported usage is unavailable, inspect practical signals: repeated large reads, losing relevant state, or unreliable recall. Keep usage labeled unknown; use targeted reads without inventing a percentage.
- Compare → mode using the table in Rules.
- Adapt per mode. Change how you read and delegate before doing anything else.
- Compact when heavy (fill > 70% — or the absolute cap in step 6).
Re-express what you still need as short notes; stop holding full file
contents in context; explicitly recommend
/compactto the user (and/clearwhen the task is done). - Optional absolute cap. When client-reported context exceeds 500K tokens and that cap is relevant to the actual model,
recommend
/compactimmediately — regardless of percentage bands. The goal is cutting token cost, so trigger early, not at the window edge. - Sensitive-work exception. Do NOT recommend compaction during data-loss-risk, security, irreversible-operations, or state-heavy debugging work — losing detail can change the outcome. Keep full context and state the tradeoff explicitly.
- Preserve thread and plan. Immediately before recommending
/compact//clear, write a 2–4 line handoff note (current task • plan • decisions • next steps) so the summary retains the thread. - Report only meaningful pressure. Explain a needed handoff or compaction briefly; do not emit a usage estimate on every routine read. If no usage metric is exposed, say it is unknown when asked.
Rules
| Fill | Mode | Behavior |
| < 40% | expansive | Normal workflow; still prefer relevant reads |
| 40–50% | balanced | Prefer targeted reads and search; delegate only when useful, available and authorized |
| > 50% | lean | Recommend /compact at a natural stopping point; reduce full-file holds |
| > 70% | constrained | Targeted search plus enough surrounding code for correctness; recommend compaction at a safe boundary; delegate only when available and authorized |
| > 500K tokens (absolute) | cost-cap | Recommend /compact immediately, bands ignored; write the handoff note first; never during sensitive work |
- The numeric bands above apply only to reported usage against a known window. Character/byte estimates are not reliable context measurements, especially for multilingual content.
- A full
Readadds the file to the current working context — preferReadwith offset/limit, orgrep, when a section suffices. - Multi-file search is normally a targeted local search. Delegate only when independent scopes, available tools and authorization make it useful; do not require a subagent merely because a search touches multiple files.
- When you summarize/drop a file, never later quote its exact code as if it is still loaded — re-read only the needed lines.
- At reported high pressure, avoid unnecessary large reads but retain enough context to understand every edit.
- Plan boundary: approval alone does not trigger compaction. Use a completed exploration/plan as a safe handoff point only when actual context pressure justifies it, respecting the sensitive-work exception.
Compact handoff (delivering /compact)
The agent never runs /compact itself — the user does. Deliver it exactly
like a privileged command (the sudo-handoff pattern):
- State the observed trigger. Cite reported usage if available, otherwise describe concrete working-set pressure without invented counts.
- Prepare the handoff note (2–4 lines: current task • plan • decisions • next steps), retaining the important constraints.
- Give the supported copy-pasteable command in a fenced block, then put the handoff note after it as the last content:
Preceded by one sentence of what it does and why it's needed./compact - Continue bounded useful work unless a pause is required. Recommend the command only if the client supports it. Do not block an authorized task merely because a recommendation was made; never claim compaction ran without confirmation.
- Resume from the note once the user confirms. Never assume it ran.
Rules:
- The note must be the last thing you write — the summary keeps the tail of the conversation.
- Never deliver a handoff during sensitive work (see Workflow step 7).
- If the user declines, keep working in constrained mode — don't nag repeatedly.
Common mistakes
- Counting only the last message — context is cumulative since the session started.
- Reading a whole file when grep + offset/limit would do (the biggest waste by far).
- Silently continuing after heavy reads instead of recommending
/compact— the user can't see your token usage. - Summarizing a file but then still referencing its exact contents (it's gone — you must re-read).
- Treating this skill as optional because "the AGENTS.md already has context rules" — this is the procedure for those rules; the rules are the thresholds, this is the loop.
- Recommending
/compactduring sensitive work (data-loss risk, security, irreversible ops, state-heavy debugging) just to save tokens. - Crossing 500K tokens without telling the user that every further read is expensive — a missed compaction makes each re-read costlier than the compaction itself.
Validation
- Any stated usage/band traces to client-reported metrics; unknown metrics stay unknown. Targeted reads preserve necessary edit context.
- After compacting, the session should feel lighter: the next user turn should show a smaller working set (fewer large reads).
- When the client reports high pressure, a supported compaction recommendation occurs at a safe boundary; lack of an unavailable metric is not a skill failure.
- If reported usage crossed an applicable cap, note whether supported compaction was recommended or deferred for safety; do not assert an unmeasured threshold was crossed.
- A handoff note exists right before every
/compact//clearrecommendation, so the thread and plan survived the summary. - The user confirms
/compactran, and you resume from the pre-written note rather than from memory.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

