Reverse Engineering what makes AI agents tick
Three tools. Three agents. One question:
what's actually inside the box?
Every AI coding agent ships as a black box. You type a prompt. It edits your files. Magic?
Not magic. A while loop, a system prompt, and a handful of tools.
The totality of constraints that define an agent's behavior envelope.
Soft agent = few constraints, trusts the model. Hard agent = many constraints, governs the model.
HTTP proxy intercepts all Claude Code API calls. Captures system prompts, tool schemas, behavioral rules.
Technique: MITM proxy on localhost:9876
Live dashboard connecting to OpenCode's official REST API + SSE event stream. Real-time token tracking.
Technique: SSE on port 4096
Parses Pi-mono's JSONL session files. Visualizes the minimalist philosophy — just 4 tools, 880 tokens.
Technique: JSONL tree parser
// proxy.js — zero npm dependencies const server = http.createServer((req, res) => { // Intercept HTTPS to api.anthropic.com const proxyReq = https.request({ hostname: 'api.anthropic.com', headers: req.headers // pass auth through }); // Reassemble SSE streaming chunks proxyRes.on('data', (chunk) => { buffer += chunk; res.write(chunk); // forward to client parseSSE(buffer); // also log it }); }).listen(9876);
Every request & response logged. SSE streaming reassembled into complete messages.
Every agent — Claude Code, OpenCode, Pi-mono — runs the exact same core loop.
That's it. The "intelligence" is in the model. The code is just a coordinator.
What makes Claude Code feel magical isn't clever engineering — it's a really long system prompt telling the model exactly how to behave.
The reverse engineering tools proved this: system prompts and tool definitions account for 85-95% of the agent's personality.
Pi-mono uses 10x fewer tokens and still works remarkably well. More constraints ≠ better agent.
| Section | Tokens | Purpose |
|---|---|---|
| Identity | ~50 | "You are Claude Code" |
| Workflow Rules | ~3,200 | How to use tools, git, PRs |
| Environment | ~320 | OS, cwd, git status, date |
| Tool Defs | ~3,500 | JSON schemas for 17 tools |
| Reminders | ~900 | Start/end context nudges |
Key rules we extracted:
| Pi-mono | OpenCode | Claude Code | |
|---|---|---|---|
| Total tools | 4 | 15 | 17 |
| File read | read | Read | Read |
| File write | write | Write | Write |
| File edit | edit | Edit | Edit + MultiEdit |
| Shell | bash | Bash | Bash |
| Search files | — | Glob | Glob |
| Search content | — | Grep | Grep |
| Sub-agents | — | Task | Task |
| Web fetch | — | WebFetch | WebFetch |
| Plan mode | — | PlanMode | PlanMode |
With bash, you don't need Glob, Grep, WebFetch, or Git tools. The model composes them from find, rg, curl.
Dedicated tools are safer and produce smaller tool results (fewer tokens). Explicit > implicit.
Pi-mono starts with 99.6% of context free. Claude Code starts with 96%. Sounds similar — but over a long session, that 4% fixed cost compounds.
Pi-mono
OpenCode
Claude Code
Where each agent lands on the trust-vs-control axis.
| Dimension | Pi-mono (Soft) | OpenCode (Mid) | Claude Code (Hard) |
|---|---|---|---|
| System prompt | 880 tokens | 7,730 tokens | 8,000+ tokens |
| Tool count | 4 | 15 | 17 |
| Permission gates | None | User-selectable | Tiered + hooks |
| Output verbosity | Model decides | "Concise" | "< 4 lines" |
| Git safety | None | Some | Extensive (no force, no amend) |
All three agents implement some form of context compaction:
Uses Haiku (cheap, fast model) for compaction — not Sonnet. Different models for different jobs. The quota check, topic detection, and compaction all use Haiku.
Starting at 0.4% context, compaction kicks in much later. The minimal system prompt buys more conversation room.
// The Task tool creates isolated contexts Task({ description: "Research auth patterns", prompt: "Find all auth middleware...", subagent_type: "Explore" }) // Sub-agent gets: // - Fresh context window // - Own tool access // - Single response back // Parent context stays clean
No built-in sub-agents. Instead: bash can spawn another Pi-mono process. Unix philosophy.
System prompts get all the attention. But tool results are what actually blow up your context.
One Read of a big file can cost 3-4x more tokens than the entire system prompt. This is why agents tell you: "prefer Grep over cat, prefer Edit over Write."
node proxy.js # Point Claude Code at localhost:9876 # Open visualize.html to explore
npm run dev # Connects to OpenCode on :4096 # Live dashboard at localhost:3000
npm run dev # Load any .jsonl session file # Dashboard at localhost:3000
Run an agent session. Read the captured data. See for yourself what's inside the box.
The model is the intelligence.
The prompt is the personality.
The tools are the hands.
The constraints are the guardrails.
agent37.club