Skip to content

Agents and LLMsHarness and toolingreference

History of the pi coding-agent harness

A coding-agent harness built and maintained with the agent it constrains, from 2025-03 to 2026-10: per-repo instruction files until 2026-01, a shared harness from then on. This page is the hub of the series. It covers the timeline, the layout, where each guard runs, the extension and skill catalogue, and the lessons that hold outside this setup.

TL;DR:

  • Claude Code with per-repo CLAUDE.md files from 2025-03, an opencode configuration (later a fork) from 2026-01, pi from 2026-05-21, opencode retired 2026-08-15. Claude Code came back as a second harness on 2026-07-22 and shares the guard cores with pi.
  • One dotfiles repo is the source of truth, symlinked into $HOME with GNU (GNU’s Not Unix) stow. As of 2026-10-31 it holds 99 pi extensions, 88 shared library files (73 of them -core.ts cores) and 91 skills, 77 of them linked into Claude Code. A file in the repo does nothing until stow links it, and stow-drift checks that.
  • Per-command git approval prompts were replaced by gates. Over 30 days the prompt was answered yes 3,829 times out of 3,833 and caught no leak, so routine git now runs unprompted and leak checks run on the bytes that leave the machine: a pre-push gate and a server-side pre-receive hook.
  • The tool-routing rules (about 43 KB) are prepended to every request and decide which tool the model reaches for.
  • A survey of the pi package registry on 2026-10-19 (~5,300 packages) produced one trial install. The rest duplicated a subsystem the harness already had or carried far more code than the one idea worth taking.

2025-03Claude Code,per-repo CLAUDE.md2026-01-14opencode config,later a fork2026-05-21pi becomes thedaily harness2026-07-22Claude Code backas second harness2026-08-15opencode retired2026-08shared guard coresfor both harnesses2026-10-20git prompts replacedby gates

Per-repo Claude Code instructions (2025-03 to 2026-01)

Section titled “Per-repo Claude Code instructions (2025-03 to 2026-01)”

The first agent was Claude Code, configured per repo. A CLAUDE.md landed in the NAS (network-attached storage) stack repo on 2025-03-29 and in a paste service repo on 2025-04-11 (commit message “guidance to Claude Code (claude.ai/code)”). The shell history records the global npm install of Claude Code on 2025-04-26 and interactive claude sessions from 2025-06-24. More repos gained one through 2025 (the old DNS (Domain Name System) sinkhole on 2025-11-21, a redirect service on 2025-12-17). Each file carried that repo’s rules, and rules shared across repos, such as “make sure commits are without co-author/claude”, were copied from file to file. Nothing lived in one shared repo, so this era left per-repo instruction files and no harness.

opencode was installed on 2026-01-14 (the shell history records the install script at 09:24 UTC (Coordinated Universal Time); the first of 3,060 opencode sessions started five minutes later). The dotfiles repo gained an opencode configuration on 2026-01-19, with MCP (Model Context Protocol) servers for Cloudflare docs, mermaid, TypeScript and fetch. Over the following months that grew into a fork of opencode itself, with its own patches and a FORK.md describing them (methodology injection among them), synced with upstream by hand.

The move to pi (2026-05-21) and opencode’s retirement (2026-08-15)1

Section titled “The move to pi (2026-05-21) and opencode’s retirement (2026-08-15)1”

The migration to pi started on 2026-05-21: a converter that moved opencode’s SQLite sessions into pi’s JSONL (JSON Lines) format, the first pi guard (git-gh-gate.ts), the web research tool, and the docs and context7 integrations that closed the remaining gaps. From then on pi was the harness in daily use and opencode the fallback.

On 2026-08-15 opencode was retired. The .config/opencode/ tree was deleted from the dotfiles repo, with git history as the archive, and the tool-routing rules moved to .pi/agent/prompts/tool-routing.md, prepended to the system prompt by tool-routing.ts on every turn.

Claude Code came back as a second harness after five months unused (the shell history has no claude launch from 2026-02 to 2026-06). The dotfiles repo wired it to the shared skills and a CLAUDE.md on 2026-07-22, and the dual-harness plan of 2026-08-11 moved it onto the guard cores in .pi/agent/extensions/lib/. The port document (pi-to-claude-code-port.md, 17 commits through 2026-08-12) maps pi’s in-process TypeScript extensions to Claude Code’s separate mechanisms: MCP servers for tools, hook scripts for guards, a statusline for TUI (terminal user interface) state, commands for slash prompts, and subagents for delegation.

AreaDatesWhat shippedDetail
Guards2026-05 to 2026-10prose, provenance, confidential-identifier and git guards; the tiered git gate and leak gatesGuard extensions, git without prompts
Memory store2026-08 to 2026-10Postgres session store across clients, full-text and vector searchMemory store
Context and compaction2026-05 to 2026-10spill and prefix-stable prune of tool output, a compaction trialContext and prompt cache
Loops2026-07-13 to 2026-10sensor-gated loop, loop graph, weekly garden runSelf-correcting loop
Research stack2026-05 to 2026-10SearXNG, crawler, OSINT and local-data toolsResearch stack

The earliest pi extensions were guards: git-gh-gate.ts (2026-05-21) and tool-guard.ts (2026-05-22). confidential-write-guard.ts (2026-06-26) blocks identifiers the user has confirmed are confidential. epistemic-guard.ts (2026-08-03) blocks an emitted version, flag, path, URL (Uniform Resource Locator) or CVE (Common Vulnerabilities and Exposures) id that appears in no tool result of the current session. ascii-punctuation-guard.ts and ai-tell-guard.ts enforce the prose rules. By 2026-10-20, 18 extensions hooked tool_call.

On 2026-10-20 the per-command git approval prompt was replaced by a tiered gate. Routine local or recoverable git (commit, push without force or delete, worktree add and remove, merge, switch) runs unprompted when the global git hooks are active, and every decision is written to an audit log. History rewrites, force and delete pushes, and hook bypasses still prompt. Leak checks moved to a client pre-push gate (gitleaks, blocked terms and sensitive files everywhere; on public targets also an identifier and provenance scan and a local-model review) and a Forgejo pre-receive hook. A daily cache tells every layer which repos are public, and agent-inventory lists the worktrees, branches, unpushed commits, stashes and dirty trees agents leave behind.

The session-history store extension (<store>.ts, 2026-08-09) connected pi to a Postgres session-history store shared across clients, with full-text and vector search, seeded from 640,000 existing messages.2 <store>-seed.ts (2026-08-16) added live ingest on session events. By 2026-10 the store served seven search tools (<store>_search, search_messages, semantic_search, search_ledger, search_memories, get_memory, list_sessions) and held the only full copy of sessions older than 30 days, since the local FTS5 (Full-Text Search 5) index prunes at 30 days.

tool-output-prune.ts (2026-05, algorithm ported from the opencode fork) and tool-output-spill.ts (2026-08-21) bound oversized tool output. The prune was rewritten on 2026-10-10 to keep the prompt prefix stable: it fires only past a trigger floor, prunes down to a low watermark, never un-prunes a result, records its decisions as context_edit entries, and below the floor works on a structuredClone so the prefix stays byte-identical for the provider’s prompt cache. The prefix-compaction.ts trial (2026-10-20) re-sent the last request with one summarise instruction appended so the provider’s prefix cache could serve the history. It was slower than pi’s default compaction on both providers in use and ships off by default; the context and prompt-cache reference has the numbers.

The self-correcting loop shipped incrementally from 2026-07-13: a sensor-gated inner loop with a governor (wall-clock budgets, cgroup limits, git checkpoint and rollback), a model-escalation ladder and an adversarial review. loop graph (2026-10-06) added dependency-graph scheduling for multi-loop runs. garden (2026-10-13) runs the skills lint and stow-drift unattended every Sunday at 06:00.

A self-hosted research stack grew alongside: SearXNG metasearch, a crawler that escalates from curl_cffi to Playwright, OSINT (open-source intelligence) tools, a Singapore rental due-diligence suite, and MCP integration. The tool-routing rules escalate in both directions between it and Exa: when SearXNG returns nothing on a long-tail local query the agent tries Exa, and when Exa returns nothing it falls back to SearXNG.

On 2026-10-19 the pi.dev package registry listed ~5,300 community packages. The survey read the top 300 by downloads plus 16 that overlapped the harness’s own extensions, all via npm pack with nothing installed or executed. One was worth a trial (prefix-cache compaction, above).


The source of truth is one dotfiles repo, symlinked into $HOME with GNU stow.

dotfiles repo (source of truth).pi/agent/extensions/99 extensionspi(primary)stow.pi/agent/extensions/lib/88 files, 73 coresimported.claude/hooks, MCP toolkit,77 skill symlinksimported.config/git/hooks/pre-push gateimported.pi/agent/skills/91 skills.pi/agent/prompts/ +APPEND_SYSTEM.md.pi/agent/mcp.jsonClaude Code(second harness)stowgit pushstow
  1. The dotfiles repo holds the extensions, the shared library cores, skills, prompt fragments, MCP server config, the Claude Code adapters and the git hooks.
  2. GNU stow symlinks them into $HOME. A fresh machine needs --no-folding; .stow-local-ignore excludes what should not be linked (.git, README.md, AGENTS.md, package.json).
  3. pi loads every top-level .pi/agent/extensions/*.ts and */index.ts at startup. Claude Code reads .claude/hooks/ and .claude/mcp/toolkit.ts, which import the cores from .pi/agent/extensions/lib/. The git hooks import the same cores.
  4. stow-drift exits 1 on a repo file in a loaded tree that has no live symlink. Exit 1 means dead config.

Counts in this section are as of 2026-10-31: 96 top-level .ts files plus three directory extensions (lsp/, session-fts/, session-ledger/), 84 top-level skills plus 7 under skills/work/.

A pi extension registers in one TypeScript file and can define a tool, intercept tool calls, inject context and draw TUI. Claude Code splits the same surface across MCP servers (tools), hook scripts (guards), the statusline (TUI state), commands (slash prompts) and subagents. Each rule’s logic lives once, in lib/<name>-core.ts, and a thin pi extension and a thin Claude Code hook import it. The git hooks import the same cores for the pre-push gate, so a rule change lands in one file.

Two prose files are added to every request:

  • tool-routing.md, prepended by tool-routing.ts: the search pipeline, web research escalation, the docs.erfi.io workflow, LSP (Language Server Protocol) for code intelligence, subagent delegation, memory and session-search triggers, bash discipline and background-task rules. The extension resolves the file relative to its own module path, so a pi-package checkout loaded in place works too.
  • APPEND_SYSTEM.md, appended: commit and PR (pull request) authorship (no AI-attribution trailers), safety, epistemic calibration, confidential identifiers in tracked files, output formatting, and AI (artificial intelligence) prose tells.

Both are mirrored by hand into .claude/CLAUDE.md for Claude Code. Per-model-family files sit beside them: local-model-rules.md for local models behind llmc, model-rules/kimi.md for Kimi (since 2026-11-15; from 2026-09-28 the local file went to every non-Anthropic provider, details in model routing).

Each skill is a directory under .pi/agent/skills/ with a SKILL.md: frontmatter whose description is the trigger text the model sees (capped at 500 characters), and a body capped at 500 lines. scripts/skills-lint.py checks frontmatter shape, ASCII (American Standard Code for Information Interchange) punctuation, dead paths, retired terms and freshness (a metadata.verified date older than 90 days warns). It runs in the pre-commit hook and in the weekly garden run.

Skills reach Claude Code through one symlink per skill in .claude/skills/, so that directory’s contents are the allowlist (A skills system for coding agents). Skills that touch private session data stay pi-only.

Since 2026-09-29 pi reads MCP servers from a native .pi/agent/mcp.json; before that a separate bridge package did the job. A server is a local command or a remote url, with OAuth where the server supports it. Secrets go in as ${VAR} env references or !command substitution, never as literal values. Rarely used servers are marked "exposure": "deferred" and the model finds their tools through tool_search.

A server that only one project needs sits in the global file with "enabled": false, and that project’s .pi/mcp.json carries a bare {"enabled": true} override.

Since pi 0.79.0, project-local inputs (.pi/ and AGENTS.md in the working directory) load only after a trust decision. Global config under ~/.pi/agent/ always loads. Decisions persist to ~/.pi/agent/trust.json, which is runtime state and not tracked. The subagent spawners (task.ts, bg-tasks.ts) pass --approve only when the parent session trusts the working directory, so a subagent never loads project inputs the user declined.


pi fires extension events at fixed points in a turn. Each guard hooks the point where the thing it checks first exists: the prompt before the model sees it, the tool call before it runs, the tool result before the model reads it, the final reply, and the push.

before_agent_start, contexttool-routing prependhistory-first, docs-firstmodel turntool_calltool-guard, git-gh-gate,epistemic, confidential-write,ascii, ai-tell, dangerous-cmd,secret-outputagent_enduncarded-guard,git-session-reportfinal replyblocked,with reasontool runsallowedtool_resultsecret-output (mask),untrusted-content (wrap),tool-output-spillgit pre-pushleak gateif the toolis git pushForgejo pre-receive(public-mirrored repos)

The event names are from each extension’s pi.on(...) registrations. Several guards hook more than one point: secret-output-guard.ts blocks reads of registered secret stores at tool_call and masks registered values at tool_result and message_end, and epistemic-guard.ts checks writes at tool_call and answers at message_end.


99 extensions as of 2026-10-31, plus two disabled ones (custom-footer.ts.disabled, superseded by pi’s built-in footer, and stuck-state-recovery.ts.disabled). Each group links to the pages that cover it in depth.

AreaExtensions
Docs, search and fetchdocs.ts (docs over SSH), exa.ts, webfetch.ts, web-research.ts, oci-tags.ts, context7.ts
Code intelligencelsp/, glob.ts, grep.ts
Session history and memorysession-search.ts, session-ledger/, <store>.ts, memory.ts
Data extractionpdf.ts, opendata.ts, osint.ts, sg-rent.ts, video-review.ts
Testing and scanningbench.ts, go-test.ts, hurl-test.ts, osv-scan.ts, secret-scan.ts
Delegation and planningtask.ts, bg-tasks.ts, todowrite.ts, question.ts
Renderingrender-diagram.ts, build-favicon-set.ts
File and shell utilitieswrite-stream.ts, apply-patch.ts, yank.ts, powershell.ts, pg-analyser.pi.ts, bash-error-hints.ts

More: self-correcting loop, research stack, memory store, subagents and worktrees.

ExtensionWhat it does
tool-guard.tsblocks or advises on bash and write anti-patterns and points at the right tool
git-gh-gate.tstiered git gate: routine git runs, risky git prompts, every decision logged
epistemic-guard.tsblocks emitted versions, flags, paths, URLs and CVE ids with no source in the session
confidential-write-guard.tsblocks identifiers the user confirmed as confidential
ascii-punctuation-guard.tskeeps smart punctuation out of files, commits and heredocs
ai-tell-guard.tsblocks the regex-able AI prose tells in prose files and commit messages
dangerous-cmd-guard.tsblocks or asks for confirmation on destructive shell commands
secret-output-guard.tsblocks reads of registered secret stores and masks registered values
untrusted-content.tswraps and scans web content for prompt injection
skill-guard.tsnudges the model to the matching skill before it proceeds
cd-agents-reload.tsinjects a repo’s AGENTS.md when the agent cds into a repo mid-session
work-router.tsroutes implementation work to direct, a loop or a foreman wave by its shape, and judges a mode the user names
code-reload.tsnotices changed extension code in a running session; reloads unattended sessions when nothing would be lost
lookup-before-ask.tsnudges when the agent asks the user a fact a history store already holds
entity-qualifier-nudge.tsnudges when a bare device identifier is used as evidence without its host
slash-typo-guard.tscatches mistyped slash commands before they reach the model
repeat-tool-guard.tsescalating reminder on repeated identical tool calls
tool-output-spill.tsspills oversized tool output to disk and keeps a preview inline
degenerate-stream-guard.tsaborts a turn whose output collapses into repetition
runaway-turn-guard.tsmakes long turns visible and caps the extreme end
cost-guard.tswarns on session spend and context cost
git-session-report.tsafter each turn, tells the user what git state the session left open
uncarded-guard.tsafter each run, nudges the agent to card open work its reply left uncarded

More: guard extensions, secret guard, git without prompts, leak gates.

AreaExtensions
Prompt injectiontool-routing.ts, local-model-rules.ts, style-toggle.ts, veans-prime.ts (board workflow priming)
Nudges before workhistory-first.ts, docs-first.ts, skill-first.ts
Model and providerlocal-provider-hints.ts, llmc-dynamic.ts, llmc-session-guard.ts, llmc-failover.ts, max-tokens-cap.ts, vision-fallback.ts

More: model routing.

AreaExtensions
Agent view and workersagent-view.ts, btw.ts, lineage.ts, worker-inbox.ts
Context and compactioncontext-inspector.ts, tool-output-prune.ts, prefix-compaction.ts (off by default), compaction-progress.ts, resume-after-compact.ts, trigger-compact.ts, clipboard-image-shrink.ts
Sessionssession-fts/, session-auto-title.ts, session-name.ts, session-summary.ts, session-undo.ts, bookmark.ts, migrate-sessions.ts, <store>-seed.ts
Shell and editorinteractive-shell.ts, inline-bash.ts, vim-editor.ts, atuin.ts
Streaming and errorscontinue-after-error.ts, streaming-thinking-guard.ts
Display and telemetrytool-activity.ts, transcript-timestamps.ts, llm-metrics.ts, config-snapshot.ts, notify.ts

More: context and prompt cache, subagents and worktrees, resuming sessions.


On 2026-08-27 a guard extension was written, unit-tested, committed and documented, but never stow-linked. No symlink pointed from ~/.pi/agent/extensions/ to the repo file, so the guard never loaded in the session it was written to protect.

stow-drift now exits 1 on a repo file in a loaded tree with no live symlink, and runs before any claim that a config change works. Extensions load at session start, so the check runs in a fresh process instead of waiting for a restart: timeout -s KILL 120 pi -p --no-mcp '<text that should trip the guard>' </dev/null.

Over 30 days the git approval prompt fired 3,833 times across 205 sessions and was denied 4 times: two misclicks, one change of mind and one “check first”. None of the 3,833 stopped a secret or a confidential term from leaving the machine. Each prompt still stopped the session until someone answered it.

The tiered gate lets routine git run and moved leak protection into checks that run on every push: the client pre-push gate and the server pre-receive hook. Skipping either needs a flag (--no-verify or a push option) that the tier gate holds for approval. A prompt remains only for irreversible or remote-config actions. Running agent git commands without per-command approval prompts has the baseline and the replay.

On 2026-07-07 a compound command (write a commit message with a heredoc, then git add, git commit -F, git push) was blocked by one guard whose reason said only “re-run your bash”. The agent re-ran the git commit suffix alone, which failed because the message file had never been written, and spent four turns on it. When it re-ran the full compound, a second guard blocked it, because pi stops at the first blocking tool_call handler and the second guard’s once-per-repo notice had never fired.

The block reason now states that no segment of the command ran, heredoc and git add included, and that the whole command must be re-run. The guards share one module for that notice and for the once-per-repo nudges, so a re-run is blocked at most once.

System prompt changes and the prefix cache

Section titled “System prompt changes and the prefix cache”

/context (context-inspector.ts) showed that the system prompt changed within a session. Six extensions return a full systemPrompt from before_agent_start, and the system prompt sits at position 0, so any change to one of those strings misses the provider’s prefix cache. A semantic retrieval block was injected on the first qualifying prompt and absent from the next, which changed the prompt at byte offset 40,224 and cost two cache misses per session. A memory save mid-session changes the memory block the same way.

The fix moved the one-shot block out of the system prompt and into a message, so the prompt stays byte-identical across the session. The measurement is in the context and prompt-cache reference.

The 2026-10-19 survey of ~5,300 community pi packages produced one trial. The rest duplicated subsystems the harness already had (subagents, todos, guards, LSP, memory) or carried a much larger surface than the idea worth taking. Reading the top candidates’ source with npm pack, taking the one technique that improves on what exists, and installing nothing kept the survey free of install-time code execution.

tool-routing.md is about 43 KB, prepended to every request for every model. Three of its rules and the failure each targets:

  • After two search calls with no drill-in, open the most likely hit. Targets the agent rewording the same query instead of reading a result.
  • Search session history before asking anyone. Targets questions to the user whose answer <store>_search already held.
  • Never curl a search engine from bash. Targets raw-curl fallbacks when Exa returned nothing, while the self-hosted SearXNG and crawler were available.

  1. The retirement is recorded in the dotfiles repo’s AGENTS.md (“opencode (legacy TUI, retired)”) and the retirement commit of 2026-08-15: “refactor: retire opencode - two harnesses (pi primary, CC work)”. The tool-routing.md canonical date is from the same commit batch (2026-08-15). ↩

  2. The 640k figure is from the agent memory store reference. The seeding run and embedding process are described there. ↩