Skip to content

Self-Managed Context

Lets an agent edit its own live context window as a file, with safety rules the harness enforces.

Stars
18,282
Licence
MIT
Files
3 files

What it does

This skill teaches an AI agent to manage its own working memory instead of waiting for a system to compress it on a schedule. The model's context is exposed as an editable file that the agent rewrites with ordinary code tools, deciding what to keep verbatim, evict, or update in place. The skill also describes the guardrails the surrounding harness must enforce, such as protecting the system prompt, rejecting edits that grow the context past budget, logging edit receipts, and rolling back on overflow. It also notes that edits can break prefix caching and raise compute cost.

Great for

  • Developers building agent harnesses who want to experiment with model-driven context editing
  • Researchers evaluating context-management strategies for long-horizon coding or research agents
  • Teams diagnosing agents that lose exact values or fail to update state during long tasks

Skip it if

  • Simple chatbots or short tasks where context limits never matter, since the added machinery is unnecessary
  • Systems where the harness cannot enforce a pinned prefix and edit gates, because the model could rewrite its own instructions or persist injected text in its notes
  • Teams wanting a ready-made tool; this is a design contract and protocol guide, not a drop-in library, and it names no specific packages

Try asking

  • “Design a context-as-a-file protocol for my agent with a pinned system prompt and edit receipts”
  • “Help me price the prefix-cache cost of mid-context edits in my coding agent”
  • “Diagnose why my self-editing agent never edits its context or wipes useful state”
  • “Explain the safety invariants I need before letting a model rewrite its own context window”
Step-by-step guide: how to use Self-Managed ContextInstall, first run, examples, tips and FAQs

Install in 3 steps

  1. 1

    Download the skill

    The ZIP contains the 3 original files, the MIT licence and an attribution note.

    self-managed-context.zip
  2. 2

    Add it to your agent

    Claude Code (all projects)

    mkdir -p ~/.claude/skills && unzip self-managed-context.zip -d ~/.claude/skills/

    Claude Code / Agent SDK (this project only)

    mkdir -p .claude/skills && unzip self-managed-context.zip -d .claude/skills/

    Claude apps (web/desktop): Settings → Capabilities → Skills → Upload skill, and choose the ZIP.

  3. 3

    Ask for the task

    No special command needed — the agent reads the skill's description and loads it when your request matches. Try one of the prompts above.

Get better results

  • Read the harness-protocol reference before implementing, since the invariants table is the core of the safe design
  • Pin system and task messages outside the editable file so the model cannot rewrite its own instructions
  • Watch for injected instructions persisting in model-written notes, and treat the editable region as untrusted input

What's inside

  • references/evidence.md
  • references/harness-protocol.md
  • SKILL.md

Redistributed unmodified from muratcankoylan/Agent-Skills-for-Context-Engineering under the MIT licence. The assessment was drafted with AI from the skill's files on 2026-10-29. Skills can instruct your agent to run code — read SKILL.md and any scripts before installing.