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.mdfiles 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
$HOMEwith GNU (GNU’s Not Unix) stow. As of 2026-10-31 it holds 99 pi extensions, 88 shared library files (73 of them-core.tscores) and 91 skills, 77 of them linked into Claude Code. A file in the repo does nothing until stow links it, andstow-driftchecks 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.
The journey
Section titled “The journey”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.
The opencode era (2026-01 to 2026-05)
Section titled “The opencode era (2026-01 to 2026-05)”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.
What was built, by area
Section titled “What was built, by area”| Area | Dates | What shipped | Detail |
|---|---|---|---|
| Guards | 2026-05 to 2026-10 | prose, provenance, confidential-identifier and git guards; the tiered git gate and leak gates | Guard extensions, git without prompts |
| Memory store | 2026-08 to 2026-10 | Postgres session store across clients, full-text and vector search | Memory store |
| Context and compaction | 2026-05 to 2026-10 | spill and prefix-stable prune of tool output, a compaction trial | Context and prompt cache |
| Loops | 2026-07-13 to 2026-10 | sensor-gated loop, loop graph, weekly garden run | Self-correcting loop |
| Research stack | 2026-05 to 2026-10 | SearXNG, crawler, OSINT and local-data tools | Research stack |
Guards
Section titled “Guards”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.
Memory store
Section titled “Memory store”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.
Context and compaction
Section titled “Context and compaction”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.
Research stack
Section titled “Research stack”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.
The package survey
Section titled “The package survey”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).
Harness layout
Section titled “Harness layout”The source of truth is one dotfiles repo, symlinked into $HOME with GNU stow.
- The dotfiles repo holds the extensions, the shared library cores, skills, prompt fragments, MCP server config, the Claude Code adapters and the git hooks.
- GNU stow symlinks them into
$HOME. A fresh machine needs--no-folding;.stow-local-ignoreexcludes what should not be linked (.git,README.md,AGENTS.md,package.json). - pi loads every top-level
.pi/agent/extensions/*.tsand*/index.tsat 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. stow-driftexits 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/.
Why shared cores
Section titled “Why shared cores”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.
Prompt fragments
Section titled “Prompt fragments”Two prose files are added to every request:
tool-routing.md, prepended bytool-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).
Skills tree
Section titled “Skills tree”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.
MCP servers
Section titled “MCP servers”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.
Project trust
Section titled “Project trust”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.
Where each guard runs
Section titled “Where each guard runs”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.
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.
Extension catalogue
Section titled “Extension catalogue”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.
Tools the model can call (35)
Section titled “Tools the model can call (35)”| Area | Extensions |
|---|---|
| Docs, search and fetch | docs.ts (docs over SSH), exa.ts, webfetch.ts, web-research.ts, oci-tags.ts, context7.ts |
| Code intelligence | lsp/, glob.ts, grep.ts |
| Session history and memory | session-search.ts, session-ledger/, <store>.ts, memory.ts |
| Data extraction | pdf.ts, opendata.ts, osint.ts, sg-rent.ts, video-review.ts |
| Testing and scanning | bench.ts, go-test.ts, hurl-test.ts, osv-scan.ts, secret-scan.ts |
| Delegation and planning | task.ts, bg-tasks.ts, todowrite.ts, question.ts |
| Rendering | render-diagram.ts, build-favicon-set.ts |
| File and shell utilities | write-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.
Guards and safety (21)
Section titled “Guards and safety (21)”| Extension | What it does |
|---|---|
tool-guard.ts | blocks or advises on bash and write anti-patterns and points at the right tool |
git-gh-gate.ts | tiered git gate: routine git runs, risky git prompts, every decision logged |
epistemic-guard.ts | blocks emitted versions, flags, paths, URLs and CVE ids with no source in the session |
confidential-write-guard.ts | blocks identifiers the user confirmed as confidential |
ascii-punctuation-guard.ts | keeps smart punctuation out of files, commits and heredocs |
ai-tell-guard.ts | blocks the regex-able AI prose tells in prose files and commit messages |
dangerous-cmd-guard.ts | blocks or asks for confirmation on destructive shell commands |
secret-output-guard.ts | blocks reads of registered secret stores and masks registered values |
untrusted-content.ts | wraps and scans web content for prompt injection |
skill-guard.ts | nudges the model to the matching skill before it proceeds |
cd-agents-reload.ts | injects a repo’s AGENTS.md when the agent cds into a repo mid-session |
work-router.ts | routes implementation work to direct, a loop or a foreman wave by its shape, and judges a mode the user names |
code-reload.ts | notices changed extension code in a running session; reloads unattended sessions when nothing would be lost |
lookup-before-ask.ts | nudges when the agent asks the user a fact a history store already holds |
entity-qualifier-nudge.ts | nudges when a bare device identifier is used as evidence without its host |
slash-typo-guard.ts | catches mistyped slash commands before they reach the model |
repeat-tool-guard.ts | escalating reminder on repeated identical tool calls |
tool-output-spill.ts | spills oversized tool output to disk and keeps a preview inline |
degenerate-stream-guard.ts | aborts a turn whose output collapses into repetition |
runaway-turn-guard.ts | makes long turns visible and caps the extreme end |
cost-guard.ts | warns on session spend and context cost |
git-session-report.ts | after each turn, tells the user what git state the session left open |
uncarded-guard.ts | after each run, nudges the agent to card open work its reply left uncarded |
More: guard extensions, secret guard, git without prompts, leak gates.
Prompt, policy and model routing (13)
Section titled “Prompt, policy and model routing (13)”| Area | Extensions |
|---|---|
| Prompt injection | tool-routing.ts, local-model-rules.ts, style-toggle.ts, veans-prime.ts (board workflow priming) |
| Nudges before work | history-first.ts, docs-first.ts, skill-first.ts |
| Model and provider | local-provider-hints.ts, llmc-dynamic.ts, llmc-session-guard.ts, llmc-failover.ts, max-tokens-cap.ts, vision-fallback.ts |
More: model routing.
Session lifecycle and UX (30)
Section titled “Session lifecycle and UX (30)”| Area | Extensions |
|---|---|
| Agent view and workers | agent-view.ts, btw.ts, lineage.ts, worker-inbox.ts |
| Context and compaction | context-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 |
| Sessions | session-fts/, session-auto-title.ts, session-name.ts, session-summary.ts, session-undo.ts, bookmark.ts, migrate-sessions.ts, <store>-seed.ts |
| Shell and editor | interactive-shell.ts, inline-bash.ts, vim-editor.ts, atuin.ts |
| Streaming and errors | continue-after-error.ts, streaming-thinking-guard.ts |
| Display and telemetry | tool-activity.ts, transcript-timestamps.ts, llm-metrics.ts, config-snapshot.ts, notify.ts |
More: context and prompt cache, subagents and worktrees, resuming sessions.
Lessons that generalise
Section titled “Lessons that generalise”Stow links for config files
Section titled “Stow links for config files”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.
The git approval prompt
Section titled “The git approval prompt”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.
Block messages for compound commands
Section titled “Block messages for compound commands”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 community package survey
Section titled “The community package survey”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.
Routing rules shape every request
Section titled “Routing rules shape every request”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>_searchalready held. - Never
curla search engine from bash. Targets raw-curl fallbacks when Exa returned nothing, while the self-hosted SearXNG and crawler were available.
Related docs
Section titled “Related docs”This series
Section titled “This series”- Guard extensions that enforce prose and process rules - the nine core guard extensions and the stow-link incident
- Keeping credentials out of agent transcripts - the known-value secret guard design
- Running agent git commands without per-command approval prompts - why approval prompts were replaced by gates
- Leak gates that let coding agents push without approval prompts - building the pre-push and server pre-receive leak gates
- Context, prompt cache, and compaction in a coding-agent harness - context size, cache stability, compaction trials
- Subagents, worktrees, and parallel agent work - task/bg workers, agent view, worktrees, main-session git
- Which model runs which agent work - per-caller model defaults, the effort rule, vision fallback, provider-path guards
- A skills system for coding agents - trigger descriptions, the skills lint, promotion to a second harness, stocktakes
- One rule set, two agent harnesses - shared cores with thin per-harness adapters
- Resuming any coding-agent session from any directory - one newest-first list of pi and Claude Code sessions, resumed in their original directory
- A self-hosted transcription service for coding agents - diarization, voice prints, conversation metrics
- Agent image generation and LoRA training - generation and fine-tuning as agent tools on the shared GPU (graphics processing unit)
- Reverse engineering with a coding agent and headless Ghidra - a deferred RE (reverse engineering) tool server and a protocol parity matrix
- A personal knowledge graph with a local LLM (large language model) - local entity extraction over a private archive
Existing related pages
Section titled “Existing related pages”- Documentation over SSH (Secure Shell) for coding agents - the docs.erfi.io mirror system described in the tool-routing rules
- Labelling AI use in your own work - 0rwx applied to the repos this harness produces, and what a single-axis label leaves out
- One identity, two registers - how a personal design language became a CLI (command-line interface) and CI (continuous integration) gate that the harness exposes as a tool
- Forgejo as the primary forge on the NixOS edge router - where the dotfiles repo lives
- A kanban board for coding agents - the open-work tracking system that replaced plan-doc checkboxes
- A cross-client memory store for coding agents - the session-history store design
- Loop or graph: a sensor-gated coding-agent loop - the self-correcting loop harness
- A self-hosted web research stack for coding agents - the research stack
References
Section titled “References”-
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)”. Thetool-routing.mdcanonical date is from the same commit batch (2026-08-15). ↩ -
The 640k figure is from the agent memory store reference. The seeding run and embedding process are described there. ↩
Linked from
- A personal knowledge graph with a local LLM
- A self-hosted transcription service for coding agents
- A skills system for coding agents
- Agent image generation and LoRA training
- Context, prompt cache, and compaction in a coding-agent harness
- Guard extensions that enforce prose and process rules in a coding agent
- Labelling AI use with the 0rwx framework
- Model routing in a coding-agent harness
- One design language for a photo site and self-hosted tools
- Resuming any coding-agent session from any directory
- Reverse engineering with a coding agent and headless Ghidra
- Sharing guards and tools between two coding-agent harnesses
- Tool-output pruning and the prompt cache: a replay of long agent sessions