Agents and LLMsHarness and toolingreference
Sharing guards and tools between two coding-agent harnesses
Two coding-agent harnesses touch the same repos, the same secrets and the same infrastructure. The first one got a guard layer first: extensions that block leaked credentials, reject AI-generated prose tells, gate git commands, mask secret values in output and enforce tool-choice rules. The second harness needs the same layer, and the choice is between porting it and duplicating it. This page describes a third option: one copy of the logic in shared cores, thin per-harness adapters, and rules for what lives where.
The source is the dotfiles repo behind both harnesses (pi and Claude Code), read as of 2026-10-20, with counts from ls and wc -l on the same day. The pattern applies to any pair where one harness has an in-process extension API (application programming interface) and the other splits the same surface across separate mechanisms.
Counts drift. A recount on 2026-10-31 gave 88 files in lib/, 73 of them *-core.ts, 28 tools registered in the MCP (Model Context Protocol) server, and 77 skill symlinks out of 85 skills. The figures below stay as of 2026-10-20.
TL;DR:
- 81 shared cores in
lib/hold the logic of every guard and tool. pi adapters import them as in-process extensions, Claude Code adapters import them into MCP servers and hook scripts. - 26 MCP tools in one stdio server give Claude Code the CLI (command-line interface) wrappers, service clients and renderers that pi has as built-in tools.
- 22 hook scripts mirror pi’s
tool_callinterceptors. The mapping is not 1:1: some guards gain auto-rewrite viaupdatedInput, others lose mid-turn abort and masking of the model’s own reply. - Two prose rules files (
tool-routing.md,APPEND_SYSTEM.md) are mirrored by hand into one (CLAUDE.md). - 74 skills are promoted by per-skill symlink. The directory contents are the allowlist.
- Claude Code’s settings file is machine-mutated, so a tracked fragment with the hooks wiring is jq-merged in at install time.
- 3 MCP servers are registered in both harnesses from one
mcp.json, gated by a stored list of eligible names. - The 12 language servers in
.lsp.jsonrun for Claude Code through a skills plugin and for pi through itslspextension.
Topology
Section titled “Topology”lib/ holds 81 TypeScript files, 68 of them *-core.ts, and they import nothing from either harness. pi loads 93 top-level extensions that import from lib/, each hooking one event in a single in-process runtime. Claude Code reaches the same cores through a 26-tool stdio MCP server for LLM-callable tools and 22 hook scripts for guard events (PreToolUse, PostToolUse, Stop and others). 74 of the 84 skills reach Claude Code by per-skill symlink.
Early decision: what to share, what to keep per-harness
Section titled “Early decision: what to share, what to keep per-harness”| What | Share or keep? | How |
|---|---|---|
| Guard logic (credential blocking, prose enforcement, secret masking, anti-patterns, provenance) | Share | One lib/<name>-core.ts per guard, imported by both harness adapters |
| LLM-callable tools (CLI wrappers, service clients, renderers) | Share | One MCP server importing the same lib/ cores |
| Tool-choice rules (when to search, how to escalate) | Share | Hand-synced prose file, mirrored verbatim |
| Skills (methodology, infrastructure, operations) | Share (curated) | Per-skill symlinks; directory contents are the allowlist |
| MCP server definitions | Share | One mcp.json, registered in both harnesses; a list of eligible server names gates the second harness |
| LSP server binaries | Share | Same binaries on PATH; different config format per harness |
| TUI / session internals (status line, compaction, session store) | Per-harness | Each harness has its own equivalent or the surface does not exist |
| Machine-mutated config (plugin registrations, enabled plugins) | Per-harness | Harness B’s live settings file is mutated by the harness itself; a tracked fragment is merged in at install time, never symlinked |
| Cost / provider guards (output caps, spend warnings, model-swap guards) | Per-harness | Different providers, different guard surfaces |
| Streaming / mid-turn guards (degenerate stream, runaway turn, thinking deltas) | Per-harness | Harness B’s hook model lacks streaming deltas and mid-turn abort |
Logic lives in lib/, rules in prose, config per harness. A guard’s detection stays in the shared core. The adapter owns the action: blocking a tool call in harness A, returning permissionDecision: deny from a hook in harness B.
The architectural mismatch
Section titled “The architectural mismatch”Harness A (pi) runs one in-process TypeScript runtime. A single .ts file registers an LLM-callable tool, hooks the tool call to block or annotate, injects context into the system prompt, and paints the TUI (terminal user interface) - all in one file, all through one API.
Harness B (Claude Code) splits the same surface across five separate mechanisms:
| pi capability | Claude Code home | Notes |
|---|---|---|
defineTool(...) LLM (large language model) tool | MCP server (stdio/http/sse), separate process | Full tool shape, but out-of-process |
tool_call hook -> {block, reason} | hook PreToolUse (permissionDecision: deny) | Superset: can also rewrite input via updatedInput |
tool_call result annotation | hook PostToolUse (updatedToolOutput) | Superset: can rewrite output, not just annotate |
context event injection | hook additionalContext (Pre/PostToolUse, SessionStart, Stop, UserPromptSubmit) | Partial: advisory context, not raw message injection |
ctx.ui.setWorkingMessage / footer / toasts | statusline (read-only JSON -> stdout) | No mid-tool progress equivalent |
| Slash prompt templates | .claude/commands/*.md or skill | Near 1:1 |
| Subagent spawn | native subagents (.claude/agents/*.md) | Richer native support |
A pi extension that only blocks tool calls ports to a PreToolUse hook with permissionDecision: deny. One that only annotates tool results ports to a PostToolUse hook with additionalContext. One that does both, or updates the TUI mid-tool, has no direct equivalent.
Several guards that pi can only block-and-ask-for-resubmit (its tool_call hook cannot rewrite input) become auto-fixes under harness B. The ASCII (American Standard Code for Information Interchange) punctuation guard is the example: on pi it blocks and hands back the folded form for the model to resubmit, and under harness B the hook returns the folded form as updatedInput so the model never sees a rejection.
The shared-core pattern
Section titled “The shared-core pattern”One copy of the logic, thin adapters. The core file imports nothing from either harness:
lib/<name>-core.ts pure logic, zero harness importsextensions/<name>.ts harness A adapter (defineTool / tool_call).claude/hooks/<name>.ts harness B adapter (hook script, same core).claude/mcp/toolkit.ts harness B adapter (MCP tool, same core)The 81 files in lib/ cover every guard (epistemic, confidential-write, ascii, ai-tell, secret-output, dangerous-cmd, untrusted-content), the git gate and pre-push scan, tool-output spill/prune, context inspection, the agent view, worker inbox, worker session persistence, skill-guard, task limits, and more.
A guard rule changes in the core and both adapters pick it up. The bun unit tests cover the core regardless of harness:
bun test ./.pi/agent/extensions/tests/A harness B hook script is a self-contained TypeScript file run by bun. It reads a JSON (JavaScript Object Notation) payload from stdin (including session_id, transcript_path, cwd, hook_event_name, and the tool input/output), runs the shared-core detection, and prints JSON to stdout:
#!/usr/bin/env bunimport { scan, foldToAscii } from "../../.pi/agent/extensions/lib/ascii-core.ts";
const payload = JSON.parse(await Bun.stdin.text());const detections = scan(payload.tool_input.content);if (detections.length > 0) { process.stdout.write(JSON.stringify({ permissionDecision: "deny", permissionDecisionReason: detections.map(d => d.reason).join("; "), }) + "\n");}The MCP toolkit server is one stdio process that registers every shared tool:
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";import { queryOciTags } from "../../.pi/agent/extensions/lib/oci-tags-core.ts";import { scanOsv } from "../../.pi/agent/extensions/lib/osv-core.ts";// ... 26 tools totalIt runs from the repo checkout (not the stow symlink) so both the SDK (software development kit) (node_modules in .claude/mcp/) and the ../../.pi/agent cores resolve. Registration:
claude mcp add --scope user erfi-toolkit -- bun \$HOME/dotfiles/.claude/mcp/toolkit.tsThe 26 tools span CLI wrappers (oci_tags, osv_scan, secret_scan, hurl_test, go_test, bench, pg_analyser), service clients (docs over SSH (Secure Shell) with 6 sub-tools, a session-history store client with 7 search tools, web_research, exa web/code search, osint with 9 sub-tools, video_review, context7 query + resolve), and renderers (render_diagram, pdf, build_favicon_set). confidential_terms completes the set.
Guard hooks: the event-model mismatch
Section titled “Guard hooks: the event-model mismatch”22 hook scripts mirror pi’s tool_call interceptors under harness B’s event model. The mapping is not 1:1 in these ways:
Gains: auto-rewrite via updatedInput
Section titled “Gains: auto-rewrite via updatedInput”On pi, a guard that detects a problem in the tool input can only block and hand back a reason. The model must read the reason and resubmit. Under harness B’s PreToolUse hook, the same detection can return updatedInput with the fix already applied plus additionalContext naming what changed. The model never sees the block. The ASCII punctuation guard uses this for prose files (.md, .txt, anything under docs/): guillemets, em-dashes and smart quotes are folded to ASCII in the input before it reaches the tool. Code files and Bash commands are still denied, because folding a command can change what it does.
Gains: output masking via updatedToolOutput
Section titled “Gains: output masking via updatedToolOutput”On pi, the secret-output guard masks registered secret values in tool results by hooking the tool_result event in-process and replacing the values before they enter the model’s context. Under harness B, the same core runs in a PostToolUse hook that returns updatedToolOutput with every string leaf redacted. This is the only PostToolUse hook that rewrites output - harness B runs PostToolUse hooks in parallel on the original output and keeps one rewrite, so this hook must be the sole output-rewriter.
On 2026-10-29 a credential got past the masking on pi. An agent dumped an alerting tool’s settings, and the tool stored its mail-provider API key inside a notification URL (Uniform Resource Locator) (mailtos://host?user=...&pass=<key>&...). Two gaps lined up. The key sat in no registered secret store, so there was no value to match. And the guard split output into candidate tokens on whitespace, quotes and brackets but not on ?, & or @, so even a registered value in that position would not have stood alone as a candidate. The fix tries each URL query segment and the userinfo password as candidates, adds a format rule for that provider’s key shape (masked even when unregistered), and registers the vault items holding those keys. The leaked key turned out to be already revoked; the live keys from the same provider were rotated anyway.
Losses: no mid-turn abort, no streaming guard
Section titled “Losses: no mid-turn abort, no streaming guard”pi’s runaway-turn-guard.ts and degenerate-stream-guard.ts need streaming deltas and a mid-stream abort. Harness B’s hooks fire before and after tool calls, never during them, so both guards stay pi-only.
Losses: advisory vs blocking context
Section titled “Losses: advisory vs blocking context”pi’s context event can inject raw messages into the system prompt. Harness B’s additionalContext is advisory - the model sees it but it does not sit in the same position as the system prompt. A context injection that depends on its exact position in the prompt, such as the tool-routing rules at a fixed offset, cannot be replicated.
Hand-synced rules: one prose file, two harnesses
Section titled “Hand-synced rules: one prose file, two harnesses”Two prose files shape every turn for harness A:
tool-routing.md(prepended bytool-routing.tseach turn): the search-family pipeline, web research escalation, docs.erfi.io workflow, LSP-for-code-intel rule, subagent delegation policy, memory and session-search triggers, bash discipline, and the bg-tasks family rules. About 45 KB (2026-11-15).APPEND_SYSTEM.md(appended every turn): commit/PR (pull request) authorship rules, safety rules, epistemic calibration, confidential identifiers in tracked files, output surface formatting, and AI (artificial intelligence) prose tells.
Both are mirrored into one file for harness B: CLAUDE.md. The mirror is manual. A shared file with includes would let an edit to the included fragment silently change what one harness sees.
A change to a mirrored rule lands in both copies. A rule that only makes sense for one harness (a pi-specific API reference, a hook contract for harness B) stays in that harness’s file.
A third file, local-model-rules.md, is injected only when a local model is in use, and a model family that needs its own notes gets a file under model-rules/ (Kimi, since 2026-11-15). These have no harness B equivalent and stay pi-only.
Per-skill symlink promotion: the skills allowlist
Section titled “Per-skill symlink promotion: the skills allowlist”74 of the 84 skills are promoted to harness B via per-skill symlinks in .claude/skills/. Each symlink points back into the shared skills tree:
.claude/skills/systematic-debugging -> ../../.pi/agent/skills/systematic-debugging.claude/skills/writing-plans -> ../../.pi/agent/skills/writing-plansThe directory contents are the allowlist. A skill that should not reach harness B, such as a private-corpus tool or one that only makes sense in harness A, stays out of the directory. There is no configuration file or denylist.
Skills that ship as upstream plugin bundles (vendor content installed directly into .claude/skills/ by harness B’s plugin system) coexist with the symlinks. GNU (GNU’s Not Unix) stow nests the symlinks alongside the real directories.
A lint script (scripts/skills-lint.py) checks frontmatter shape, ASCII punctuation, dead paths, retired terms, and freshness. It runs as a pre-commit hook and weekly in a garden loop.
Settings fragment merge: when the file is mutated by the harness
Section titled “Settings fragment merge: when the file is mutated by the harness”Harness B’s live settings file (~/.claude/settings.json) is machine-mutated state: the harness writes its own plugin registrations, enabled plugins, and per-project overrides into it. Symlinking the whole file from the dotfiles repo would lose those mutations on every install.
Instead, the repo tracks a fragment, settings.hooks.json, carrying only the hooks wiring (22 hook scripts across 7 events: PreToolUse, PostToolUse, Stop, UserPromptSubmit, Notification, SessionStart, SubagentStop). At install time, install.sh do_claude() jq-merges the fragment’s hooks object into the live file:
- Per-event arrays are concatenated, order preserved
- Duplicate entries (same
commandandmatcher) are deduplicated first-seen - The live file’s
permissionsand other keys are left untouched - The merge is idempotent: running it again produces the same file
The fragment is the only source of hooks wiring. Porting a new guard adds an entry to it and re-runs install.sh; existing hooks stay in place.
MCP servers: one definition, two harnesses
Section titled “MCP servers: one definition, two harnesses”Since 2026-09-29, harness A loads MCP servers from a native .pi/agent/mcp.json. Servers support command (local subprocess), url (remote HTTP (Hypertext Transfer Protocol)), and OAuth. Secrets go in ${VAR} env refs or !command substitution, never literal values.
Three of those servers are also registered in harness B (research, terraform, shadcn). A stored list in install.sh (CC_MCP_FROM_PI) names which servers are eligible. do_claude() iterates the list, reads each server’s definition from .pi/agent/mcp.json, and registers it in harness B at user scope:
claude mcp add --scope user research -- env RESEARCH_BASE_URL=... \ bun \$HOME/infra/research/mcp/server.tsThe registration is probed against ~/.claude.json (the user-scope MCP store) and re-registered when the definition changes. A server that moves from command to url or gains an env var is re-registered; one that stays identical is skipped.
Project-scoped MCP lives in <repo>/.pi/mcp.json for trusted repos. A global server one project needs sits in the global file with "enabled": false, and that project carries a bare override {"enabled": true}.
LSP servers: same binaries, different config
Section titled “LSP servers: same binaries, different config”The same LSP (Language Server Protocol) binaries serve both harnesses:
| Language | Binary |
|---|---|
| Shell | bash-language-server |
| YAML (YAML Ain’t Markup Language) | yaml-language-server |
| JSON | vscode-json-language-server |
| CSS (Cascading Style Sheets) / SCSS (Sassy Cascading Style Sheets) / Less | vscode-css-language-server |
| HTML (HyperText Markup Language) | vscode-html-language-server |
| TOML (Tom’s Obvious, Minimal Language) | taplo |
| Terraform | terraform-ls |
| Astro | astro-ls |
| Markdown | markdown-oxide |
| Dockerfile | docker-langserver |
| SQL (Structured Query Language) | sql-language-server |
| GraphQL | graphql-lsp |
Harness A loads them through its lsp/ extension, which spawns the right server per file extension. Harness B loads them through a skills-directory plugin: .claude/skills/lsp-servers/.lsp.json, which maps file extensions to language IDs (identifiers) and declares the binary, args, and optional startup timeout per server.
TypeScript, Go, Python, Rust, Lua and C/C++ come from the official *-lsp@claude-plugins-official plugins in harness B. Harness A spawns its own entries for them from PATH (lsp/servers.ts lists typescript-language-server, gopls, rust-analyzer, pyright-langserver, clangd and lua-language-server, among others).
What carries over to another pair of harnesses
Section titled “What carries over to another pair of harnesses”The 81 cores, 26 tools, 22 hooks and 74 promoted skills belong to this setup.
- A guard’s decision logic (does this text contain a secret, is this punctuation mojibake-prone) stays in a dependency-free file, and the mechanism that acts on it lives in the adapter. Logic changes once.
- A hand-synced rules file works while the sync rule is one sentence: a change to a mirrored rule lands in both copies.
- A symlinked skills directory is its own allowlist:
lsshows what is promoted and there is no denylist to drift. - A harness that mutates its own config at runtime gets a tracked fragment merged in, because symlinking the whole file would overwrite those mutations.
- MCP definitions registered from one source need a stored allowlist, since not every server for harness A belongs in harness B.
- Language servers are the cheapest share: the binaries are already on PATH and each harness needs only its own mapping from extension to language ID.
- The event-model mismatch stays. Guards that need streaming deltas or mid-turn state have no analogue in an event-granular hook model, and a guard on output may be unable to mask the model’s own reply. Port the guards that fit.
- Run
stow-driftbefore claiming a config change works. A guard written, tested and committed but never symlinked into the live tree is dead config; the drift check exits 1 on such a file. Verify out-of-band withtimeout -s KILL 120 <harness> -p '<text that should trip the guard>' </dev/null.
Decision guide
Section titled “Decision guide”- Harness-specific internals (TUI, session store, compaction, streaming guards) stay per-harness. Do not port.
- Machine-mutated config files are tracked as fragments and jq-merged at install time. Never symlink the whole file.
- LLM-callable tools go in
lib/<name>-core.tswith an MCP wrapper for harness B. - Guards that block or rewrite go in
lib/<name>-core.tswith a hook script for harness B. If the guard needs capabilities harness B’s event model lacks (mid-turn abort, reply-output masking), keep it per-harness. - Skills are promoted via per-skill symlinks. The directory contents are the allowlist.
- Prose rules and policies are hand-synced to both rules files.
Evidence
Section titled “Evidence”| Claim | How it was checked | Status |
|---|---|---|
81 files in lib/ | ls lib/*.ts | wc -l, 2026-10-20 | measured |
68 of them are *-core.ts | ls lib/*-core.ts | wc -l, 2026-10-20 | measured |
| 26 tools in the MCP toolkit server | grep -c 'server.registerTool' toolkit.ts, 2026-10-20 | measured |
22 hook scripts wired in settings.hooks.json | 22 non-smoke .ts files under hooks/ matched to 22 unique script refs in settings.hooks.json, 2026-10-20 | measured |
| 74 skills promoted to harness B via symlinks | find skills/ -type l | wc -l = 74, 2026-10-20 | measured |
3 MCP servers in CC_MCP_FROM_PI | install.sh line 30: research terraform shadcn, 2026-10-20 | read from source |
settings.hooks.json fragment jq-merged in do_claude() | install.sh do_claude() lines 371-401, jq-merge of hooks into live settings.json | read from source |
LSP config: 12 servers in .lsp.json | .lsp.json top-level keys count, 2026-10-20 | measured |
updatedInput auto-rewrite probed on CC (Claude Code) 2.1.292 | pi-to-claude-code-port.md Phase 0 checkbox, 2026-10-15 | live-verified |
updatedToolOutput secret masking live-verified on CC 2.1.304 | pi-to-claude-code-port.md secret-output-guard row, 2026-10-20 | live-verified |
MessageDisplay rewrites only the screen, not the transcript | CC hooks docs, read 2026-10-20, recorded in the port doc’s secret-output-guard row | design-only (verified from docs; not empirically probed) |
| Skills lint script: pre-commit hook + weekly garden loop | dotfiles repo scripts/skills-lint.py + garden skill, 2026-10-20 | read from source |
stow-drift exits 1 on UNLINKED live-tree files | dotfiles repo bin/stow-drift.go, liveTrees and liveFiles lists, 2026-10-20 | read from source |
Related docs
Section titled “Related docs”- The pi harness journey: a coding-agent harness built from one - the series hub and the extension catalogue these guards come from
- Guard extensions that enforce prose and process rules in a coding agent - the nine guard extensions and the stow-link incident
- Keeping credentials out of coding-agent transcripts - the known-value secret guard design, shared across both harnesses
- Running agent git commands without per-command approval prompts - the tiered git gate and pre-push leak gate, both ported
- Leak gates that let coding agents push without approval prompts - building the pre-push and server pre-receive leak gates
- Which model runs which agent work: model routing in a coding-agent harness - the per-caller model routing that the hand-synced rules govern
- Subagents, worktrees, and parallel agent work - the worker kinds and the main-session-only git rule
- A cross-client memory store for coding agents - the session-history store that both harnesses query
- A self-hosted web research stack for coding agents - the research MCP server registered in both harnesses
- Loop or graph: a sensor-gated coding-agent loop measured against the 2026 harnesses - the loop harness, runnable from either harness