Skip to content

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_call interceptors. The mapping is not 1:1: some guards gain auto-rewrite via updatedInput, 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.json run for Claude Code through a skills plugin and for pi through its lsp extension.

shared cores (one copy of the logic)harness A (in-process API)harness B (separate mechanisms)hand-synced ruleslib/81 TypeScript files68 *-core.ts93 top-levelextensions(import lib/)importMCP toolkit server26 tools -> lib/importhooks/22 hook scripts-> lib/import84 skillsskills/74 symlinksper-skill symlinks(allowlist)mcp.jsonMCP serverdefinitionsskills/lsp-servers/.lsp.jsontool-routing.mdAPPEND_SYSTEM.md(prepended/appendedevery turn)CLAUDE.md(mirrored subset)hand-synced

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”
WhatShare or keep?How
Guard logic (credential blocking, prose enforcement, secret masking, anti-patterns, provenance)ShareOne lib/<name>-core.ts per guard, imported by both harness adapters
LLM-callable tools (CLI wrappers, service clients, renderers)ShareOne MCP server importing the same lib/ cores
Tool-choice rules (when to search, how to escalate)ShareHand-synced prose file, mirrored verbatim
Skills (methodology, infrastructure, operations)Share (curated)Per-skill symlinks; directory contents are the allowlist
MCP server definitionsShareOne mcp.json, registered in both harnesses; a list of eligible server names gates the second harness
LSP server binariesShareSame binaries on PATH; different config format per harness
TUI / session internals (status line, compaction, session store)Per-harnessEach harness has its own equivalent or the surface does not exist
Machine-mutated config (plugin registrations, enabled plugins)Per-harnessHarness 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-harnessDifferent providers, different guard surfaces
Streaming / mid-turn guards (degenerate stream, runaway turn, thinking deltas)Per-harnessHarness 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.


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 capabilityClaude Code homeNotes
defineTool(...) LLM (large language model) toolMCP server (stdio/http/sse), separate processFull 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 annotationhook PostToolUse (updatedToolOutput)Superset: can rewrite output, not just annotate
context event injectionhook additionalContext (Pre/PostToolUse, SessionStart, Stop, UserPromptSubmit)Partial: advisory context, not raw message injection
ctx.ui.setWorkingMessage / footer / toastsstatusline (read-only JSON -> stdout)No mid-tool progress equivalent
Slash prompt templates.claude/commands/*.md or skillNear 1:1
Subagent spawnnative 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.


One copy of the logic, thin adapters. The core file imports nothing from either harness:

lib/<name>-core.ts pure logic, zero harness imports
extensions/<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 bun
import { 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 total

It 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.ts

The 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.


22 hook scripts mirror pi’s tool_call interceptors under harness B’s event model. The mapping is not 1:1 in these ways:

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.

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 by tool-routing.ts each 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.


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-plans

The 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 command and matcher) are deduplicated first-seen
  • The live file’s permissions and 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.ts

The 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:

LanguageBinary
Shellbash-language-server
YAML (YAML Ain’t Markup Language)yaml-language-server
JSONvscode-json-language-server
CSS (Cascading Style Sheets) / SCSS (Sassy Cascading Style Sheets) / Lessvscode-css-language-server
HTML (HyperText Markup Language)vscode-html-language-server
TOML (Tom’s Obvious, Minimal Language)taplo
Terraformterraform-ls
Astroastro-ls
Markdownmarkdown-oxide
Dockerfiledocker-langserver
SQL (Structured Query Language)sql-language-server
GraphQLgraphql-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.

  1. 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.
  2. A hand-synced rules file works while the sync rule is one sentence: a change to a mirrored rule lands in both copies.
  3. A symlinked skills directory is its own allowlist: ls shows what is promoted and there is no denylist to drift.
  4. A harness that mutates its own config at runtime gets a tracked fragment merged in, because symlinking the whole file would overwrite those mutations.
  5. MCP definitions registered from one source need a stored allowlist, since not every server for harness A belongs in harness B.
  6. 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.
  7. 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.
  8. Run stow-drift before 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 with timeout -s KILL 120 <harness> -p '<text that should trip the guard>' </dev/null.

New piece of agentinfrastructureHarness-specific(TUI, session,streaming)?Machine-mutatedconfig file?noKeep per-harnessyesLLM-callabletool?noTracked fragment,jq-merge at installyesGuard thatblocks/rewrites?nolib/<name>-core.ts+ MCP tool wrapperyesSkill orslash command?nolib/<name>-core.ts+ hook scriptyesProse rule orpolicy?noPer-skill symlinkif eligibleyesHand-synced toboth rules filesyes
  1. Harness-specific internals (TUI, session store, compaction, streaming guards) stay per-harness. Do not port.
  2. Machine-mutated config files are tracked as fragments and jq-merged at install time. Never symlink the whole file.
  3. LLM-callable tools go in lib/<name>-core.ts with an MCP wrapper for harness B.
  4. Guards that block or rewrite go in lib/<name>-core.ts with 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.
  5. Skills are promoted via per-skill symlinks. The directory contents are the allowlist.
  6. Prose rules and policies are hand-synced to both rules files.

ClaimHow it was checkedStatus
81 files in lib/ls lib/*.ts | wc -l, 2026-10-20measured
68 of them are *-core.tsls lib/*-core.ts | wc -l, 2026-10-20measured
26 tools in the MCP toolkit servergrep -c 'server.registerTool' toolkit.ts, 2026-10-20measured
22 hook scripts wired in settings.hooks.json22 non-smoke .ts files under hooks/ matched to 22 unique script refs in settings.hooks.json, 2026-10-20measured
74 skills promoted to harness B via symlinksfind skills/ -type l | wc -l = 74, 2026-10-20measured
3 MCP servers in CC_MCP_FROM_PIinstall.sh line 30: research terraform shadcn, 2026-10-20read 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.jsonread from source
LSP config: 12 servers in .lsp.json.lsp.json top-level keys count, 2026-10-20measured
updatedInput auto-rewrite probed on CC (Claude Code) 2.1.292pi-to-claude-code-port.md Phase 0 checkbox, 2026-10-15live-verified
updatedToolOutput secret masking live-verified on CC 2.1.304pi-to-claude-code-port.md secret-output-guard row, 2026-10-20live-verified
MessageDisplay rewrites only the screen, not the transcriptCC hooks docs, read 2026-10-20, recorded in the port doc’s secret-output-guard rowdesign-only (verified from docs; not empirically probed)
Skills lint script: pre-commit hook + weekly garden loopdotfiles repo scripts/skills-lint.py + garden skill, 2026-10-20read from source
stow-drift exits 1 on UNLINKED live-tree filesdotfiles repo bin/stow-drift.go, liveTrees and liveFiles lists, 2026-10-20read from source