🎯 The Problem No Agent Escapes 0:00
Every agent has it, no agent can escape it, and every engineer must understand it: the context window. It's "the precious resource for accomplishing work with your agents," and knowing how to control it is a "massively untapped opportunity." The key reframe: your agents are now intelligent enough to be self-aware of their own context windows — so why not let them decide when it's time to compact?
The default in most agentic coding tools (Claude Code, Codex) is auto-compaction at a fixed percentage. IndyDevDan's counter: "Defaults are for engineers who don't own their harness." With harness engineering on the Pi coding agent, you can do much better — and for anyone firing off longer and longer running agents, "managing your context window properly will literally pay you with each compaction that runs."
📝 The Draft Plan: Encode Your Expertise 2:04
"All great work starts with a hand-written draft plan. No software factories, no agents, no whisper flow — just me, my thoughts, and the keyboard." The plan encodes the problem, solution, workflow (plan → build → verify), a definition of done, and a "how you're graded" rubric. This translation step — your expertise encoded into a prompt your agents can execute — is the real edge in agentic engineering now.
Two sections of the plan deserve special attention:
- Definition of done — how the agent knows when to stop. (Referenced against OpenAI's noted failure to ship a "done tool" for its agents.)
- How you're graded — "an insane hack": these models are always being graded inside the big AI labs during training, so giving them a rubric lets them adhere to it. Graded continuously on completed bullets; instant failure for writing deliverables outside the working dir, or reading another agent's files.
The grading rubric also serves a scaling goal: as he transitions from in-loop to out-loop agentic coding, he wants signal now about which models he can trust over longer horizons when he's not present.
🛠️ The Build: Self-Compact Tool & Three Thresholds 4:18
The build gives the agent four things, each a deliberate piece of prompt/harness engineering:
| Feature | What it does |
|---|---|
| Self-compact tool | A dedicated tool the agent can call at any time to compact its own context — and leave a note to itself that survives the summary. |
| Three thresholds | Notice → warning → force. A wide gap before the warning (natural stopping point), a short gap to the hard cutoff where the harness blocks every other tool. |
| Context bar UI | Cached tokens, uncached tokens, free context, and all three markers rendered live in the terminal. |
| Full prompt control | Override the default compaction prompt, the soft notice, and the warning prompt. "Every agentic coding tool has a baked-in compaction message. Pi lets you replace it. Claude Code does not." |
The note-to-self is a subtle but important tweak: compaction normally fires a user prompt to summarize; the note-to-self is an additional user prompt the agent writes to itself, added during summarization. So the agent both compacts and hands itself a memo — "a goal, determination, done, next action."
💰 Cost-Aware Defaults & the 270K Doubling Point 11:09
The thresholds aren't arbitrary — they're tuned around a real pricing cliff. GPT models' price basically doubles at the 270K-token mark. So the defaults are set to soft notice at 225K, hard warning at 250K, and forced compaction at 270K — giving the agent room to wrap up its current work before the cost starts doubling. "The agent compacts before the bill does."
🥊 The 3-Way Showdown: GLM vs Astra vs Fable 15:06
With the plan written, typing stops and agents take over. A just file kicks off the same plan against three harnesses, each running a different model: Pi on GLM 5.2, Codex on GPT-6 Astra, and Claude Code on Fable 5.1. "I think in ands not ors" — no winning tools, just the tools you can customize and own.
| Harness | Model | Result |
|---|---|---|
| Pi | GLM 5.2 | 💥 98% context — context explosion, did not finish |
| Claude Code | Fable 5.1 | ✅ 50 min, ~500K tokens, 50% context (1M window) |
| Codex | GPT-6 Astra | ✅ 21 min, ~136K tokens — half the time, a fraction of the tokens |
Agents building agents, each working the same plan → build → verify workflow, all firing side by side in a Herdr terminal.
📊 Results: GLM Chokes, Astra Ships Fastest 17:12
GLM 5.2's failure is the cleanest illustration of the entire premise: it hit 98% context and could not finish — "it thinks a lot," scrolling through long chains of reasoning, and powerful open-weight workhorse models have limits. If that agent had self-compaction, it would have gotten the job done.
The two that finished are telling. Fable 5.1 used 500K tokens over 50 minutes (50% of its 1M-token context). Codex on GPT-6 Astra used 136K tokens over 21 minutes — half the time, a fraction of the tokens, and the clear efficiency winner. Both produced the full deliverable: specs (plan → build → verify), then the working apps, then updated the just file.
🔬 Live Proof: Notice → Warn → Note-to-Self → Compact 20:04
To prove the mechanism, the thresholds are spread out (soft 10%, warning 20%, hard 30%) and the agent is pointed at a stress test — find the largest file, read it in 40KB chunks, and chew up context. The live sequence is the payoff:
- Notice fires at the soft threshold ("context use, soft threshold — I have plenty of room").
- Warning fires ("threshold passed, I need to compact now").
- The agent decides to compact on its own, writes a note to itself, then is forced to compact.
The result is visible as a "compaction line" — a note carrying goal, determination, done, and next action, plus the custom compaction message. If needed, you could record how many compactions occurred per run ("cycle one"). The same flow is demonstrated on both the Fable 5.1 (Pi) and GPT-6 Astra (Codex) builds, stress-tested with DeepSeek V4 Flash and GLM Flash through OpenRouter.
🧭 The Philosophy: Master the Core Four 26:21
The closing thesis, made "dead clear": master the core four — context, model, prompt, tools — and you master the agent. Master the agent and you master knowledge work. Add domain expertise and "you have it all."
The bigger frame is the shift from in-loop to out-loop agentic coding. There will always be in-loop work, but "what really matters is your ability to scale out-of-loop" — toward autonomous systems that run long horizons without you. Self-compaction is one lever; you can add multiple warning thresholds, tune the gaps, and design the whole process end-to-end.
⚖️ Verdict: Build the Feature You Need 28:53
The final word is about tooling: "The tools you use directly limit what you believe is possible." The Pi coding agent earns the endorsement precisely because it's customizable, extensible, and open — "I see no limits with it." And he notes, pointedly, that Claude Code is now copying this kind of customization with its own plugin system. "Where do you think that came from? Open, customizable harnesses like the Pi agent."
His advice: "Build the feature you need, not the feature you're given." The edge isn't writing code — "anyone can write code" — it's knowing what you want, encoding it in detail, and handing it to agents that can execute it.
💡 Key Takeaways
- The context window is the untapped opportunity. Every agent has it, no agent escapes it, and managing it well "pays you with each compaction."
- Question the defaults. Fixed-percentage auto-compaction is a default, not a law — an agent can choose a better moment to compact.
- Give the agent its own tool. A self-compact tool lets the agent compact autonomously and leave itself a note that survives the summary.
- Three thresholds, tuned to cost. Notice → warning → force, spaced around the 270K point where GPT pricing doubles.
- Own your prompts. Pi lets you override the compaction prompt; Claude Code doesn't. That's harness engineering.
- The draft plan is the edge. Encode your expertise into a prompt — problem, workflow, definition of done, grading rubric — and the detail you add is the detail you get out.
- Results differ wildly by model. GLM 5.2 choked at 98% context; Fable 5.1 shipped in 50 min/500K tokens; Astra shipped in 21 min/136K tokens.
- Master the core four. Context, model, prompt, tools — master them and you master the agent, then knowledge work.
- Build the feature you need. Open, customizable harnesses (like Pi) are the reason Claude Code now ships a plugin system.
🔗 Resources & Links
- 🐙 github.com/disler/self-compact-pi-agent — the self-compact Pi agent codebase (MIT)
- 🌐 pi.dev — the Pi coding agent
Source video: youtube.com/watch?v=3b0U4_02bAE. Note: the repo was published alongside this video and is brand new (~30 stars at publish time).