agentleFS
edenbuildsedenbuilds/agentloop/.agents/skills/context-surgeon/SKILL.md

context-surgeon

Skill0 starsChanged 4 months agoMITView on GitHub

Continuous budget-aware context policy for agentloop. Use on long runs, before/after heavy tool bursts, when approaching context limits, at slice boundaries, and whenever handoff continuity matters. Not an occasional cleanup — this is harness policy.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 3 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Prefer file-backed state (.agentloop/*) over chat archaeology.

    line 25
  2. Distinctive:

    Keep failing gate logs verbatim

    line 29
  3. Distinctive:

    Never compact away the current failing test/lint output.

    line 31
  4. Distinctive:

    Keep always-on instructions short.

    line 32
  5. Very specific:

    Read .agentloop/stop.yaml when present.

    line 37
  6. Very specific:

    If stop.yaml is missing on a multi-step task, create it from templates/.agentloop/stop.yaml before continuing heavy work.

    line 44
  7. Very specific:

    Before discarding chat detail that encodes a decision/preference/lesson, upsert or supersede it into native memory, then compact.

    line 67

≈ “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.

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

Context Surgeon (policy)

Context management is continuous and budget-aware. Do not wait for the window to explode.

Always-on triggers (run compact / handoff when any fire)

TriggerAction
Slice complete (PEV)Update .agentloop/plan.md progress; refresh .agentloop/handoff.md
External gate failure capturedKeep failing log verbatim; compact prior successful tool noise
~40%+ of host context used (or host warns)Staged compact via context-compact
Turn count hits 50% of max_turnsMid-run handoff + progress summary
Switching mode (PEV ↔ warroom ↔ swarm)Full handoff artifact before switch
User says “continue later” / session endWrite .agentloop/handoff.md (required); upsert durable facts via scripts/memory.sh
Swarm worker returnsFold structured return into plan; drop raw worker chat
Durable decision extracted mid-runscripts/memory.sh upsert (or supersede); add key to handoff memory_keys

Policy loop

  1. Prefer file-backed state (.agentloop/*) over chat archaeology.
  2. Compact in stages (see context-compact):
    • Drop raw successful tool noise
    • Summarize completed slices into plan progress
    • Keep failing gate logs verbatim
    • Emit / refresh handoff
  3. Never compact away the current failing test/lint output.
  4. Keep always-on instructions short; push procedures into skills.
  5. Optimize for stable prompt prefixes when the host caches them.

Budget awareness

Read .agentloop/stop.yaml when present. Treat these as hard:

  • max_turns — stop and hand off with escalate note
  • no_progress — stop, do not “try differently” forever
  • Context pressure high — compact before new exploration
  • Cost/token abort band from Conductor plan — stop and ask

If stop.yaml is missing on a multi-step task, create it from templates/.agentloop/stop.yaml before continuing heavy work.

Handoff minimum (every meaningful run)

Write .agentloop/handoff.md with:

  • goal + done-definition
  • pointer to .agentloop/plan.md
  • verify command
  • progress (done / in-progress / blocked)
  • open risks
  • next concrete action
  • memory keys touched (if any)

Another session must be able to continue without re-explanation.

Relationship to other skills

  • context-compact — mechanical stages
  • conductor-plan — sets per-run compaction cadence
  • persistent-memory — durable store via .agentloop/memory + scripts/memory.sh (promote before dropping chat detail)
  • implementation-notes — dense mid-build notes (complementary)

Before discarding chat detail that encodes a decision/preference/lesson, upsert or supersede it into native memory, then compact.

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.