Install
Install with PiG
pig install npm:pi-attachInstall with Pi
pi install npm:pi-attachPackages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.
Pi manifest JSON
The pi field of package.json.
{
"image": "https://raw.githubusercontent.com/shahidshabbir-se/pi-attach/main/assets/attach.png",
"extensions": [
"./index.ts"
]
}README
Written by the package's publisher, shown as published in version 0.3.0 (README.md). PiG does not review it.
pi-attach
Subagents for Pi you can attach to, with git worktree isolation. Delegate work, then step into the running agent's own Pi conversation — live transcript, native tool cards, steering, resume — without leaving the terminal. Writing agents can work on their own branches, keeping changes separate until you're ready to merge.

pi install npm:pi-attach
Then just ask for help:
use a background task: Explore reads every file in src and says what each does
Why another subagents package
Most manage agents as rows in a dashboard. pi-attach treats a Subagent as a whole Pi session you can walk into. By default the child is its own interactive pi TUI on a pseudo-terminal: Attach hands it the terminal, so you are literally in the child's session. When PTY support is unavailable, Pi reconstructs the same conversation from the child's event stream using its own components. Either way, type while it runs and your message steers it; type after it finishes and it resumes the same session, with everything it already learned.
Writing agents can also work in isolated git worktrees, each on its own branch. The delivery reports the changes and a merge command, so you can review and integrate the work when you're ready. Worktrees isolate the working directory, not absolute-path writes; they are not a sandbox.
No tmux. No panes. No overlay. It is drawn by Pi and works in any terminal.
| (blank) | pi-attach |
|---|---|
| Transport | one real interactive pi per Task on a PTY; RPC fallback when PTY is unavailable |
| Navigation | the child's TUI replaces the parent's view in place |
| Steering | type in the child's view; steer or queue |
| Resume | --session <file> on the finished child |
| Sessions | children write to <parent session>/subagents, so /resume stays clean |
| Rendering | the child's own Pi TUI, or Pi's components reconstructed from RPC events |
| Worktrees | Isolated checkout and branch per writing Task; delivery includes changes and a merge command |
| Limits | maxTurns, effort, skills, mcpServers, hooks, memory, context per agent |
Tools
The parent model gets one tool:
task({ agent: "Explore", name?: "List ADR files", prompt: "…", model?: "fast", isolate?: true })
name labels the Task in the Agent List and its delivery. model asks for a declared role such as fast; leave it out unless the Task needs something different. isolate: true runs the Task in its own git worktree.
Concurrency is capped (default 4) and the rest queue. x in the Agent List stops a Task. Closing Pi stops its children.
Agents
Two definitions ship inside the package:
Explore— read-only search and reading (read,grep,find,ls,bash)general-purpose— full tool access for multi-step work
Drop ~/.pi/agent/agents/<name>.md to override one by name, or to add your own. The current roster, with each agent's role and model, is part of the task tool description, so the parent knows what it can delegate to.
Children inherit your installed extensions by default, so guardrail extensions still ask you before doing something risky — the dialog names the agent that triggered it. An agent can opt out with extensions: none.
Worktrees
Tasks run in the Parent's directory by default. Request a separate checkout with isolate: true, or set worktree: true in an agent definition. Worktree isolation requires a repository with at least one commit.
Ran in worktree pi-attach/write-hello-b8bxzy (/home/you/.pi/agent/worktrees/sa-b8bxzy).
Changes: 1 file changed, 1 insertion(+)
Merge with: git merge pi-attach/write-hello-b8bxzy
The checkout lives under Pi's agent directory (~/.pi/agent/worktrees/), so no project tree is ever touched, and worktree.dir moves it; the branch is kept, so nothing is lost. It is a working directory, not a sandbox: a Task that is handed an absolute path can still write there. worktree.cleanup decides whether a directory survives a Task — when-clean keeps one that has changes, always commits the leftovers to the branch and reclaims it. A Parent that dies leaves its worktrees behind, so starting Pi in a repository reaps the orphans, committing their edits to the branch first. worktree.enabled: false turns the whole feature off.
Limits
An agent file can bound how a Task runs, and every limit is checked before the child starts:
---
name: reviewer
tools: read, grep, bash
worktree: true
maxTurns: 30
effort: high
skills: [skills/review]
mcpServers: [sentry]
memory: [notes/project.md]
context: none
---
agentLimits in config overrides the file; a bad level or a missing path fails the Task, naming the field, rather than silently doing nothing.
mcpServers is connection-level: the child gets a mirrored agent directory whose mcp.json holds only the servers the agent named, with auth, settings and extensions symlinked through, so unwanted servers never connect.
Nesting
nesting.maxDepth (default 1) withholds task from a Subagent at the limit, as Claude Code does. Raise it and a child's Tasks appear as nested rows under it:
❯ general-purpose Nested check (+1) running · 21s
└ ● Explore List files running · 15s
A child that delegated is held open until its follow-up turn carries the nested result, so the answer that comes back is the child's real answer, not its first "delegated" line.
Models
Model choice is layered, Claude-style:
forceModel— one model for every Subagent- the role the parent passes to
task agentModels[<agent>]model:in the agent fileagentModels["*"]- otherwise inherit the parent's model
inherit is a keyword at any layer and stops the search. A role the parent invents is ignored with a warning; a bad model from your config fails the Task before launch, naming the layer.
{
"models": { "fast": "provider/cheap-model", "deep": "provider/strong-model" },
"agentModels": { "Explore": "fast", "general-purpose": "deep" },
"budget": { "maxTokensPerTask": 200000 }
}
budget.maxTokensPerTask stops a runaway Subagent and delivers what it produced, with the reason.
Configuration
Optional. pi-attach reads the first of:
$PI_ATTACH_CONFIG~/.pi/agent/pi-attach.jsonconfig.jsoninside the package (development)
| Key | Default | Meaning |
|---|---|---|
key | ctrl+shift+a | Shortcut that focuses the Agent List |
concurrency | 4 | Running Tasks at once; the rest queue |
maxRows | 8 | Agent List rows before +N more |
messageMode | steer | queue delivers a message after the current work |
animation | { frames: ["●"], intervalMs: 1000 } | One frame means a static glyph |
glyphs | ◌ ✓ ✗ ■ | Per-state glyphs, for icon fonts |
models | {} | Named model roles |
agentModels | {} | Role or model per agent; "*" is the default |
forceModel | unset | Role or id forced onto every Subagent |
budget.maxTokensPerTask | unset | Stop a Task that spends more than this |
agentLimits | {} | Per-agent limits that beat the agent file; "*" is the default |
worktree.enabled | true | Kill switch for worktree isolation |
worktree.cleanup | when-clean | when-clean, always (commit leftovers, reclaim) or never |
worktree.dir | ~/.pi/agent/worktrees | Where checkouts are created |
nesting.maxDepth | 1 | How deep Subagents may delegate; 1 withholds task from Subagents |
transport | pty | pty runs a real interactive child; rpc reconstructs its events in Pi |
handoff | true | With transport: "pty", Enter hands the terminal to the child |
transport: "pty" is the default. It needs the optional node-pty,
@xterm/headless and @xterm/addon-serialize packages. It starts each
Subagent as a real pi TUI on a pseudo-terminal; Enter suspends Pi and gives
the child the terminal, and Ctrl-] gives it back while the child keeps
running. If those packages are missing, or Pi is not in its interactive TUI,
Tasks run over RPC instead, with the child's events reconstructed as a Pi
transcript. transport: "rpc" forces that fallback and needs no native module.
Fullscreen TUI mode is the tested path; the mirrored screen does not cover
images, IME cursor placement or scrollback.
A finished PTY Task's Enter instead reopens its saved session as a fresh
pi --session <file> TUI. That viewer is a view, not a second Task: it is
closed before Pi resumes, and the original Task can then be resumed normally.
If the original child is still shutting down, the view waits for it rather than
opening a second writer on the same session file.
Keys
| Key | Where | Effect |
|---|---|---|
↓ on an empty editor | Agent List | Focus the list |
↑ ↓ | Agent List | Move the selection |
Enter | Agent List | View the selected Task, or main |
x | Agent List | Stop the selected Task |
Esc | Agent List | Leave the list |
Enter | Subagent view | Steer, queue, or resume with the text |
Ctrl-] | PTY handoff | Give the terminal back to Pi; a live child keeps running, a finished viewer closes |
Esc | Subagent view | Back to the parent, nothing stopped |
ctrl+o | everywhere | Expand tool output, prompts and results |
Documentation
- docs/ui.md — the full UI contract
- docs/agents.md — agent definitions, model roles, budget
- docs/adr/ — the decisions, including two reversals this work forced
- GLOSSARY.md — the language used above
Development
npm install
npm test # unit and boundary tests
npm run test:tui # drives real Pi in a PTY: /agents, attach, Ctrl+O, Esc
PI_SUBAGENTS_LIVE=1 node --test test/live-rpc.test.ts # one real child, costs a model call
Known limits
- The view swap depends on Pi's internal layout. It validates before touching anything, restores exactly what it replaced, and refuses with a warning otherwise — that code lives in one module and is covered by the real-TUI probe.
- PTY handoff only exists in Pi's interactive TUI; RPC and print parents use the reconstructed transcript.
- The footer always describes the parent session; a child's usage is printed inside its own transcript.
- Mouse support (click, hover, wheel) is implemented and hit-tested, but has not been observed end to end in this environment.
License
MIT