agentleFS
sefaertuncsefaertunc/Worclaude/.claude/skills/context-management/SKILL.md

context-management

Skill4 starsChanged 7 months agoMITView on GitHub

Context budget awareness, when to compact, when to clear, subagent offloading

14 other projects use a version of this, 1 of them edited.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

10 rules. 0 are common, 10 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 13 edited versions we read keep these.

  • 10

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use when: you're mid-task and need more room but want to keep working.

    line 29
  2. Distinctive:

    After compaction, always re-orient:

    line 33
  3. Distinctive:

    Use when: you're starting a genuinely new task with no relationship to the current one.

    line 39
  4. Distinctive:

    Use when: a side task would pollute your main context (research, testing, file generation).

    line 44
  5. Distinctive:

    When a new Claude Code session opens, a hook automatically injects:

    line 76
  6. Distinctive:

    Use /start for additional context (handoff files, agent routing).

    line 82
  7. Distinctive:

    If the session summary is missing or stale, /start still reads PROGRESS.md and handoff files as fallback.

    line 98
  8. Distinctive:

    After compaction, only 5 files are restored at 5k tokens each.

    line 144
  9. Distinctive:

    Don't compact right before a complex merge or refactor.

    line 171
  10. Distinctive:

    After /compact, always verify your understanding before making changes.

    line 173

“Common” is measured: kept by at least 6 in 10 of the 13 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Context Management

Note: The bash examples below are reference snippets. If you enable disableSkillShellExecution in Claude Code settings (v2.1.101+), any inline shell execution from skills is blocked. These fenced examples are safe to read; copy-paste them into your terminal to run.

The 70% Rule

Context windows are finite. When you estimate you've used roughly 70% of available context, it's time to act. Don't wait until you're out of room — you lose the ability to reason well before you hit the hard limit.

Signs you're running low:

  • You've read many large files in this session
  • You've had a long back-and-forth conversation
  • You're working on a second or third major task
  • Responses are getting slower or less coherent

Three Tools, Different Jobs

/compact — Compress and continue

Use when: you're mid-task and need more room but want to keep working. What it does: summarizes conversation history, freeing context. Pair with: PostCompact hook that re-reads CLAUDE.md and PROGRESS.md automatically.

After compaction, always re-orient:

  • What task am I working on?
  • What branch am I on?
  • What did I just do?

/clear — Fresh start

Use when: you're starting a genuinely new task with no relationship to the current one. What it does: wipes conversation entirely. Caution: you lose ALL context. Make sure PROGRESS.md is updated first.

Subagents — Offload without losing context

Use when: a side task would pollute your main context (research, testing, file generation). What it does: spawns a separate context that does work and returns results. Your main context stays clean.

Decision Matrix

SituationAction
~70% context, mid-task/compact
Task complete, starting unrelated work/clear
Need to research something tangentialSubagent
Need to run tests while continuing designSubagent
Context feels sluggish, responses degrading/compact
Long debugging session, found the fix/compact, then implement

PostCompact Hook

The workflow installs a PostCompact hook that runs:

cat CLAUDE.md && cat docs/spec/PROGRESS.md 2>/dev/null || true

On Windows, this command runs in Git Bash (installed with Git for Windows).

This ensures you never lose your bearings after compaction. The hook fires automatically — you don't need to re-read these files manually.

Session Persistence

The workflow automatically maintains session continuity:

SessionStart Hook (automatic)

When a new Claude Code session opens, a hook automatically injects:

  • CLAUDE.md — project conventions and rules
  • PROGRESS.md — current project state
  • The most recent session summary from .claude/sessions/

You don't need to manually re-read these. The hook handles it. Use /start for additional context (handoff files, agent routing).

Session Summaries

Session summaries are written to .claude/sessions/ by:

  • /commit-push-pr — writes a summary before committing (completed work)
  • /end — writes a summary before the handoff commit (in-progress work)

These are local files (gitignored) that bridge the gap between sessions. They're automatically picked up by the next session's SessionStart hook.

The Continuity Chain

Session 1: work → /commit-push-pr → writes session summary → push
Session 2: SessionStart hook → reads summary → knows what happened → /start for extras

If the session summary is missing or stale, /start still reads PROGRESS.md and handoff files as fallback. The system degrades gracefully.

Hook Profiles

Control which hooks fire via the WORCLAUDE_HOOK_PROFILE environment variable:

ProfileHooks ActiveUse When
minimalSessionStart, PostCompact onlyExploring, learning, minimal overhead
standardAll hooks (default)Normal development
strictAll hooks + TypeScript checkingPre-release, team CI, maximum safety

Set in your shell:

export WORCLAUDE_HOOK_PROFILE=minimal   # lightweight
export WORCLAUDE_HOOK_PROFILE=standard  # default (same as unset)
export WORCLAUDE_HOOK_PROFILE=strict    # maximum enforcement

Or per-session:

WORCLAUDE_HOOK_PROFILE=strict claude

The default is standard if the variable is not set. You don't need to do anything for normal development — the default just works.

Token Budgets (Reference)

Approximate values from Claude Code v2.1.88 source (March 2026). These may change between releases.

ResourceBudget
Context window (default)200,000 tokens
Context window (Opus 4.6 / Sonnet 4.6 with 1M)1,000,000 tokens
Max output tokens (Sonnet 4.6)32,000 default, 128,000 upper limit
Max output tokens (Opus 4.6)64,000 default, 128,000 upper limit
Tool presence overhead~500 tokens (added when any tools are enabled)
Post-compact file restore5 files max, 50,000 token budget, 5,000 per file
Post-compact skills restore25,000 token budget, 5,000 per skill
Compact summary output20,000 tokens max
CLAUDE.md total budget~40,000 characters across all loaded instruction files
MEMORY.md (native, ~/.claude/)200 lines / 25,000 bytes

Practical takeaways:

  • After compaction, only 5 files are restored at 5k tokens each. Structure your work so the most important files are recently read.
  • Skills over 5k tokens get truncated after compaction. Keep skills focused.
  • The 70% rule still applies — these numbers help you estimate when you'll hit it.

Context Budget Tiers

Monitor your context usage and adjust behavior accordingly:

TierContext FreeBehavior
PEAK>75%Normal operation — read files freely, keep full context
GOOD50-75%Be selective about file reads — summarize large files
DEGRADING25-50%Summarize before reading new files, consider /compact
CRITICAL<25%Save state immediately, /compact, reload only essentials

Heuristics (you cannot measure exact tokens):

  • Many large file reads in this session = likely DEGRADING
  • Long conversation with multiple tasks = likely DEGRADING
  • Just started or just compacted = likely PEAK

Gotchas

  • Compacting doesn't free as much context as you think. If you've read 20 large files, compaction helps but won't get you back to fresh. Consider /clear if the task is done.
  • Subagents don't share your conversation context. They start fresh. Give them explicit instructions and file paths — don't assume they know what you know.
  • Don't compact right before a complex merge or refactor. You'll lose the nuanced understanding of the changes you've been building up.
  • After /compact, always verify your understanding before making changes. The summary may have lost important details.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.