README.md
pi-t3-bridge
pi-t3-bridge is a Pi package that runs Pi as an agent inside T3 Code. It gives a Pi thread the tools T3 expects, and it adds two skill sets, pstack and tstack, so the thread can plan work, hand parts of it to other models, and check what comes back.
| 1 | flowchart LR |
| 2 | You((You)) --> T3[T3 Code] |
| 3 | T3 -->|runs a thread| Pi[Pi agent] |
| 4 | subgraph pkg [pi-t3-bridge] |
| 5 | Bridge[bridge.ts<br/>cards, goals, workflows, limits] |
| 6 | Pstack[pstack.ts<br/>pstack skills, model routing, child sandbox] |
| 7 | Tstack[tstack.ts<br/>tstack skills] |
| 8 | end |
| 9 | Pi --> Bridge & Pstack & Tstack |
| 10 | Bridge -->|MCP| T3 |
| 11 | Pstack -->|delegate_task| T3 |
| 12 | T3 -->|child threads| Models[Claude, GPT, and other models] |
Requirements
You need Node.js 22.19.0 or later and Pi 1.5.0 or later. T3 Code is needed only if you run Pi threads inside T3 or call T3 tools from Pi.
On Linux, delegated children run in a bwrap sandbox, so you also need the bubblewrap package. If AppArmor stops bwrap, run sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0.
Install
The package is on GitHub only, so you install it with Pi from git.
| 1 | pi install git:github.com/Snestra/pi-t3-bridge # newest commit on main |
| 2 | pi install git:github.com/Snestra/pi-t3-bridge@v0.10.1 # one release |
| 3 | pi -e git:github.com/Snestra/pi-t3-bridge # one session, nothing saved |
pi update --extensions moves an install from main to the newest commit. If you still have the old npm package, run pi remove npm:pi-t3-bridge before you install from git.
Each of the three extensions works on its own, so you can load only the ones you want.
| 1 | { |
| 2 | "packages": [ |
| 3 | { |
| 4 | "source": "git:github.com/Snestra/pi-t3-bridge", |
| 5 | "extensions": ["bridge.ts"] |
| 6 | } |
| 7 | ] |
| 8 | } |
What is in the package
| 1 | pi-t3-bridge/ |
| 2 | ├── bridge.ts # connects Pi to T3 Code |
| 3 | ├── pstack.ts # serves pstack skills and picks models for subagents |
| 4 | ├── tstack.ts # serves tstack skills |
| 5 | ├── src/bridge/ # code for bridge.ts |
| 6 | ├── src/pstack/ # code for pstack.ts, including the child sandbox |
| 7 | ├── pstack/ # upstream pstack skills, agents, and model defaults |
| 8 | ├── overlay/ # the changes Pi needs on top of pstack/ |
| 9 | └── tstack/ # Theo Browne's tstack skills |
Tools and commands
The bridge adds the tools and commands below, and T3 shows most of them as cards in the chat. If another package already has a tool with the same name, e.g. ask from pi-ask, the bridge keeps the other tool and tells you once.
| Name | What it does |
|---|---|
tasks | Shows the task list for the run as a card. With workflowId, it shows a workflow's steps. |
plan | Shows a plan card with Approve, Revise, and Cancel buttons. |
ask | Asks you questions as cards and waits for your answers. |
create_workflow, get_workflow | Save and read a workflow of steps with dependencies and acceptance checks. |
launch_workflow_step, reconcile_workflow_step | Start a delegated step in T3, and settle a launch whose result is unknown. |
transition_workflow | Starts, finishes, retries, or cancels a step, holds a local step for your decision, or records that a worktree step was merged. |
get_goal, update_goal | Read the saved goal, and report completion or a blocker with evidence. |
transcript | Returns the session file and session ID. |
pstack_model | Picks the model for a subagent. It comes from pstack.ts. |
/goal | Saves, shows, edits, pauses, resumes, or clears the session's goal. |
/t3-usage | Shows the cost of the thread and its children, the cache hit rate, and which model families are out of usage. |
/t3-exhausted <family> [reset time], /t3-recovered <family> | Mark a model family as out of usage, or usable again, for every chat on the machine. |
/t3-transcript | Shows the session file path. |
Workflows
A workflow is a saved list of steps that the agent works through in order, and each step must show evidence before the steps after it can start. The agent creates one with create_workflow when a job has parts that depend on each other or that other models should do in parallel.
| 1 | create_workflow |
| 2 | id: "fix-login" |
| 3 | concurrency: 2 # steps that may run at the same time |
| 4 | maxAttempts: 2 # tries per step |
| 5 | goalId: <optional> # ties the workflow to the saved goal |
| 6 | steps: |
| 7 | reproduce local shared acceptance [repro-output] |
| 8 | fix-api delegated worktree depends on reproduce acceptance [tests-pass] |
| 9 | fix-ui delegated worktree depends on reproduce acceptance [screenshot] |
| 10 | merge local shared depends on fix-api, fix-ui integrates fix-api, fix-ui |
A step runs either in the parent thread or in a child thread. A local step always works in the parent's own checkout, which the schema calls shared. A delegated step runs in a T3 child, either in the same checkout or in its own git worktree.
| Executor | Isolation | How it starts | How it ends |
|---|---|---|---|
local | shared | transition_workflow with start | transition_workflow with finish and evidence |
delegated | shared or worktree | launch_workflow_step, which calls T3's delegate_task | transition_workflow with finish, after T3 reports the child done |
Step states
A step becomes ready only when every step it depends on has succeeded with evidence for each acceptance ID. A worktree step's output must also be merged by a shared step that lists it in integrates, unless the step that depends on it is that same shared step.
| 1 | stateDiagram-v2 |
| 2 | [*] --> pending |
| 3 | pending --> ready: dependencies accepted |
| 4 | ready --> running: start or launch |
| 5 | running --> waiting_for_child: T3 started the child |
| 6 | running --> waiting_for_user: launch result unknown, or local wait |
| 7 | waiting_for_user --> running: resume, or reconcile as started |
| 8 | waiting_for_user --> failed: reconcile as not started |
| 9 | running --> succeeded: finish with evidence |
| 10 | waiting_for_child --> succeeded: finish after the child is done |
| 11 | running --> failed: finish as failed |
| 12 | waiting_for_child --> failed: finish as failed |
| 13 | waiting_for_child --> cancelled: cancel the child |
| 14 | failed --> pending: retry, if attempts remain |
| 15 | ready --> cancelled: cancel before start |
Launch and finish of a delegated step
The bridge records the intent to launch before it calls T3, so a crash between the two calls never leaves a child the workflow does not know about. After a restart, a step with only an intent moves to waiting_for_user, and the agent checks T3 and calls reconcile_workflow_step.
| 1 | sequenceDiagram |
| 2 | participant Agent |
| 3 | participant Bridge |
| 4 | participant T3 |
| 5 | participant Child |
| 6 | Agent->>Bridge: launch_workflow_step(stepId, revision, task) |
| 7 | Bridge->>Bridge: save launch intent |
| 8 | Bridge->>T3: delegate_task |
| 9 | T3->>Child: start |
| 10 | Bridge->>Bridge: save child task ID, state waiting_for_child |
| 11 | Child-->>T3: final result |
| 12 | Agent->>Bridge: transition_workflow(finish, evidence) |
| 13 | Bridge->>T3: task_status |
| 14 | T3-->>Bridge: completed, no pending work |
| 15 | Bridge->>Bridge: save result, state succeeded |
The bridge accepts a delegated step as finished only when T3 says the child is done, with no question, approval, or child work still pending. Otherwise finish saves the latest child status and leaves the step waiting.
Rules the bridge enforces
The bridge checks every change against the saved workflow, so two calls can't overwrite each other and a stale plan can't run.
| 1 | on(any workflow change) |
| 2 | if revision differs from the saved revision refuse |
| 3 | if the workflow belongs to another session or branch refuse |
| 4 | if the workflow names a goal that no longer allows work refuse |
| 5 | if a second shared step would write the checkout refuse |
| 6 | if running steps would exceed concurrency refuse |
| 7 | if the step has used all its attempts refuse retry |
| 8 | save the new workflow and add 1 to revision |
Workflows live as t3.workflow.v1 entries in the session file, so each branch of a session has its own workflows. When a workflow names the saved goal, the goal can't complete until every step of the workflow is accepted, and pausing the goal also cancels the workflow's running children.
Saved goals
/goal <objective> saves one objective on the session branch and starts work on it. When the agent stops before it has finished, the bridge asks it to continue, until the agent reports completion with evidence or reports a blocker.
| 1 | active |
| 2 | completion with current evidence complete |
| 3 | the same blocker for 3 cycles blocked |
| 4 | Stop, or a restored session paused |
| 5 | paused or blocked |
| 6 | /goal resume active |
| 7 | any state |
| 8 | /goal clear no goal |
| Command | Result |
|---|---|
/goal | Shows the objective, status, and reason, without a model request. |
/goal <objective> | Starts a goal when no unfinished goal exists. |
/goal -- <objective> | Starts a goal whose first word is a command word, e.g. edit. |
/goal edit <objective> | Changes an unfinished goal, and drops its old evidence. |
/goal approve | Approves the acceptance conditions the agent proposed. |
/goal review | Lets you judge evidence for conditions that no command can check. |
/goal pause, /goal resume, /goal clear | Pause, restart, or remove the goal. |
The agent proposes acceptance conditions, and each condition may name a command and its exit code, or a file and the text it must contain. After you approve the conditions, the bridge runs those checks itself when the agent reports completion. A condition with no check waits for /goal review.
| 1 | update_goal(status: complete) |
| 2 | if conditions are not approved refuse |
| 3 | if a question, approval, child, or linked workflow is pending refuse |
| 4 | if the files changed since the evidence refuse, gather fresh evidence |
| 5 | run each command and file check |
| 6 | if every condition has current evidence mark complete |
In T3, press Stop before you send a goal command, because T3 refuses commands while the thread is busy. In a terminal or over RPC, you can send them at any time. With pi -p "/goal <objective>", Pi waits for the goal's run to end before it exits.
Goals have no token or time budget, and normal permissions still apply. Opening, reloading, or cloning a session pauses an active goal, so only /goal resume starts work again.
Plan approval
T3's own Plan mode does nothing in a Pi thread, because T3 doesn't send the Plan setting to Pi. The agent uses the plan tool instead, and while the plan card waits for you, the bridge blocks every tool that can change files.
| 1 | stateDiagram-v2 |
| 2 | [*] --> open |
| 3 | open --> waiting: agent calls plan |
| 4 | waiting --> approved: Approve |
| 5 | waiting --> revising: Revise |
| 6 | waiting --> cancelled: Cancel |
| 7 | revising --> waiting: agent calls plan again |
| 8 | cancelled --> open: you send a new message |
| 9 | approved --> [*]: write tools run again |
Read-only tools still run while the card waits, so the agent can keep reading files. If the card can't render, the plan appears in a selection dialog instead.
Reply checks
When a run is about to stop, the bridge checks the last reply with two fixed rules. No model judges the reply, so the same reply always gets the same result.
| 1 | on(run about to stop) |
| 2 | if the reply hit the output limit |
| 3 | continue, at most twice per prompt |
| 4 | else if the last 5 lines of prose ask a question |
| 5 | and the ask tool is on, and the session is not a child |
| 6 | tell the agent to ask with the ask tool, once per prompt |
A question in plain text ends the run, and nobody sees it. The second rule sends the agent back to put the question on an ask card, which waits for your answer. Code blocks and inline code don't count, so a ? in a regex is ignored.
Usage limits and resume
The bridge keeps one record of which model families are out of usage, and every Pi session on the machine reads it. When a child fails with a usage limit, the bridge marks its family as out until the reset time, and pstack sends new work to another family.
| 1 | sequenceDiagram |
| 2 | participant Parent |
| 3 | participant Bridge |
| 4 | participant T3 |
| 5 | Parent->>T3: delegate_task (Claude) |
| 6 | T3-->>Bridge: child failed, usage limit |
| 7 | Bridge->>Bridge: mark claude as out until the reset |
| 8 | Parent->>T3: delegate_task (next family) |
When the main thread's own account runs out, the agent can't call any tool. The bridge then asks T3 to post a resume message into the thread just after the reset time.
Shell time limit
The bridge stops any shell command after 300 seconds, in the main thread and in children. A command can ask for a shorter limit but not a longer one, and you can change the limit with bashTimeoutSeconds.
T3 tools from a terminal
When you run Pi in a terminal, the bridge connects it to the MCP server of the T3 Code app on your machine, so you can start and message T3 threads from the terminal.
| 1 | on(session start) |
| 2 | if Pi runs inside a T3 thread |
| 3 | use the tools T3 gives the thread |
| 4 | else |
| 5 | if the saved token is missing or expires within a day |
| 6 | sign in with the t3 CLI, no browser needed |
| 7 | connect to mcpUrl |
| 8 | show "connected, N tools" or the error in the status bar |
The token lasts 30 days and is saved in ~/.local/state/pi-t3/t3-mcp.json. When mcpUrl points at a T3 server on another machine, sign in with /mcp login t3 instead.
The pstack extension
The pstack extension serves the pstack skills, which reach Pi through t3-pstack. The poteto-mode skill picks the workflow that fits your request, e.g. a bug fix, a feature, a design review, or a PR watch.
| 1 | on(Pi start) |
| 2 | copy pstack/ to ~/.local/state/pi-t3/pstack-overlay/<hash>/ |
| 3 | apply each change in overlay/ to the copy |
| 4 | serve the skills from the copy |
The pstack/ folder keeps the upstream text unchanged, and overlay/ holds the changes Pi needs. If an overlay change no longer matches a new upstream version, the tests fail and name the file.
Model routing
The pstack_model tool returns the T3 target for a subagent, based on its role, job, and size.
| 1 | pstack_model(role, job, size) |
| 2 | if size is L refuse, so the agent splits the job |
| 3 | if the model sheet names a model use it |
| 4 | else look up job and size in pstack/models.json |
| 5 | if the model's family is out use the same tier in the next family |
| 6 | return the target for delegate_task |
| Job | Size S (30 min, 5 files) | Size M (90 min, 15 files) |
|---|---|---|
mechanical | Haiku 5.5, low | Sonnet 5.5, medium |
check | GPT 6 Luna, low | Haiku 5.5, medium |
research | Muse Spark 1.3, medium | Muse Wonder 1.0, medium |
implement | GPT 6.1 Sol, medium | Sonnet 5.5, high |
hard | Opus 5.5, high | Opus 5.5, high |
review panel | Opus 5.5, Muse Wonder Full 1.0, GPT 6.1 Sol | same |
design panel | Opus 5.5, Muse Wonder Full 1.0, GPT 6 Astra | same |
To choose your own models, run the setup-pstack skill. It writes a model sheet at ~/.config/pi-t3-bridge/models.md, and a line of session hook: off in the sheet stops the poteto-mode note on each prompt.
Limits for delegated children
When a session starts with a complete pstack brief, the extension treats it as a delegated child and holds it to the limits in the brief. The child can't lift the limits through anything it writes.
| 1 | on(tool call) |
| 2 | if the first message is not a "# Task:" brief |
| 3 | your own session, no limits |
| 4 | else if the brief is complete |
| 5 | child: sandboxed shell, writes only to listed files, time and disk limits |
| 6 | else if T3 started the session as a delegated task |
| 7 | block every tool and list what the brief is missing |
| 8 | else |
| 9 | your own session, no limits |
A brief is complete when its header names the job, size, time limit, and disk limit, and it has all seven sections of pstack/skills/poteto-mode/brief.md. The child writes its report from commands it ran itself, and the parent reads the report from ledger.jsonl when it checks the task.
The child sandbox
A delegated child runs every shell command in a sandbox, which is sandbox-exec on macOS and bwrap on Linux and WSL2. The child can write to its own work and to package manager caches, and everything else stays read-only.
| 1 | writable inside the sandbox |
| 2 | ├── <workdir>/ # the child's checkout |
| 3 | ├── <git dir>/ # so git commit works, except hooks/ and config |
| 4 | ├── ~/.cache, ~/.npm, ~/.local/share/uv, ~/.local/share/mise |
| 5 | ├── <pnpm store>/ |
| 6 | ├── <system temp folder>/ # also $TMPDIR and $XDG_RUNTIME_DIR |
| 7 | └── /dev |
Install scripts don't run inside the sandbox, because a prepare such as lefthook install would fail on the read-only hooks. On Linux each child also gets its own process namespace, so a stray pkill can't reach the host.
Chrome and Electron need --no-sandbox inside the child, and a pi run inside a child needs PI_CODING_AGENT_DIR set to a writable copy of ~/.pi/agent. Native Windows and WSL1 have no sandbox, so the bridge blocks a child's shell commands there unless you set childSandbox to "off".
The tstack extension
The tstack extension serves Theo Browne's skills from tstack/skills. They cover the PR cycle, from file-pr through babysit-pr, plus council, sol-loop, full-send, full-stop, takeover, modernize, and leaving-pr-comments.
Settings and files
The bridge reads ~/.config/pi-t3/config.json again on each prompt, and every key is optional. If a value is invalid, only that key falls back to its default.
| Key | Default | Meaning |
|---|---|---|
bashTimeoutSeconds | 300 | The longest a shell command can run, in seconds. |
childSandbox | "on" | With "off", child commands run with no sandbox on every platform. |
mcpUrl | http://127.0.0.1:3773/mcp | The T3 MCP address for Pi in a terminal. It applies on the next /new, /reload, or start. |
| 1 | ~/.config/ |
| 2 | ├── pi-t3/config.json # bridge settings |
| 3 | └── pi-t3-bridge/models.md # model sheet from setup-pstack |
| 4 | ~/.local/state/pi-t3/ |
| 5 | ├── accounts.json # model families that are out of usage |
| 6 | ├── ledger.jsonl # one line per delegated brief, with cost and report |
| 7 | ├── t3-mcp.json # T3 MCP token for Pi in a terminal |
| 8 | └── pstack-overlay/ # pstack skills with the Pi changes applied |
XDG_CONFIG_HOME and XDG_STATE_HOME replace ~/.config and ~/.local/state when they are set.
Data handling
The package has no server and sends no telemetry. Any file a skill asks the agent to read goes to your model provider, and the PR tools use your GitHub CLI login.
Development
The repository uses npm, and some tests need Docker to run Linux containers.
| 1 | npm install |
| 2 | npm test # node:test suites for the bridge and the pstack scripts |
| 3 | npm run typecheck |
| 4 | npm run check # Ultracite lint and format check |
The pstack/ folder is a git subtree of t3-pstack, so you take upstream changes with git merge -X subtree=pstack pstack-upstream. Put Pi changes in overlay/, and leave pstack/ as upstream wrote it.
License
The package uses the MIT license. See LICENSE and NOTICE.md for the copyright holders, who include Lauren Tan, Cursor, and Christian Bager Bach Houmann.