pi-subagent-manager 1.10.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +9 -9
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.js +790 -0
  4. package/dist/orch/checklist-integration.js +176 -0
  5. package/dist/orch/context-entries.js +6 -0
  6. package/dist/orch/cost-ledger.js +38 -0
  7. package/dist/orch/diagnostics.js +86 -0
  8. package/dist/orch/extensions.js +66 -0
  9. package/dist/orch/housekeeping-usage.js +22 -0
  10. package/dist/orch/housekeeping.js +248 -0
  11. package/dist/orch/inherited-tools.js +57 -0
  12. package/dist/orch/mailbox.js +195 -0
  13. package/dist/orch/manager.js +970 -0
  14. package/dist/orch/paths.js +69 -0
  15. package/dist/orch/prompt.js +30 -0
  16. package/dist/orch/registry.js +115 -0
  17. package/dist/orch/runtime.js +835 -0
  18. package/dist/orch/tools.js +112 -0
  19. package/dist/orch/transcript.js +165 -0
  20. package/dist/prefs/agent-import.js +188 -0
  21. package/dist/prefs/config.js +878 -0
  22. package/dist/prefs/import-discovery.js +547 -0
  23. package/{src/prefs/import-instructions.ts → dist/prefs/import-instructions.js} +0 -1
  24. package/dist/prefs/models.js +56 -0
  25. package/dist/prefs/settings.js +491 -0
  26. package/dist/types.js +1 -0
  27. package/dist/ui/agent-loader.js +63 -0
  28. package/dist/ui/agent-navigation-editor.js +168 -0
  29. package/dist/ui/cost-footer.js +209 -0
  30. package/dist/ui/dialog.js +505 -0
  31. package/dist/ui/import-picker.js +191 -0
  32. package/dist/ui/live-agent-view.js +527 -0
  33. package/dist/ui/model-picker.js +529 -0
  34. package/dist/ui/settings-ui.js +671 -0
  35. package/dist/ui/status-ui.js +470 -0
  36. package/dist/ui/thread-tree.js +142 -0
  37. package/dist/ui/tool-picker.js +331 -0
  38. package/dist/ui/transcript-tool.js +91 -0
  39. package/dist/ui/ui.js +1019 -0
  40. package/package.json +17 -5
  41. package/docs/assets/subagent-manager-demo.gif +0 -0
  42. package/docs/async-lifecycle.md +0 -153
  43. package/docs/custom-agents.md +0 -154
  44. package/docs/default-agents.md +0 -95
  45. package/docs/demo.md +0 -63
  46. package/docs/development.md +0 -74
  47. package/docs/importing-agents.md +0 -41
  48. package/docs/pi-footer.md +0 -128
  49. package/docs/research-claude.md +0 -258
  50. package/docs/research-codex.md +0 -143
  51. package/docs/research-default-agent-models.md +0 -121
  52. package/docs/research-model-audit-2026-10.md +0 -154
  53. package/docs/research-model-roles-coding.md +0 -99
  54. package/docs/research-model-roles-writing.md +0 -78
  55. package/docs/research-researcher-workflow.md +0 -97
  56. package/docs/settings.md +0 -293
  57. package/docs/subagent-extension-limitations.md +0 -98
  58. package/docs/threads.md +0 -73
  59. package/docs/tools-and-ui.md +0 -129
  60. package/src/index.ts +0 -920
  61. package/src/orch/checklist-integration.ts +0 -230
  62. package/src/orch/context-entries.ts +0 -15
  63. package/src/orch/cost-ledger.ts +0 -56
  64. package/src/orch/diagnostics.ts +0 -95
  65. package/src/orch/extensions.ts +0 -83
  66. package/src/orch/housekeeping-usage.ts +0 -47
  67. package/src/orch/housekeeping.ts +0 -348
  68. package/src/orch/inherited-tools.ts +0 -84
  69. package/src/orch/mailbox.ts +0 -261
  70. package/src/orch/manager.ts +0 -1084
  71. package/src/orch/paths.ts +0 -73
  72. package/src/orch/prompt.ts +0 -39
  73. package/src/orch/registry.ts +0 -168
  74. package/src/orch/runtime.ts +0 -1041
  75. package/src/orch/tools.ts +0 -190
  76. package/src/orch/transcript.ts +0 -186
  77. package/src/prefs/agent-import.ts +0 -245
  78. package/src/prefs/config.ts +0 -1017
  79. package/src/prefs/import-discovery.ts +0 -643
  80. package/src/prefs/models.ts +0 -74
  81. package/src/prefs/settings.ts +0 -614
  82. package/src/types.ts +0 -271
  83. package/src/ui/agent-loader.ts +0 -98
  84. package/src/ui/agent-navigation-editor.ts +0 -233
  85. package/src/ui/cost-footer.ts +0 -230
  86. package/src/ui/dialog.ts +0 -678
  87. package/src/ui/import-picker.ts +0 -231
  88. package/src/ui/live-agent-view.ts +0 -600
  89. package/src/ui/model-picker.ts +0 -701
  90. package/src/ui/settings-ui.ts +0 -830
  91. package/src/ui/status-ui.ts +0 -628
  92. package/src/ui/thread-tree.ts +0 -173
  93. package/src/ui/tool-picker.ts +0 -398
  94. package/src/ui/transcript-tool.ts +0 -142
  95. package/src/ui/ui.ts +0 -1407
@@ -1,41 +0,0 @@
1
- # Importing agents
2
-
3
- Already have agents for another pi subagent package? Import them.
4
-
5
- ## How
6
-
7
- - **First run:** in an interactive TUI session, you're offered an import once. (Not in `off` or `orchestration` mode.)
8
- - **Any time:** `/agents import`.
9
-
10
- The checkbox picker starts with nothing selected.
11
-
12
- | Key | Action |
13
- | ------ | --------------------- |
14
- | ↑↓ | Navigate |
15
- | Space | Toggle row |
16
- | Ctrl+A | Toggle all |
17
- | Enter | Submit (empty = skip) |
18
- | Esc | Cancel |
19
-
20
- ## What happens
21
-
22
- Your **current main model** does the conversion, in your current conversation. There's no converter code and no separate agent.
23
-
24
- - It receives only the selected file paths, relevant source settings paths, the target schema, your scoped models and tools, and migration instructions.
25
- - It must explain and get your approval for anything lossy: unsupported features, dropped security restrictions, unavailable models, name collisions.
26
- - Originals are never modified.
27
- - New definitions load after the turn, or with `/agents reload`.
28
-
29
- Requires `opportunistic` mode (it uses the main thread's file tools). TUI only — RPC/print/JSON sessions never prompt.
30
-
31
- ## Where it looks
32
-
33
- Supported sources: [`@tintinweb/pi-subagents` 0.19.0](https://github.com/tintinweb/pi-subagents/blob/e955e29c51b7a6cce37e1108cd2d6c57a77e151c/src/custom-agents.ts) and [npm `pi-subagents` 0.74.0](https://github.com/nicobailon/pi-subagents/blob/b6bda32f03b7f549623bc404c9be14dca298ddc4/src/agents/agents.ts).
34
-
35
- - **User:** `<pi-agent-dir>/agents`; recursive `~/.agents` (npm).
36
- - **Project (trusted only):** `.pi/agents`, `.agents/agents` (tintinweb), recursive `.agents` (npm), including npm's nearest configured ancestor.
37
- - **Extra:** npm's `PI_SUBAGENT_EXTRA_AGENT_DIRS` and `settings.json` → `subagents.agentScanDirs` / `agentExcludeDirs`.
38
-
39
- Skipped: `skills`/`.skills` trees, any `SKILL.md`, symlinks, `.chain.md` workflows, installed-package builtins. npm's git-root anchoring isn't reproduced.
40
-
41
- The offer is remembered in `<pi-agent-dir>/subagent-manager/.import-offered`.
package/docs/pi-footer.md DELETED
@@ -1,128 +0,0 @@
1
- # Subagent dollar totals in pi-footer
2
-
3
- With `npm:pi-footer` loaded, choose one of the two integration paths below. Both
4
- show the selected **Display value**: settled subagent-only USD (default), or total
5
- main-session + settled-subagent USD. Keep pi-footer’s native cost widget if you
6
- want the main-session cost shown separately.
7
-
8
- The shared status key / event Widget ID is exactly **`subagent_cost`**. It is not
9
- `pi-subagent-manager`, an extension file path, or an npm package ID.
10
-
11
- ## Extension Status (recommended; default)
12
-
13
- 1. Open `/agents settings` → **Footer display** → **Location**, choose
14
- **pi-footer status widget**, return to settings, and save with **Ctrl+S**.
15
- 2. Open `/footer`, choose **Edit lines**, select a row, and add **Extension Status**.
16
- 3. Set **Status key** to **`subagent_cost`** and enable **Raw value only**.
17
- 4. Save the footer configuration.
18
-
19
- The corresponding subagent-manager setting is:
20
-
21
- ```json
22
- {
23
- "costDisplay": "pi-footer-status"
24
- }
25
- ```
26
-
27
- For a file-based footer setup, insert this widget object into an existing row
28
- array in `lines` in `~/.pi/agent/extensions/pi-footer.json`:
29
-
30
- ```json
31
- {
32
- "id": "subagent-cost-status",
33
- "type": "external-status",
34
- "enabled": true,
35
- "options": {
36
- "externalStatusKey": "subagent_cost",
37
- "raw": true,
38
- "hideWhenEmpty": true,
39
- "trimValue": 0
40
- }
41
- }
42
- ```
43
-
44
- Here `id` identifies the footer widget instance; **`externalStatusKey`** is the
45
- lookup key that must match the publisher. Do not put the package name in it.
46
- The manager already publishes the value using this API (no extra extension needed):
47
-
48
- ```typescript
49
- ctx.ui.setStatus("subagent_cost", "💵 $0.1234");
50
- ```
51
-
52
- It clears the status with `ctx.ui.setStatus("subagent_cost", undefined)`.
53
-
54
- ## Pi Event Value (alternative)
55
-
56
- 1. Open `/agents settings` → **Footer display** → **Location**, choose
57
- **pi-footer event**, return to settings, and save with **Ctrl+S**.
58
- 2. In `/footer`, add a **Pi Event Value** widget to the desired row.
59
- 3. Enter **Widget ID** as **`subagent_cost`** manually, replacing the generated ID,
60
- and enable **Raw value only**. Event IDs do **not** appear in the status-key selector.
61
- 4. Save the footer configuration.
62
-
63
- The corresponding subagent-manager setting is:
64
-
65
- ```json
66
- {
67
- "costDisplay": "pi-footer-event"
68
- }
69
- ```
70
-
71
- Insert this widget object into an existing row array in the footer's `lines`:
72
-
73
- ```json
74
- {
75
- "id": "subagent-cost-event",
76
- "type": "event",
77
- "enabled": true,
78
- "options": {
79
- "widgetId": "subagent_cost",
80
- "raw": true,
81
- "hideWhenEmpty": true
82
- }
83
- }
84
- ```
85
-
86
- The manager already emits the following event; no custom publisher is required.
87
- This is the exact event name and payload shape, with an illustrative dollar value:
88
-
89
- ```typescript
90
- pi.events.emit("pi-footer:update-widget", {
91
- widgetId: "subagent_cost",
92
- value: "💵 $0.1234",
93
- });
94
- ```
95
-
96
- To clear the event value, the manager emits:
97
-
98
- ```typescript
99
- pi.events.emit("pi-footer:update-widget", {
100
- widgetId: "subagent_cost",
101
- value: null,
102
- });
103
- ```
104
-
105
- ## File locations and refresh behavior
106
-
107
- - Merge `costDisplay`, `costValue`, and `costIcon` settings into
108
- `~/.pi/agent/subagent-manager/settings.json`, or the trusted-project override
109
- `.pi/agent/subagent-manager/settings.json`. Preserve your other settings.
110
- - Footer widget snippets are **objects inside a row**, not complete configuration
111
- files: the structure is `"lines": [[widgetObject, otherWidgetObject]]`. Preserve
112
- existing rows and widgets. `PI_FOOTER_CONFIG` can override the footer file path.
113
- - After manual file edits, use Pi's `/reload` to reload extensions and settings.
114
- Using the settings dialogs applies changes immediately when saved.
115
- - Choose only the widget matching your selected mode. Switching modes clears the
116
- old output; shutdown clears the published value too.
117
- - `$0.0000` appears at session start/reload and immediately on subagent startup.
118
- Running costs settle on completion, pause, stop, or failure; they remain in
119
- agent rows until then. Nested agents are counted once, and accounting survives
120
- resume and reaping. The selected money, coins, or wallet icon prefixes the
121
- dollar value: emoji with Nerd Font icons off, or a Nerd Font glyph with it on.
122
- - If the status key is missing, check that the manager is loaded and the location
123
- is **pi-footer status widget**, not **pi-footer event**. **Replace Pi status**
124
- uses the same status key but includes a Subagents/Total label. All locations
125
- support either display value; choose **Only subagent cost** for a subtotal.
126
-
127
- See [Cost display settings](settings.md#labs-cost-display-costdisplay) for all modes
128
- and fallback behavior when pi-footer is not loaded.
@@ -1,258 +0,0 @@
1
- # Claude Code subagents / Agent SDK research
2
-
3
- _Research only. No implementation done._
4
-
5
- ## Bottom line
6
-
7
- - **Use file-based `.claude/agents/*.md` definitions if we need the full subagent feature surface** (`hooks`, `isolation: worktree`, `omitClaudeMd`, color, experimental cache TTL). **Programmatic SDK `AgentDefinition` is a subset**, and the Python SDK is the smallest subset. ([subagents docs](https://code.claude.com/docs/en/sub-agents), [TS SDK ref](https://code.claude.com/docs/en/agent-sdk/typescript), [Python SDK ref](https://code.claude.com/docs/en/agent-sdk/python), [Python source](https://github.com/anthropics/claude-agent-sdk-python/blob/main/src/claude_agent_sdk/types.py))
8
- - **Capability restriction is `tools` + `disallowedTools`.** In SDK session options, **`allowedTools` / `allowed_tools` only auto-approve permissions; they do not restrict availability**. ([TS SDK ref](https://code.claude.com/docs/en/agent-sdk/typescript), [permissions guide](https://code.claude.com/docs/en/agent-sdk/permissions))
9
- - **Subagents are context-isolated by default**: fresh conversation, own system prompt, own context window, separate tool loop. They do **not** inherit the parent conversation history/tool results/auto memory/output style. ([subagents docs](https://code.claude.com/docs/en/sub-agents), [SDK subagents](https://code.claude.com/docs/en/agent-sdk/subagents))
10
- - **Background is the default** in SDK/programmatic subagent use, and resume is a first-class concept; if we need live steering/interrupts/status handling, the streaming/client APIs matter more than one-shot `query()`. ([SDK subagents](https://code.claude.com/docs/en/agent-sdk/subagents), [SDK sessions](https://code.claude.com/docs/en/agent-sdk/sessions), [Python source `query.py`](https://github.com/anthropics/claude-agent-sdk-python/blob/main/src/claude_agent_sdk/query.py), [Python source `client.py`](https://github.com/anthropics/claude-agent-sdk-python/blob/main/src/claude_agent_sdk/client.py))
11
-
12
- ## 1) File-based frontmatter: supported fields
13
-
14
- For custom subagent markdown files, the documented frontmatter fields are:
15
-
16
- - **Required:** `name`, `description`
17
- - **Optional:** `tools`, `disallowedTools`, `model`, `permissionMode`, `maxTurns`, `skills`, `mcpServers`, `hooks`, `memory`, `background`, `omitClaudeMd`, `effort`, `isolation`, `color`, `initialPrompt`, `experimental` (`cacheTtl` inside it)
18
-
19
- Important config rules:
20
-
21
- - **Exact camelCase matters** (`disallowedTools`, `maxTurns`, etc.).
22
- - **Unknown fields are silently ignored**.
23
- - `background: true` forces background execution.
24
- - `isolation: worktree` is the documented file-based isolation mode.
25
- - `omitClaudeMd: true` skips user/project/local `CLAUDE.md` loading for that subagent.
26
-
27
- Source: [Create custom subagents](https://code.claude.com/docs/en/sub-agents)
28
-
29
- ## 2) SDK parity vs file-based frontmatter
30
-
31
- ### TypeScript `AgentDefinition` (documented)
32
-
33
- Programmatic subagents in the TS Agent SDK support:
34
-
35
- - `description`, `prompt`
36
- - `tools`, `disallowedTools`
37
- - `model`
38
- - `skills`, `memory`, `mcpServers`
39
- - `initialPrompt`, `maxTurns`
40
- - `background`, `omitClaudeMd`
41
- - `effort`, `permissionMode`
42
- - `criticalSystemReminder_EXPERIMENTAL`
43
-
44
- Source: [TS SDK reference](https://code.claude.com/docs/en/agent-sdk/typescript), [SDK subagents](https://code.claude.com/docs/en/agent-sdk/subagents)
45
-
46
- ### Python `AgentDefinition` (documented + source-confirmed)
47
-
48
- Current Python `AgentDefinition` supports:
49
-
50
- - `description`, `prompt`
51
- - `tools`, `disallowedTools`
52
- - `model`
53
- - `skills`, `memory`, `mcpServers`
54
- - `initialPrompt`, `maxTurns`
55
- - `background`, `effort`, `permissionMode`
56
-
57
- Notably, the current Python implementation **does not define** `omitClaudeMd`, `hooks`, or `isolation` on `AgentDefinition`. That matches the narrower Python docs surface.
58
-
59
- Sources: [Python SDK reference](https://code.claude.com/docs/en/agent-sdk/python), [Python source `types.py`](https://github.com/anthropics/claude-agent-sdk-python/blob/main/src/claude_agent_sdk/types.py)
60
-
61
- ### Practical implication
62
-
63
- If Pi needs per-agent `worktree` isolation, per-agent hooks, or full frontmatter parity, **do not assume programmatic `AgentDefinition` is enough**; the file-based subagent path is richer.
64
-
65
- ## 3) Tool allow/block semantics
66
-
67
- ### File-based / programmatic subagent capability shaping
68
-
69
- - `tools` = **actual allowlist of tools present in the subagent session**.
70
- - If `tools` is omitted, the subagent **inherits every tool available to subagents**.
71
- - `disallowedTools` removes tools from the inherited/specified set.
72
- - If a tool is left out, it is **not present at all** — no prompt, no fallback.
73
-
74
- Sources: [Create custom subagents](https://code.claude.com/docs/en/sub-agents), [SDK subagents](https://code.claude.com/docs/en/agent-sdk/subagents)
75
-
76
- ### Do not confuse with SDK `allowedTools` / `allowed_tools`
77
-
78
- - SDK `allowedTools` / `allowed_tools` are **permission auto-approval** lists.
79
- - The docs are explicit: **“This does not restrict Claude to only these tools.”**
80
- - Use `disallowedTools` to block tools at the session level; use subagent `tools` / `disallowedTools` to shape a subagent’s tool inventory.
81
-
82
- Sources: [TS SDK reference](https://code.claude.com/docs/en/agent-sdk/typescript), [permissions guide](https://code.claude.com/docs/en/agent-sdk/permissions)
83
-
84
- ### Universal subagent removals
85
-
86
- The subagent docs say these are removed from **every** subagent, even if listed in `tools`:
87
-
88
- - `AskUserQuestion`
89
- - `EndConversation`
90
- - `EnterPlanMode`
91
- - `ScheduleWakeup`
92
- - `WaitForMcpServers`
93
- - `Workflow`
94
-
95
- Conditionals:
96
-
97
- - `ExitPlanMode` is removed unless the subagent `permissionMode` is `plan`
98
- - `Agent` is removed at the depth limit
99
-
100
- Source: [Create custom subagents](https://code.claude.com/docs/en/sub-agents)
101
-
102
- ### Foreground vs background tool surface
103
-
104
- By default subagents inherit built-in + MCP tools from the main conversation, then Claude Code applies filters. The docs explicitly say **background subagents keep every MCP tool but only a reduced built-in set**:
105
-
106
- `Read`, `Grep`, `Glob`, `LSP`, `Bash`, `PowerShell`, `Edit`, `Write`, `NotebookEdit`, `WebFetch`, `WebSearch`, `TodoWrite`, `Skill`, `ToolSearch`, `EnterWorktree`, `ExitWorktree`, `Monitor`, `TaskStop`, `SendMessage`, `Artifact` (plus `SubagentHandback` when applicable).
107
-
108
- So the **same subagent definition can resolve to a different tool set in foreground vs background**.
109
-
110
- Source: [Create custom subagents](https://code.claude.com/docs/en/sub-agents)
111
-
112
- ## 4) Context inheritance and isolation
113
-
114
- ### What a non-fork subagent gets at startup
115
-
116
- The docs say a non-fork subagent starts fresh, but not empty. It gets:
117
-
118
- - its **own system prompt** plus environment details
119
- - the **delegation/task message**
120
- - **`CLAUDE.md` files** (unless `omitClaudeMd`, and Explore/Plan skip them)
121
- - a **git status snapshot** (Explore/Plan skip it)
122
- - **preloaded skills** from the `skills` field
123
- - a **sibling roster** reminder when `SendMessage` is available and other named agents exist
124
-
125
- Sources: [Create custom subagents](https://code.claude.com/docs/en/sub-agents), [SDK subagents](https://code.claude.com/docs/en/agent-sdk/subagents)
126
-
127
- ### What it does **not** inherit
128
-
129
- The docs explicitly say the subagent does **not** get:
130
-
131
- - the parent **conversation history**
132
- - the parent’s already-invoked **skills**
133
- - the files Claude already **read**
134
- - the parent **system prompt**
135
- - the parent’s **auto memory**
136
- - the parent’s **output style**
137
- - the parent’s **context-window size** (the subagent’s model controls that)
138
-
139
- Also: **skills do not inherit from the parent conversation**; if we want startup preload, we must list them in `skills`.
140
-
141
- Sources: [Create custom subagents](https://code.claude.com/docs/en/sub-agents), [SDK subagents](https://code.claude.com/docs/en/agent-sdk/subagents)
142
-
143
- ### Working directory / isolation
144
-
145
- - Subagents start in the parent session’s current working directory.
146
- - `cd` inside Bash/PowerShell tool calls does not persist between calls.
147
- - File-based agents can use `isolation: worktree` for a temporary git worktree.
148
- - **Programmatic SDK AgentDefinition does not document per-agent `cwd`, `additionalDirectories`, or `isolation`.** Those controls are session-level, not per-agent.
149
-
150
- Sources: [Create custom subagents](https://code.claude.com/docs/en/sub-agents), [TS SDK reference](https://code.claude.com/docs/en/agent-sdk/typescript), [Python SDK reference](https://code.claude.com/docs/en/agent-sdk/python)
151
-
152
- ## 5) Foreground/background lifecycle
153
-
154
- ### Defaults and launch behavior
155
-
156
- - In SDK subagents, **background is the default**.
157
- - If an `Agent` tool call omits `run_in_background`, it launches a background subagent.
158
- - Claude sets `run_in_background: false` when it needs the result before continuing.
159
- - `background: true` forces background execution even when Claude wants the result.
160
-
161
- Sources: [SDK subagents](https://code.claude.com/docs/en/agent-sdk/subagents), [Create custom subagents](https://code.claude.com/docs/en/sub-agents)
162
-
163
- ### Foreground behavior
164
-
165
- - Foreground subagents **block the main conversation until complete**.
166
- - Permission prompts are passed through to the user.
167
-
168
- Source: [Create custom subagents](https://code.claude.com/docs/en/sub-agents)
169
-
170
- ### Background behavior
171
-
172
- - Background subagents run concurrently while the main conversation continues.
173
- - If a background subagent hits a permissioned tool call, Claude Code surfaces the prompt in the main session and names the subagent.
174
- - `Esc` denies just that one tool call without stopping the subagent.
175
- - Longer-lived permission grants apply to the **whole session**, including the main conversation.
176
- - Results come back later as a **completion notification**; if asked early, Claude reports the subagent is still running.
177
-
178
- Source: [Create custom subagents](https://code.claude.com/docs/en/sub-agents)
179
-
180
- ## 6) Steering, resume, stop/pause, status
181
-
182
- ### Steering
183
-
184
- Documented steering controls:
185
-
186
- - When fork mode is off, ask Claude to run a task in the **foreground** or **background**.
187
- - Press **`Ctrl+B`** to background a running task.
188
-
189
- Source: [Create custom subagents](https://code.claude.com/docs/en/sub-agents)
190
-
191
- ### Resume semantics
192
-
193
- - Each subagent invocation is a **new instance** unless explicitly resumed.
194
- - A resumed subagent retains **full conversation history, tool calls, results, and reasoning**.
195
- - A completed subagent resumes **in the background** without a new `Agent` invocation.
196
- - A resumed run keeps the **tool set from the first run**.
197
- - Built-in **Explore** and **Plan** are **one-shot** and return no agent ID, so they **cannot be resumed**.
198
-
199
- Source: [Create custom subagents](https://code.claude.com/docs/en/sub-agents)
200
-
201
- ### Session-level continue / resume / fork
202
-
203
- SDK session semantics:
204
-
205
- - `continue` / `continue_conversation=True` = resume the **most recent** session in the current directory
206
- - `resume` = resume a **specific** `session_id`
207
- - `fork` = create a **new** session with a copy of an existing session’s history
208
- - `session_id` is returned on result messages
209
-
210
- Source: [SDK sessions](https://code.claude.com/docs/en/agent-sdk/sessions)
211
-
212
- ### Status / monitoring surfaces
213
-
214
- If Pi needs runtime observability, the official surfaces are:
215
-
216
- - **SDK message stream**: background tasks (including subagents) emit `TaskStartedMessage`, `TaskProgressMessage`, and `TaskNotificationMessage` (`completed` / `failed` / `stopped`). ([Python SDK ref](https://code.claude.com/docs/en/agent-sdk/python))
217
- - **Agent view CLI**: `claude agents --json` exposes session `state` = `working | blocked | done | failed | stopped`, live `status` = `busy | waiting | idle`, and `waitingFor` = `permission prompt | input needed | sandbox request | worker request | dialog open`. ([agent view](https://code.claude.com/docs/en/agent-view))
218
-
219
- ### Stop / pause behavior
220
-
221
- - The Python streaming client exposes `interrupt()` and `stop_task(task_id)`; one-shot `query()` explicitly says **no interrupts / no follow-up messages**. ([Python source `client.py`](https://github.com/anthropics/claude-agent-sdk-python/blob/main/src/claude_agent_sdk/client.py), [Python source `query.py`](https://github.com/anthropics/claude-agent-sdk-python/blob/main/src/claude_agent_sdk/query.py))
222
- - I found **no dedicated documented “pause subagent” API**. The documented controls are **background**, **stop**, and **resume**.
223
- - If the user explicitly stops a subagent, it **does not auto-resume**; while its row is still present, the user can resume it from its transcript.
224
-
225
- Sources: [Create custom subagents](https://code.claude.com/docs/en/sub-agents), [agent view](https://code.claude.com/docs/en/agent-view)
226
-
227
- ### Backgrounding a foreground session with active subagents
228
-
229
- This is the closest thing to a “pause” semantic in the docs, and it matters:
230
-
231
- - When backgrounding a foreground session, Claude Code tries to wait for running foreground subagents so work can carry over.
232
- - If the user forces immediate backgrounding, **running subagents restart from the beginning** and previously spent tokens are spent again.
233
- - Some work (for example active monitors) cannot carry over and is stopped.
234
-
235
- Source: [agent view](https://code.claude.com/docs/en/agent-view)
236
-
237
- ## 7) Unsupported features / assumptions to avoid
238
-
239
- - **Do not assume unknown frontmatter keys fail loudly.** The docs say they are silently ignored.
240
- - **Do not assume `allowedTools` means capability restriction.** It is permission pre-approval, not tool removal.
241
- - **Do not assume subagents can ask the user clarifying questions themselves.** `AskUserQuestion` is removed from every subagent.
242
- - **Do not assume parent memory/style/history carry over.** Auto memory, output style, prior reads, and prior tool results do not.
243
- - **Do not assume programmatic SDK agents can express all markdown-frontmatter features.** File-based config is richer, especially for `hooks` and `isolation`; Python is narrower still.
244
- - **Do not assume a generic pause primitive exists.** The documented controls are backgrounding, stop, resume, and workflow/session-level carry-over behavior.
245
- - **Do not assume per-agent filesystem scoping exists in the SDK.** No documented per-agent `cwd`, `additionalDirectories`, or `isolation` field exists in SDK `AgentDefinition`.
246
-
247
- ## Primary sources
248
-
249
- - Claude Code subagents: https://code.claude.com/docs/en/sub-agents
250
- - Agent SDK subagents: https://code.claude.com/docs/en/agent-sdk/subagents
251
- - Agent SDK sessions: https://code.claude.com/docs/en/agent-sdk/sessions
252
- - Agent SDK permissions: https://code.claude.com/docs/en/agent-sdk/permissions
253
- - Agent view / background sessions: https://code.claude.com/docs/en/agent-view
254
- - TypeScript SDK reference: https://code.claude.com/docs/en/agent-sdk/typescript
255
- - Python SDK reference: https://code.claude.com/docs/en/agent-sdk/python
256
- - Python SDK source (`AgentDefinition`): https://github.com/anthropics/claude-agent-sdk-python/blob/main/src/claude_agent_sdk/types.py
257
- - Python SDK source (`query()`): https://github.com/anthropics/claude-agent-sdk-python/blob/main/src/claude_agent_sdk/query.py
258
- - Python SDK source (`ClaudeSDKClient`): https://github.com/anthropics/claude-agent-sdk-python/blob/main/src/claude_agent_sdk/client.py
@@ -1,143 +0,0 @@
1
- # Technical Research: OpenAI Codex subagents / multi-agent lifecycle
2
-
3
- ## Summary
4
- Current upstream Codex has **two distinct subagent tool surfaces**. **MultiAgent V1** matches the classic lifecycle you asked about (`spawn_agent` → `send_input` → `wait_agent` → `close_agent` / `resume_agent`), but it is centered on **thread IDs**. **MultiAgent V2** matches the **hierarchical `/root/...` path model** you want, but it changes the lifecycle to `spawn_agent` → `send_message` / `followup_task` → `wait_agent` → `interrupt_agent`, with **no model-facing `close_agent` or `resume_agent`**. This means your desired combination of **path hierarchy + V1 lifecycle verbs** is **not a single upstream interface today**; it is a custom requirement built from parts that upstream currently splits across V1 and V2. [Docs](https://developers.openai.com/codex/subagents) [V1/V2 source](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_spec.rs)
5
-
6
- ## Key Code Examples & APIs
7
-
8
- ### Surface comparison
9
-
10
- | Concern | Upstream V1 | Upstream V2 |
11
- | --- | --- | --- |
12
- | Spawn result | `agent_id` + optional nickname | canonical `task_name` (+ optional nickname) |
13
- | Primary targeting | thread id | hierarchical task path |
14
- | Send more work | `send_input` | `send_message` or `followup_task` |
15
- | Wait semantics | explicit target wait for final statuses | mailbox-activity wait, not target-specific |
16
- | Stop/close | `close_agent` | `interrupt_agent` |
17
- | Reopen | `resume_agent` | no model-facing resume |
18
-
19
- Sources: [tool spec](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_spec.rs), [V1 handlers](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents.rs), [V2 handlers](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_v2.rs)
20
-
21
- ### V1 lifecycle shape
22
- ```json
23
- {
24
- "tool": "multi_agent_v1.spawn_agent",
25
- "arguments": { "message": "Investigate X", "fork_context": false }
26
- }
27
- ```
28
- ```json
29
- {
30
- "tool": "multi_agent_v1.send_input",
31
- "arguments": { "target": "<agent_id>", "message": "Continue", "interrupt": false }
32
- }
33
- ```
34
- ```json
35
- {
36
- "tool": "multi_agent_v1.wait_agent",
37
- "arguments": { "targets": ["<agent_id>"], "timeout_ms": 30000 }
38
- }
39
- ```
40
- ```json
41
- { "tool": "multi_agent_v1.close_agent", "arguments": { "target": "<agent_id>" } }
42
- ```
43
- ```json
44
- { "tool": "multi_agent_v1.resume_agent", "arguments": { "id": "<agent_id>" } }
45
- ```
46
- Sources: [spec](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_spec.rs), [spawn](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents/spawn.rs), [send_input](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents/send_input.rs), [wait](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents/wait.rs), [close](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents/close_agent.rs), [resume](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents/resume_agent.rs)
47
-
48
- ### V2 lifecycle shape
49
- ```json
50
- {
51
- "tool": "spawn_agent",
52
- "arguments": {
53
- "task_name": "researcher",
54
- "message": "Investigate X",
55
- "fork_turns": "none"
56
- }
57
- }
58
- ```
59
- ```json
60
- {
61
- "tool": "send_message",
62
- "arguments": { "target": "researcher", "message": "One more angle" }
63
- }
64
- ```
65
- ```json
66
- {
67
- "tool": "followup_task",
68
- "arguments": { "target": "/root/researcher", "message": "Now verify Y" }
69
- }
70
- ```
71
- ```json
72
- { "tool": "wait_agent", "arguments": { "timeout_ms": 30000 } }
73
- ```
74
- ```json
75
- { "tool": "interrupt_agent", "arguments": { "target": "/root/researcher" } }
76
- ```
77
- Sources: [spec](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_spec.rs), [spawn](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_v2/spawn.rs), [message flow](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_v2/message_tool.rs), [wait](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_v2/wait.rs), [interrupt](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_v2/interrupt_agent.rs)
78
-
79
- ### Path hierarchy
80
- - Root agent path is `/root`.
81
- - If the current agent is `/root/task1` and it spawns `task_3`, upstream V2 makes the child `/root/task1/task_3`.
82
- - That child can be referred to locally as `task_3` or canonically as `/root/task1/task_3`.
83
- - A sibling branch like `/root/task2/task_3` does **not** get that shorthand; it must use the canonical path.
84
-
85
- Sources: [spawn tool description](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_spec.rs), [path construction](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_common.rs)
86
-
87
- ### Custom agent files
88
- ```toml
89
- # .codex/agents/reviewer.toml
90
- name = "reviewer"
91
- description = "PR reviewer focused on correctness, security, and missing tests."
92
- model = "gpt-6.1-sol"
93
- model_reasoning_effort = "medium"
94
- sandbox_mode = "read-only"
95
- developer_instructions = """
96
- Review code like an owner.
97
- Prioritize correctness, security, behavior regressions, and missing test coverage.
98
- """
99
- ```
100
- Source: [official subagents docs](https://developers.openai.com/codex/subagents)
101
-
102
- ## Findings
103
- 1. **The public Codex docs are conceptual; the source is required for exact tool semantics.** Official docs say current local Codex clients support subagent workflows by default, surface subagent activity in the desktop app / CLI / IDE, and support custom agents in `~/.codex/agents/` or `.codex/agents/`. But the docs do **not** spell out the exact model-facing tool API; the current open-source implementation does. [Docs](https://developers.openai.com/codex/subagents)
104
-
105
- 2. **Upstream currently ships two different multi-agent APIs, not one.** V1 exposes namespaced tools `multi_agent_v1.spawn_agent`, `send_input`, `resume_agent`, `wait_agent`, and `close_agent`. V2 exposes `spawn_agent`, `send_message`, `followup_task`, `wait_agent`, `interrupt_agent`, and `list_agents`. So `send_input` / `resume_agent` / `close_agent` are **V1 concepts**, while hierarchical task paths are a **V2 concept**. [Tool spec](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_spec.rs) [V1 module](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents.rs) [V2 module](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_v2.rs)
106
-
107
- 3. **The exact lifecycle you asked for exists upstream only in V1.** In V1, `spawn_agent` returns an `agent_id`; `send_input` targets that id and can queue or interrupt; `wait_agent` waits on explicit target ids and returns final statuses; `close_agent` shuts down the target and descendants; `resume_agent` reopens a closed agent by id. [spawn](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents/spawn.rs) [send_input](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents/send_input.rs) [wait](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents/wait.rs) [close](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents/close_agent.rs) [resume](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents/resume_agent.rs)
108
-
109
- 4. **V2 replaces that lifecycle with path-based messaging and runtime-managed reuse.** `send_message` queues text without triggering a turn; `followup_task` sends text and triggers a turn; `interrupt_agent` interrupts the current turn but explicitly keeps the agent reusable; `list_agents` enumerates live agents in the current root tree. There is **no model-facing `close_agent` or `resume_agent` in V2**, so load/unload/resume are runtime concerns, not agent tools. [spec](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_spec.rs) [message flow](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_v2/message_tool.rs) [followup_task](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_v2/followup_task.rs) [interrupt](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_v2/interrupt_agent.rs) [list_agents](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_v2/list_agents.rs)
110
-
111
- 5. **V2 path behavior already matches most of the hierarchy you want.** Upstream V2 constructs a canonical child path by taking the caller’s current agent path (or `/root`) and appending `task_name`. That means `/a/b` spawning `c` yields `/a/b/c`, and `/k/l` is a different subtree. The tool description explicitly says a child can be referred to by local shorthand (`task_3`) or canonical path, but a sibling subtree must use the canonical path. This confirms hierarchical naming, not unconditional history inheritance: V2 separately controls history with `fork_turns`. Pi-subagent will make the lexical-parent snapshot rule explicit and will not inherit from an unrelated caller. [path construction](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_common.rs) [spawn description](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_spec.rs)
112
-
113
- 6. **Important distinction: upstream separates `task_name` from role selection.** In V2, `task_name` is the path label segment, so `task_name = "researcher"` can produce `/root/researcher`. But the actual role/model/instructions come from `agent_type` and/or a custom agent file, not from `task_name` itself. That means “`/root/researcher`” is a valid upstream path label, but it does **not** automatically mean “spawn the `researcher` custom agent” unless role selection is also configured and exposed. [spawn args/spec](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_v2/spawn.rs) [official custom-agent docs](https://developers.openai.com/codex/subagents)
114
-
115
- 7. **Context inheritance is explicit and different between V1 and V2.** V1 has `fork_context: bool`; `true` forks the current thread history, `false` starts from only the delegated prompt. V2 has `fork_turns`, which accepts `none`, `all`, or a positive integer string like `"3"`; in current source, omitted `fork_turns` defaults to `all`. So V2 supports fresh children, full-history forks, and partial-history forks. [V1 spec](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_spec.rs) [V2 spawn parser](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_v2/spawn.rs)
116
-
117
- 8. **Child config inheritance is parent-first, then layered overrides.** The source builds a child config from the parent’s effective config and live turn state, then applies requested model/reasoning overrides, then optional role/custom-agent config, then reapplies runtime-only overrides such as approval policy, permission profile, and cwd. Official docs match this: custom agents can define `model`, `model_reasoning_effort`, `sandbox_mode`, `mcp_servers`, and `skills.config`, while omitted values inherit from the parent/default resolution chain. [child config source](https://github.com/openai/codex/blob/main/codex-rs/core/src/agent/child_config.rs) [docs](https://developers.openai.com/codex/subagents)
118
-
119
- 9. **Officially documented agent config covers the key knobs you asked about.** `agents.enabled` defaults to `true`; `agents.max_concurrent_threads_per_session` caps spawned threads; `agents.max_threads` is a legacy alias; `agents.default_subagent_model` and `agents.default_subagent_reasoning_effort` provide defaults; `agents.interrupt_message` controls whether interruption is recorded into model-visible context. Custom agent files require `name`, `description`, and `developer_instructions`. [config reference summary](https://developers.openai.com/codex/config-file/config-reference) [subagents docs](https://developers.openai.com/codex/subagents)
120
-
121
- 10. **`wait_agent` is materially different across versions, and this matters for any implementation that wants parity.** V1 `wait_agent` takes explicit `targets` and waits for final statuses, returning per-target status objects. V2 `wait_agent` takes only an optional timeout and waits for **mailbox activity or steered input**, returning a brief message plus `timed_out`; it is **not** a target-specific join/barrier API. [V1 wait](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents/wait.rs) [V2 wait](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_v2/wait.rs) [spec text](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_spec.rs)
122
-
123
- 11. **The current CLI/TUI explicitly surfaces subagent state and path-based activity.** Public docs say activity is visible in the app/CLI/IDE; current TUI code renders Started / Interacted / Interrupted / Completed activity rows, shows a `/subagents` picker, and surfaces states such as Pending init, Running, Interrupted, Completed, Error, Shutdown, and Not found. [docs](https://developers.openai.com/codex/subagents) [TUI source](https://github.com/openai/codex/blob/main/codex-rs/tui/src/multi_agents.rs)
124
-
125
- 12. **Bottom line: your requested design partly matches upstream and partly extends it.** Hierarchical naming matches upstream V2; Pi-subagent’s mandatory lexical-parent snapshot rule is a custom constraint (upstream controls forks separately). The classic `send_input` / `resume_agent` / `close_agent` lifecycle is upstream V1 behavior. A system that wants **both together** would be implementing a **custom Pi surface**, not copying one current Codex surface verbatim. [V1/V2 spec](https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_spec.rs)
126
-
127
- ## Sources
128
- - Kept: OpenAI Codex Subagents docs (<https://developers.openai.com/codex/subagents>) — official product-level behavior, inheritance, custom agent schema, and UI claims.
129
- - Kept: OpenAI Codex config reference (<https://developers.openai.com/codex/config-file/config-reference>) — official `[agents]` settings and defaults/aliases.
130
- - Kept: `multi_agents_spec.rs` (<https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_spec.rs>) — authoritative model-facing tool schema for V1 and V2.
131
- - Kept: V1 handler sources (`multi_agents/*.rs`) — authoritative lifecycle behavior for `send_input`, `resume_agent`, `wait_agent`, `close_agent`.
132
- - Kept: V2 handler sources (`multi_agents_v2/*.rs`) — authoritative lifecycle behavior for `spawn_agent`, `send_message`, `followup_task`, `wait_agent`, `interrupt_agent`, `list_agents`.
133
- - Kept: `child_config.rs` (<https://github.com/openai/codex/blob/main/codex-rs/core/src/agent/child_config.rs>) — authoritative config inheritance / override logic.
134
- - Kept: `multi_agents_common.rs` (<https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_common.rs>) — authoritative path construction for child agents.
135
- - Kept: TUI source (`tui/src/multi_agents.rs`) — corroborates current user-visible status surfacing.
136
- - Dropped: GitHub issues discussing docs/runtime mismatch for custom agents — useful background, but secondary to current docs + source and not needed for the checked conclusions here.
137
- - Dropped: Community forum posts about subagent model selection — secondary and partially stale relative to current `main`.
138
- - Dropped: PR discussions where current `main` source already reflects the merged behavior — helpful history, but less authoritative than the resulting code.
139
-
140
- ## Gaps
141
- - I did **not** audit every app-server/generated wire schema; if implementation later depends on exact desktop/web protocol payloads, inspect `codex-rs/protocol/src/items.rs` and app-server type exports directly.
142
- - The public config docs I checked do **not** appear to document every V2-specific internal knob; where V2 behavior matters here, I relied on current source rather than public config docs.
143
- - If later implementation needs exact name-resolution rules for every V2 tool (not just the documented path behavior), inspect the current `AgentControl::resolve` path in upstream source before coding.