context-mgmt

context-mgmt is a skill for Claude Code, Codex from ariaxhan/kernel-claude. It costs 42 tokens per session (936 once invoked), scanned A, original, MIT.

A guide to managing an AI agent's working context and token budget. It covers shortening context, keeping structured notes, sharing research through summaries, and restoring important state after a reset.

In plain words
What is it for?
Use it to monitor context usage, write handoff notes, store active task state, delegate research, limit unnecessary reads, and recover after compaction.
Why use it?
It helps preserve important decisions and reasoning when a task becomes large or the conversation needs to be compacted.

Skill for Claude CodeCodex

Part of the kernel plugin — 28 skills, 13 agents, 9 hooks shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/ariaxhan/kernel-claude/context-mgmt
Any agent
npx skills add ariaxhan/kernel-claude --skill context-mgmt
Clone the repo
git clone --depth 1 https://github.com/ariaxhan/kernel-claude

Made for: Claude Code, Codex.

Or install kernel, the plugin that ships this one along with the rest of its 28 skills, 13 agents, 9 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for context-mgmt

README.md
[![agentmods](https://agentmods.dev/badge/skills/ariaxhan/kernel-claude/context-mgmt.svg)](https://agentmods.dev/skills/ariaxhan/kernel-claude/context-mgmt)
Your own site
<a href="https://agentmods.dev/skills/ariaxhan/kernel-claude/context-mgmt"><img src="https://agentmods.dev/badge/skills/ariaxhan/kernel-claude/context-mgmt.svg" alt="Measured on agentmods" height="20"></a>
Per session 42 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 936 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00042 $0.00936
Opus 5 $0.00021 $0.00468
Sonnet 5 $0.00008 $0.00187
Haiku 4.5 $0.00004 $0.00094

Measured 4d ago against content hash a113c067c1f6, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

context-mgmt scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/context-mgmt/SKILL.md · 100 lines

What it actually says

Reasoning fidelity is the real metric, not token count. Quality degrades at ~60-70% fill, not at the limit.

<core_principles>

  1. COMPACTION: Summarize and reinitialize. Keep architecture decisions, discard noise.
  2. STRUCTURED NOTES: AgentDB + active.md persist across context resets.
  3. MULTI-AGENT: Delegate research to subagents. They explore, report summaries.
  4. MINIMAL READS: grep/glob to find, then read specific sections.
  5. TOOL RESULT CLEARING: Old tool output rarely needs to stay in context. </core_principles>

<token_budget>

  • CLAUDE.md: <150 lines (always loaded)
  • rules/: <100 lines (always loaded)
  • Skills: metadata only at startup, full content on demand
  • Commands: only when invoked
  • Reference docs: only when skill explicitly reads them </token_budget>

<compaction_protocol>

  1. CHECK fill level via /context. (gate: <60% → continue; ≥60% → proceed to step 2)
  2. Write critical state: agentdb write-end '{"did":"X","next":"Y","blocked":"Z"}'
  3. Commit any uncommitted changes. (gate: clean working tree)
  4. Generate handoff if complex work in progress: /kernel:handoff
  5. Trigger compaction.
  6. POST-COMPACT RESTORE: a. Read active.md for project context. b. Run agentdb read-start for failures, patterns, contracts. c. Check for pending checkpoints to review. </compaction_protocol>

<fidelity_signals> Watch for reasoning degradation BEFORE the token meter shows a problem:

  • Hypothesis depth dropping: agent defaults to first idea, stops exploring alternatives
  • Backtracking absent: errors patched in place instead of root-caused
  • Step count contracting: multi-step plans collapse to one-shot attempts
  • Cross-file awareness fading: agent forgets earlier files in the same session
  • Inline checks disappearing: agent stops verifying assumptions before acting

Any one of these → compact or hand off NOW, even if /context shows <60% fill. </fidelity_signals>

<what_to_preserve> Never compact away:

  • Current task context and goal
  • Active decisions and their rationale
  • Blocking issues and error states
  • File paths currently being worked on
  • Uncommitted changes description
  • Contract IDs and branch names </what_to_preserve>

<what_to_compact> Aggressively compress:

  • Exploratory searches → "searched X, found Y at path:line"
  • File reads → "read file, key insight: Z"
  • Successful operations → "completed: X"
  • Debugging traces → "root cause: X, fix: Y"
  • Tool call history → "N tool calls, outcome: X"
  • Research context → offload to AgentDB, keep one-line summary </what_to_compact>

<failure_modes>

  1. Agent tries too much at once → context exhausted mid-work Fix: Incremental progress with commits at each step.
  2. Later agent assumes done prematurely → work incomplete Fix: Explicit done-when criteria with evidence required. </failure_modes>
Files

What ships with it

2 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 100 lines · 42 tokens per session scan A a113c067c1f6

Subscribe to this mod's changes

context-mgmt is a skill published in the GitHub repository ariaxhan/kernel-claude (12 stars, last pushed today), licensed MIT. It adds 42 tokens to every session and 936 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

prolong

Recover and use durable coding-session history from PRO-LONG's local append-only log. Use on long-running coding tasks, after context compaction or session resume, when reconstructing prior decisions or tool results, or before repeating work that may already have been attempted.

alexisfox7/PRO-LONG · 55 tokens

lemmalog

Externalize working memory and logical state into the lemmalog Datalog engine (MCP). Use for ANY multi-step task where state should outlive one context window or span agents: long investigations, debugging sessions, audits, multi-agent searches, systematic explorations, planning with many interdependent constraints…

JordyZomer/lemmalog · 105 tokens

causal-memory

Causal memory for agents — install/setup the causal-memory MCP server, then record decisions/outcomes and recall them before acting. Trigger when the user asks to install or set up causal-memory/agent memory, when causal-memory MCP tools are available and the agent faces a non-trivial decision (architecture, debugging…

JingxuanC/causal-memory · 88 tokens

release_followup_lookup

Use this checklist when a user vaguely references a previous release or vendor decision.

Gen-Verse/PAST-Bench · 0 tokens

another-brain

Use the another-brain MCP tools (remember, search, recent, get, reinforce, forget) as shared long-term memory. Activates at the start of a task that may continue previous work, when recalling past decisions/fixes/preferences, when learning something worth remembering across sessions or agents, or after using a…

Flowerf19/another-brain · 69 tokens

memory

Two-layer memory system with grep-based recall.

Gen-Verse/PAST-Bench · 11 tokens