Skip to content
Back to skills

Pi As Subagent

CSecurity

Use before starting any subagent or fork: writing, investigation, routing and brief-writing go to Pi over RPC; a Claude subagent stays for a Sonnet gate or work only this session's context can do.

  • 7 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added November 10, 2026
ai-agentstypescriptrustgoshellbashnodetestinggitapi

Works with

  • claude code
  • terminal
  • cli
  • api

Security analysis

C65/100
  • highPerforms destructive filesystem operations
  • criticalSends environment variables or credentials to an external URL
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned December 1, 2026

npx -y skills add Aquaticat/Monochromatic --skill pi-as-subagent --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Pi As Subagent?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Pi As Subagent
[![Security: C — Skills Directory](https://www.skillsdirectory.com/api/skills/aquaticat-pi-as-subagent/badge)](https://www.skillsdirectory.com/skills/aquaticat-pi-as-subagent)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: pi-as-subagent
description: >-
  Use before starting any subagent or fork: writing, investigation, routing and brief-writing go to Pi
  over RPC; a Claude subagent stays for a Sonnet gate or work only this session's context can do.
---

# Pi as a subagent

Pi is a second subagent runtime here,
beside Claude Code native subagents,
and a rule that says "subagent" without naming a runtime binds it too.

Drive `pi --mode rpc` through the driver package,
`package/pi-shared/subagent-driver`,
with the writer and reviewer models of the section "Who writes and who reviews",
started in the repository,
where Pi loads `AGENTS.md` (from another folder rule `ATH` was not in its context).
Real coding tasks always go through the driver;
the owner said "Forget about --print on a real coding task."
In every prompt cite rule `ATH`,
because the model writes scratch to `/tmp` unprompted,
and quote the synthetic-load ban (rule `NLD`).
Also tell every agent,
in every prompt,
to run Git only as plain `git` and never to use real Git:
no `/usr/bin/git`,
no other absolute path to a Git binary,
and no other route around the wrapper that plain `git` reaches.
Real Git skips every guard against discarding work and every commit policy,
and agents here have committed and run `checkout --` through it.
The owner:
"Agents using real git is pretty bad.
As a duct tape patch,
put in the skill to always tell the agents to not use real git."
Also tell every agent never to print the environment (`env`,
`printenv`,
`set`),
even through a filter,
never to read another process's (`/proc/<pid>/environ`,
`ps e`),
and to name the one variable it wants:
an agent's `env | rg` put a real GitHub token in its session,
and all command output goes to the model provider.
The driver enforces that bound too:
it hands Pi its own environment with every variable whose name holds
`TOKEN`,
`SECRET`,
`KEY`,
`PASSWORD`,
`CREDENTIAL` or
`AUTH` removed
(`package/pi-shared/subagent-driver/README.md`),
so a dump shows the names a command may read and no value it may not.
Keep the sentence in every prompt anyway:
a command can still print a token it finds in a file.
Tell every agent that writes code which skill and guide to write it by:
the language's coding skill
(`.agents/skills/dum-dum-non-ts/SKILL.md` for any language but TypeScript,
`.agents/skills/testing-practices/SKILL.md` for TypeScript tests),
and the package's own guide to its code and tests where one exists,
named by its path on `main`,
since a worktree made before the guide landed does not hold it
(for the git wrapper, `package/git-policy/cli/doc/how-to-write-this-packages-code-and-tests.md`).
Pi lists the skills but loads one only when told:
rounds briefed with only the task and the safety rules on 2026-11-25
left two tests sharing one fixture folder,
a stand-in child that outlived its test,
and a test that signalled its own test binary.
The owner, on that debt:
"So pay the debt."
Name the worktree in the prompt of an agent given one,
and tell it to run every command and make every edit inside it:
one agent ran its builds in the main checkout,
so they did not test its worktree's code,
and the uncommitted edits it left there blocked merges of other branches.
Tell every agent that runs plain `git` in a throwaway repository to give that run
its own `HOME` and `XDG_RUNTIME_DIR` under its run folder:
the installed wrapper hands a repository's pushes to the commit service of the session it runs in,
and an agent's proof repositories under `/tmp/lfs-login-proof-ikmLJW/` reached the owner's real service,
which kept retrying their pushes every 600 seconds for hours after the agent deleted them.
Tell every agent never to ask the system service manager to act:
no `systemctl` verb that changes or signals a unit unless it carries `--user` and names a unit the agent started,
no call to `org.freedesktop.systemd1` on the system bus,
no `pkexec`,
and `--no-ask-password` on every `systemctl` it runs.
A request that needs authorization does not fail for an account;
it puts a password dialog on the owner's desktop and waits for the owner:
on 2026-11-22 a design run probed with `systemctl kill --signal=KILL systemd-random-seed.service`,
and the dialog stood for 25 seconds until the request timed out.
What such a request answers is taken from the source or measured in a guest.
Leave `--tools` unstated:
it is an allowlist for every tool,
extension tools included,
so naming some removes the rest.
Pi saves the session by default and the owner wants that kept,
so a run can be read back or resumed with `--session <path|id>`.

Pi may commit directly on `main`,
which auto-pushes,
and it may equally work in a worktree.
The owner on committing:
"We have to be happy with Pi committing directly on main.
We are not building another git wrapper or shim when we're already so busy with one.
If it turns out this blows up we'll consider enhancing our own git wrapper."
And later:
"Feel free to use worktrees.
I said "be okay with pi committing directly to main",
not that they have to."

The owner on how many can run at once:
"Pi doesn't have a limit to number of concurrent subagents."
Twenty is the first level of this machine's search,
not a cap:
the owner said
"Try 20,
and if it doesn't blow up (in terms of api rate limits),
we're permanently raising the practical limit to 20,"
and a trial at 20 agents on 2026-11-09 met no rate-limit error.
On the new drive the owner's later words make twenty a level to double from
(`doc/handover/agents-at-once-on-this-machine.md`,
"The cap now"),
so count every agent and read that page before starting one.
On going higher on the old drives the owner said:
"no,
that's definitely going to blow up."
A run on another provider's account is outside it.
The owner on 2026-11-10:
"Kimi trials don't count within 20 slots because 20 is neuralwatt's effective concurrency and kimi runs on Synthetic."
The owner the same day:
"You can use -flex postfix on neuralwatt models.
They have their own separate pool of 22 slots.
They're around 100% slower than standard in practice."
So `neuralwatt/deepseek-v4.1-flash-flex` is a pool of its own.
Picking all three pools,
standard Neuralwatt,
flex and `opencode-go`,
the owner wrote:
"In practice,
opencode-go may have worse inference quality and worse speed than neuralwatt's flex,
so prefer neuralwatt."
New runs filled standard Neuralwatt,
then flex with twice the wall clock,
then `opencode-go`,
until the owner closed standard Neuralwatt on 2026-11-11 and put `opencode-go` first on 2026-11-16;
the order now is under "Who writes and who reviews".
On 2026-11-11 from 01:19Z,
16 runs ended on Neuralwatt's 429
"Concurrent limit reached for deepseek-ai/DeepSeek-V4.1-Flash: 6/6 slots in use. ...
Your subscription is in overage with auto-renew off,
so pay-as-you-go limits apply until it renews."
The rate-limit endpoint still answered `effective_concurrency` 20 then;
the owner, 2026-11-18:
"that was probably an undocumented bug.
The bug happens if my auto renew for Neuralwatt isn't turned on."
So the endpoint's number holds while auto-renew is on,
and only in that overage state does the 429's own number tell;
Pi ends the run on it instead of retrying.
The owner's `retry` group was read again on 2026-11-11 at 22:33Z and holds
`enabled` true,
`maxRetries` 8 and
`baseDelayMs` 1000,
so Pi's own retry makes its attempts at a 429 before the run ends,
and the driver leaves every 429 to it
(`package/pi-shared/subagent-driver/README.md`, section "Which layer retries what").
The same night 20 of 28 Kimi reviews on Kimi flex ended on
"You've hit your concurrent flex request limit for moonshotai/Kimi-K3.1-Pro (max 7 in flight at once).
Flex requests have a separate per-account concurrency limit from standard requests."
For a few hours the launcher held standard DeepSeek at 6 and both flex pools at 7,
the DeepSeek flex 7 an assumption never measured.
The owner then wrote,
2026-11-11T05:40-05:00:
"I've re-enabled auto-renew. Treat the prev Neuralwatt 429s void."
So the pools are back to standard DeepSeek 20,
DeepSeek flex 22 and Kimi flex 22,
and only a 429 seen after that sets a lower number;
a limit is lowered from a measured refusal,
never from an assumption about another model.
Restart a run that ended on a 429 under its own name;
its worktree keeps the work.
Two launcher defects showed that night,
fixed in the scratch launcher and owed to `package/pi-shared/subagent-driver`:
a run whose launcher process had gone was counted in the `opencode-go` pool,
so 12 runs sat on standard Neuralwatt while it read 0 of 6 and took more;
the pool now comes from the unit's own `--provider` and `--model`.
A run that named no provider or model (every batch-started run) was read as "its own provider",
so it skipped every pool limit and the launcher's defaults put it on standard Neuralwatt;
it is now a default run,
and the chosen pool's provider and model are passed on.
And `--run` defaulted to 1,
so each restart wrote over the first run's `summary.json`
(16 reports, 11 recovered from `~/.pi/agent/sessions/`);
a run with no `--run` now takes the next free number.
The owner on 2026-11-10:
"And you should almost always keep all slots filled."
and
"Dozens of agents at once is normal operation."
So count the free slots whenever a run ends or a batch finishes starting,
and start work in them the same turn.
That work is the Git wrapper's and nothing else unless the owner names it:
the owner asked on 2026-11-10
"How many times do I need to tell you to focus on the wrapper this session?",
after free slots had been filled with other packages' issues
(scope recorded in `doc/handover/cli-git-rust-implementation.md`).
A tool that slows down with dozens of agents running has a defect to fix;
the number of agents is never the explanation and never a reason to start fewer.

Each run is its own driver process with its own run folder and unit name.
Runs in one checkout share its files,
so two in one crate build each other's half-finished edits.
Give a run its own worktree whenever anything else is working in the same packages.
Start a run for every independent queued item up to that number.
Resource limits that add up to more than the host has are ceilings,
not usage,
and are no reason to hold work back.

The owner on runs that do not come back:
"Regularly,
check in on subagents that should have finished their jobs (based on time estimations 90%+ percentile) but haven't returned."
`watch-overdue-pi-runs` is that check,
and it is one command in the shape rule `MWK` asks for:
it ends when a run is past the 90th percentile of the finished runs in `--runs-folder`,
or when its `--deadline-seconds` pass,
and prints one line per run to act on and nothing else.
It computes the limit itself from those runs,
so nothing here needs to be remembered.
When a line names a unit,
`check-in-on-pi-runs --runs-folder=<folder> --unit=<that unit>` prints its open tool call and the processes under the agent
with their age,
state and kernel wait.
Both commands and their options are in `package/pi-shared/subagent-driver/README.md`.
A quiet feed is usually a long test run.
A message in `inbox/` reaches Pi only between tool calls,
so a tool call that will never return gets the message first,
and then has its hung process ended by process number.

## Who writes and who reviews

Writers and reviewers both run through Pi and this driver,
both on DeepSeek V4.1 Flash.
The owner,
2026-11-17:
"Once again, /pi-as-subagent . GPT and deepseek should both be in it now. And don't use the deepseek official provider.",
and of the driver package,
"We already have a package about pi as subagents in the workspace."
GPT 6.2 Sol wrote from 2026-11-17 to 2026-11-19 and was dropped under the owner's delegation
("if you think GPT is giving us too much trouble, cull it entirely"; the owner: "I tried using GPT as a writer because
6.2 models were released and I have a 100USD/month GPT plan, so I thought I'd use the quota.
Apparently not a good decision.").
The grounds, from the audit kept at
`~/temp/agent/writer-reliability-by-model-across-topics-2026-11-19/keep/report.md`:
OpenAI's content filter ended GPT runs and no DeepSeek run on record,
one GPT run declined a decision the project had made,
and routing around the filter needed relaying refused content to other vendors;
the audit found no correctness difference either way.

- **A writer**, a run that changes code or documents,
  runs on Pi's virtual writer,
  `--provider=rate-limit-fallback --model=writer`,
  whose router asks the reviewer's members, in the reviewer's order
  (`doc/decision/writer-rounds-take-qwen-first-through-the-virtual-writer.md`,
  "The writer's members become the reviewer's":
  the owner, 2026-11-27, typed "Change writer's list to match the reviewer's list.",
  which supersedes for the writer the order of 2026-11-26,
  "Qwen, opencode-go, flex (Recommended)"):
  `qwen-token-plan-individual/deepseek-v4.1-flash-1017`,
  then `synthetic/hf:deepseek-ai/DeepSeek-V4.1-Flash-1017`,
  then `opencode-go/deepseek-v4.1-flash`,
  then `neuralwatt/deepseek-v4.1-flash-flex`.
  The same record has the owner answer "Use the virtual writer (Recommended)" to whether rounds start on it,
  so a launcher names the virtual writer rather than one pool.
  A `429` before any output moves the request on to the next member with the same transcript
  (`package/pi-plugin/rate-limit-fallback/README.md`, "Order and refusal policy").
  A member whose own window cannot hold the request is passed over for that request alone,
  and the next member that can hold it answers,
  so Synthetic's member takes the requests its 524,288-token window holds and no others.
  The selection advertises its head member's window,
  1,000,000 tokens over those four members,
  so a writer round may fill a million tokens before Pi compacts
  (`doc/decision/writer-rounds-take-qwen-first-through-the-virtual-writer.md`,
  section "Skip a member too small for the request,
  and advertise the head's window").
  The driver counts such a run in no pool,
  `VIRTUAL_POOLS` in `package/pi-shared/subagent-driver/src/pool-limits.ts`:
  the owner,
  2026-11-26,
  asked how the driver's pool gate counts a run on the virtual writer,
  "No count (Recommended)",
  so the gate counts only the runs pinned to one pool and no member's room bounds such a run.
- **Standard Neuralwatt DeepSeek** (`--provider=neuralwatt --model=deepseek-v4.1-flash`) is closed,
  and no run names it.
  The owner,
  2026-11-11:
  "Please replace the neuralwatt standard deepseek pool with qwen-token-plan-individual  deepseek-v4.1-flash-1017".
  This section listed it first for writers until 2026-11-23,
  and launchers that call `drive-pi-subagent.ts` directly,
  past the pool gate that moves such a run,
  put writer rounds on it.
  The owner,
  2026-11-23:
  "I'm seeing a lot of deepseek-v4.1-flash (standard) calls in neuralwatt which has drained a lot of my quota.
  This shouldn't happen."
- **A reviewer**, a run that reviews a change outside a gate (the short, frequent kind),
  is DeepSeek V4.1 Flash from one pool in the owner's order:
  `--provider=qwen-token-plan-individual --model=deepseek-v4.1-flash-1017` first
  (the owner, 2026-11-18: "Add my qwen individual token plan deepseek-v4.1-flash-1017 to the deepseek pool."
  and "Orderings: qwen individual token plan first."; how many runs it takes at once is unmeasured;
  its terms fit these runs, the owner, 2026-11-19: "our traffic shape is approved and it is indeed agentic coding
  and you're monitoring them", so the session that starts a run on it watches that run until it ends),
  then the earlier order ("Synthetic and C and B, as a pool with preference."):
  `--provider=synthetic --model=hf:deepseek-ai/DeepSeek-V4.1-Flash-1017`,
  then `--provider=opencode-go --model=deepseek-v4.1-flash`,
  then `--provider=neuralwatt --model=deepseek-v4.1-flash-flex` with the doubled wall clock flex runs get.
- **The provider `deepseek` is never used**, for any run.
- **Gate reviews and long-horizon audits** stay on Claude Sonnet,
  by whatever route the harness offers, outside Pi
  (rule `LHZ`; the owner, 2026-11-17: "Rewrite, audits stay sonnet", and 2026-11-18:
  "Short reviews are supposed to be frequent. Long reviews and audits are supposed to have Sonnet and be rare.",
  with long meaning a review at a gate: an integration pass before main, a release, or a design put to the owner).

A writer and its short reviewer are the same vendor,
so a short review is a second pass, labelled so (rule `IRW`),
and independence comes from the gate reviews and audits on Sonnet.
The owner, 2026-11-19:
"Short reviews don't, because we're running long reviews and audits (with other vendor(s)) anyway."
This replaces reviews on Claude Sonnet subagents and GPT runs through `codex`
(rules `KRV` and `XVW` in `AGENTS.md`).
The provider order belongs in the driver package:
once its pool table holds these pools,
this list shrinks to a pointer there.

Synthetic now refuses on concurrency too:
on 2026-11-17, with about ten DeepSeek runs going, it answered `429 "Too many concurrent requests"`;
two of six bench reviews ended on it after 93 and 127 turns,
and the four that finished met it 31 to 74 times each
(the owner had written earlier "Synthetic doesn't have a concurrent limit. The Synthetic quota got blown once again.").
So a review that ends on a Synthetic 429 moves to the next pool and resumes its session there
with `--session=<session file>`,
and how many runs Synthetic takes at once is still to be measured.
The driver's pool table (`package/pi-shared/subagent-driver/src/pool-limits.ts`) lists the qwen plan's DeepSeek pool,
`opencode-go` and Neuralwatt's DeepSeek flex pool,
plus the virtual writer and reviewer,
whose routers ask those pools' members and Synthetic's DeepSeek model beside them,
and which both advertise their head member's 1,000,000-token window
while passing over a member whose own window cannot hold the request.
A run that names Synthetic itself, which belongs to no pool, is counted nowhere:
count such runs before starting more.
The DeepSeek pool order in the paragraphs on the 20-run limit is for runs that name no model;
a writer names the virtual writer,
and a reviewer names its pool's provider and model.
The Kimi pool is closed,
and its numbers stay in that table's comments.
Rerun a reviewer's reproduction before believing a finding.

## Start a run

`pi` is in `~/Monochromatic`,
on `PATH` only through that folder's `mise` environment:
an agent's shell has not activated `mise`,
so `command -v pi` finds nothing there,
and `mise exec -- pi` run from `~/Monochromatic` works.
A systemd user unit does not inherit the shell's `PATH` either;
launches without `--setenv=PATH` failed in seconds with `spawn pi ENOENT`.
The driver also asks the `git` that `PATH` resolves, in the folder the run works in,
whether it is this repository's Git policy wrapper,
and refuses before Pi starts when it is not (issue 1768),
naming the program it found and the folder to put on `PATH`:
the wrapper is the `git` link in `.cache/monochromatic-git-policy-cli-bin` under the checkout,
which `mise run toolchain:install` makes.
`start-pi-run-in-a-worktree` asks the same question before it starts a unit;
`package/pi-shared/subagent-driver/README.md` has the section "The git a session would run".

1.  From `~/Monochromatic`,
    check that `mise exec -- pi --version` prints a version.
2.  Make a new run folder under `${HOME}/temp/agent`,
    one per run.
    The driver writes everything there.
    Give the run's own scratch a folder of its own,
    and tell the run that the run folder and the prompt file belong to the driver
    and that it deletes only inside its scratch folder,
    with every `rm` path written literally:
    on 2026-11-22 a run cleaned up with `find $S -maxdepth 1 -mindepth 1 ! -name keep -exec rm -rf {} +`
    on the folder that held its scratch, its run folder and its prompt,
    which deleted the live run folder,
    so the driver exited 1 with no `summary.json`
    and the run's report was never written.
    Choose where Pi works:
    its own worktree (`git worktree add -b <branch> .claude/worktrees/<name> main`),
    or the main checkout for a small change with nothing else in those packages.
    Tell the run not to run `pnpm install` in a new worktree:
    the wrapper's commit service relinks its `node_modules` after the add returns
    (`package/git-policy/cli/README.md`,
    "Package-manager state in a new worktree"),
    and on 2026-11-21 an install started in that window left two worktrees whose copy could never finish,
    with a warning about each on every `git` command of every session until they were removed (issue 6339).
3.  Write the prompt to a file.
    Beside rules `ATH` and `NLD`,
    give it:

    - the owner's words as the requirement,
      quoted;
    - your own reading as a suggestion it may reject;
    - the files it must not edit,
      including everything `file-enforcer` generates;
    - that it commits its own work with explicit paths,
      as `AGENTS.md` says,
      on the branch checked out where it works;
    - a final report of each change,
      each commit,
      each disagreement,
      and anything it could not do,
      because it cannot ask you;
    - that the report is its very last message,
      repeated whole if it sends anything after it:
      `summary.json`'s `lastAssistantText` keeps only the last message,
      and on 2026-11-21 a run that answered a "your gate ended" notice after its report
      left only that one-paragraph answer there (issue 6337).

4.  Start it as its own capped unit,
    in the background.
    `--wait` makes this one command end when the unit ends,
    print the unit's result,
    and exit with its status;
    following `MainPID` with `tail --pid` waited out its whole timeout on a unit that had already finished.
    The entry file uses only Node built-ins,
    so it runs from source with no build and no `node_modules`.
    The example starts a writer;
    a reviewer names the provider and model its pool gives
    (section "Who writes and who reviews"):

    The driver gives each run's Pi its own temporary folder,
    `temporary-files-pi-wrote` inside the run folder (mode `0700`),
    and starts Pi with `TMPDIR`, `TMP` and `TEMP` naming it,
    so Pi's spilled tool output stays out of `/tmp` with nothing passed here
    (`package/pi-shared/subagent-driver/README.md`).

    ```sh
    # run from ~/Monochromatic
    systemd-run --user --wait --unit=pi-<task> --collect \
      --property=RuntimeMaxSec=2500 --property=MemoryMax=3G --property=CPUQuota=200% --property=TasksMax=300 --property=IOWeight=1 \
      --setenv=PATH="$(mise exec -- printenv PATH)" --setenv=HOME="$HOME" \
      "$(mise exec -- bash --noprofile --norc -c 'command -v node')" \
      "$PWD/package/pi-shared/subagent-driver/src/drive-pi-subagent.ts" \
      --run-folder=<run> --working-folder=<its worktree, or "$PWD"> --prompt-file=<prompt-file> \
      --provider=rate-limit-fallback --model=writer \
      --wall-seconds=2400 --turn-cap=<sized from past runs>
    ```

    Size `--turn-cap` to the task from past runs at every launch.
    The owner,
    2026-11-09:
    "Always Size turn limits to the task based on past data."
    Read what the finished runs of the same kind used,
    narrowing by the run folders' names:

    ```sh
    # run from anywhere; <runs> holds the run folders, and the pattern picks the runs like this one
    jq --slurp '[.[] | select(.endReason == "idle" and (.turns | type == "number")) | .turns] | sort
      | {runs: length, median: .[length / 2 | floor], p95: .[length * 0.95 | floor], highest: .[-1]}' \
      <runs>/*-findings-fixed-*/summary.json
    ```

    Set the cap a quarter above `highest`,
    so a run as long as the longest that finished still has room.
    When too few runs of that kind have finished to say anything,
    read every run instead.
    A cap exists to end a run that stopped getting anywhere;
    one that fires on a working run costs a resume and leaves its work uncommitted.
    Measured at 2026-11-09T07:42:00-05:00 over 254 runs:
    finished fix rounds from a review or audit used a median of 126 turns,
    a 95th percentile of 329 and at most 358,
    every finished run at most 377,
    and a fixed cap of 400 ended a run with uncommitted work after 154 of its 180 minutes.

5.  Read progress from `<run>/feed.jsonl` when asked.
    To steer,
    write a text file under a name starting with a dot in `<run>/inbox/`,
    then rename it to one without the dot,
    because the driver reads any other name at once.
    Pi gets it as a steer while it runs and as a new prompt while it is idle,
    and `--idle-seconds` is how long the driver stays up for one after Pi settles.
    It defaults to 0, by the owner's "And shouldn't it be defaulted to 0?" of 2026-11-18:
    a coordinator woken by the run's end could never steer inside a window,
    and a message already in `inbox/` when Pi settles is still delivered.
    Pass a positive value only when you will steer a settled run.
    An entry must be an ordinary file:
    a named pipe is set aside rather than waited on.
    A message Pi refused,
    or an entry that cannot be read,
    stays there as `.failed-<name>`,
    and a later message of the same name that is also refused gets a number after it,
    so nothing replaces an earlier one.
    To end the run early,
    create `<run>/stop`.
6.  Read the result from `<run>/summary.json`,
    which appears last,
    so its presence means the driver has finished.
    `piExit` is there only when Pi's exit was seen,
    so a summary naming `pi-not-stopped` claims nothing about Pi having gone:
    the unit's own cleanup ends that process,
    and its `RuntimeMaxSec` is what bounds the driver when a file system call or a named pipe keeps it alive past the
    summary.
    `endReason` says how it ended:
    `idle` and `stop-file` exit 0,
    and `prompt-rejected`,
    `pi-exited`,
    `turn-cap`,
    `wall-clock`,
    `driver-failed`,
    `model-error` and `pi-not-stopped` fail the unit,
    and a Pi that left with a failing status after the run ended as `idle` fails it as `pi-exited`.
    `lastAssistantText` holds the whole final report,
    `sessionStats` holds the cost and names the session file,
    `modelError` holds what the model said when it settled on an error nothing recovered from,
    `modelErrorAttempts` says how many attempts that took,
    `retries` counts the attempts after a model error,
    `rateLimitErrors` counts the model errors that named a rate limit or a quota,
    and `feedProblem` names why the feed is incomplete when it is.
    The driver answers a transient model error with another attempt on its own:
    a provider server error,
    a request timeout,
    a dropped connection,
    or a rate limit is retried up to `--retry-cap` times with a growing wait,
    and anything else ends the run on its first error as before.
    Each attempt is a `retry` line on `feed.jsonl`,
    and `summary.json` says what they were,
    so a run that needed them reads apart from one that did not.
    A run that used up its attempts still ends `model-error`,
    which is when to start it again from the same session file as step 7 says.
7.  For a follow-up after the driver has exited,
    start the same unit under a new name,
    with a new run folder,
    a new prompt file,
    and `--session="<session file>"`.
8.  Read what it committed with `git log` and `git show`,
    fix anything wrong with further commits,
    regenerate anything `file-enforcer` owns,
    and merge a worktree's branch into `main`.
    The owner wrote "I don't think you'd need to rerun the same lints or tests another agent did, do you?":
    read which suites the agent's report names instead of running them again.
    After merging `main` into the branch,
    run only the compile or type check,
    which is what the agent could not have run on the combined tree,
    and skip that too when `main` was already in the branch.
9.  Remove a run's worktree as soon as its unit has ended,
    whether or not its branch has landed yet.
    The owner,
    2026-11-10:
    "You're the coordinator and you're supposed to remove finished worktrees automatically."
    A worktree added on btrfs is a snapshot of `main`,
    so it keeps every file `main` held when it was taken,
    build folders included,
    after `main` has replaced them.
    That day the owner found the 860 nearly full with 460 worktrees in place,
    and one finished worktree measured 26.5 GiB,
    48.7 MiB of it its own and 14.35 GiB shared with other subvolumes,
    so removing one frees little and removing all finished ones frees what only they keep.
    Remove it with the wrapper's `git worktree remove <worktree>`,
    without `--force`,
    which refuses a worktree holding uncommitted work.
    The branch stays,
    and a later run of the same name adds the worktree again from it.
    Leave a worktree whose unit is active,
    one a process still works in,
    and one with uncommitted work,
    and say which were left and why.

## Protocol

- One JSON command per line on stdin,
  one JSON record per line on stdout,
  logs on stderr.
  Split stdout on LF only,
  because Unicode line separators are valid inside JSON strings.
  Closing stdin ends the process.
- Every command takes an optional `id` that its `response` repeats.
- `{"id":"c1","type":"prompt","message":"..."}` answers `disposition: "started"`:
  accepted,
  not finished.
  A prompt sent mid-run needs `"streamingBehavior":"steer"` and answers `queued`;
  without it Pi rejects the prompt (documented,
  not run).
  `{"type":"steer","message":"..."}` and `{"type":"follow_up","message":"..."}` also queue during a run.
  `{"type":"get_last_assistant_text"}` returns `data.text`,
  or an empty object when the session has no assistant message.
- Wait for `agent_settled` before reading the final text;
  `agent_end` ends only one low-level run.
  Register that waiter before sending `prompt` or `abort`,
  because `agent_settled` can arrive before the response does.
- A dialog request (`extension_ui_request` with method `select`,
  `confirm`,
  `input`,
  or `editor`) waits for an answer,
  and the source leaves it pending forever unless a timeout field or an abort resolves it.
  Answer each with an `extension_ui_response` carrying the request's `id`;
  `{"type":"extension_ui_response","id":<the request id>,"cancelled":true}` declines it,
  and the driver declines all of them.
  The other UI methods (`notify`,
  `setStatus`,
  `setWidget`,
  `setTitle`,
  `set_editor_text`) need no reply.
- A prompt that cannot start (a missing key,
  for example) comes back as a `response` with an error text and no events,
  so a client that waits only for `agent_settled` waits forever:
  give it a deadline and an exit handler.
- A process holds one active session at a time;
  `fork`,
  `clone`,
  `switch_session`,
  and `new_session` replace it.
  `switch_session` to a file that does not exist still reports success.
  Parallel agents need separate processes.

## Pi quirks

- A Pi agent may end its turn while work it started keeps running (a build or a reproduction in its own scope);
  whoever drives it resumes the session when that work ends.
  Never brief a Pi agent to wait for long commands in one tool call:
  that rule exists only for Claude Code native subagents, whose turn end returns to the main agent.
  The owner, 2026-11-11:
  "Ending its turn is good. We don't want unnecessary waste of tokens."
  and "Claude Code native subagents, when they end their turn, will directly return to the main agent, which is annoying and wasteful. Pi agents don't have this quirk because we drive pi ourselves."
  The coordinator's launcher waits for such work and resumes the session with a short note
  (`${HOME}/temp/agent/pi-runs/start-pi-run-in-worktree.ts`, region "Wake an agent whose own work outlived its turn").
- A round a restart ended goes on from its own session,
  not from a fresh one:
  `resume-a-build-round.ts` in the round's launch folder takes the round folder,
  the worktree name,
  the branch,
  the round's own continuation file and a new unit name,
  starts Pi from the newest session of that worktree,
  and makes the worktree again when it is gone.
  The session already holds its turns.
  A round that ended by itself has `summary.json` in its run folder and its report under its
  `keep/`.
  Before a restart of the machine,
  check that every round still going has a commit of its work on `origin` or a `state-so-far.md` in
  its `keep/`,
  since nothing under `${HOME}/temp/agent` is counted on to outlast one.
- Leave extensions loaded:
  some providers exist only because an extension registers them,
  and `--no-extensions` made `synthetic` unknown.
- `pi auth check --provider neuralwatt --model deepseek-v4.1-flash --json --no-refresh` printed `invalid_state`
  and the same model worked in a real run:
  trust a prompt that gets a reply.
- The repository's `ask-user-question` tool works only in the terminal UI and answers RPC with an unavailable-tool error,
  and `ui.custom()` returns `undefined` at once in RPC mode,
  so the subagent cannot put a question to the human.
- The owner's real home has a `thinking-default` plugin (`package/pi-plugin/thinking-default`) that sets the level on every start and model change,
  whatever the command line says:
  `xhigh` when the model offers it,
  and `high` when it does not (it never picks `max`).
  So a run's reported level differs by provider for the same model family:
  Neuralwatt's DeepSeek reports `xhigh`,
  and `qwen-token-plan-individual`'s DeepSeek, whose efforts are low, high and max, reports `high`.
  Leave the thinking level alone:
  pass no `--thinking` and send no `set_thinking_level`.
- In a throwaway folder,
  project `.pi/settings.json` was ignored with no message unless the child got `--approve`;
  other project resources were not tested.
- A multi-block `edit` is rejected whole when any one `oldText` does not match,
  and a `find` given a path as its pattern returns "No files found" with `isError` false,
  so a soft miss and a success look alike until the result text is read.

## DeepSeek V4.1 Flash quirks

The owner rates it at about a low-level Sonnet 5.5 at its middle thinking level,
and finds it works poorly at any other.
The owner, 2026-11-11, correcting an earlier wording here that named `xhigh`:
"I meant DeepSeek is poor on anything but the thinking level between none/low and max.
Actually, I also just checked AA and found out its official (proper) configs only supports none high and max,
which means neuralwatt's xhigh is mapped to high internally anyway."
So `high` is the level to run it at, and a provider that reports `xhigh` for it is sending the same effort.
The owner also said:
"Expensive models are also not necessarily more trustworthy than cheap models."
It implemented and checked a multi-file change from a problem statement and evidence,
without step-by-step instructions,
though it also found the repository's existing diagnosis.

- Unprompted,
  it declines a hard or open objective:
  given "prove the Collatz conjecture" it answered that the problem is open and ended its turn.
  Told to attempt a proof,
  it did the work:
  a written proof attempt and compiled verifiers.
  Phrase a hard objective as attempts to make,
  and steer with one concrete next attempt when it stalls.
- It recovers from its own tool-argument slips without help.
- Long thinking leaves the feed quiet.
  Check the process state and the time of the last event before calling a run stuck.
- It left scripts and compiled binaries in `/tmp`,
  and notes and sources in its working directory.
- It finds and uses repo docs that already describe the problem,
  including ones that name the cause,
  so a good result may come from the doc and not from its own work.
- It builds more than the problem needs.
  Unassisted,
  it wrote a prompt change plus a phrase-list post-filter and tests,
  a much larger change than the prompt-only change that measured the same.
  Read the diff's scope against the problem.
- Told to change only the words a task needs,
  it did:
  four one-line edits,
  after 35 turns and 56 tool calls of checking.
- Given the lead's reading as a suggestion to check,
  it disagreed with one item,
  cited the commit that added the sentence,
  and was right.
  Offer a reading as a suggestion,
  not an instruction.
- It wrote `.mjs` scratch files despite rule `NMJ`.

The driver's options and files:
`package/pi-shared/subagent-driver/README.md`.
Recorded experiments and protocol evidence:
`doc/agent/drive-pi-as-a-subagent.md`,
`doc/agent/drive-pi-as-a-coding-subagent.md`,
and `doc/agent/pi-goal-extension-driven-through-rpc.md`.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.