@@ -11,56 +11,81 @@ Spawns external CLI AIs (claude, cursor-agent, codex, gemini) as isolated sub-ag
1111## Resources
1212
1313- ** [ run_subagent.py] ( scripts/run_subagent.py ) ** - Main execution script
14- - ** [ cli-formats .md] ( references/cli-formats .md ) ** - CLI output format details
14+ - ** [ codex .md] ( references/codex .md ) ** - Codex-specific setup (permissions, timeout)
1515
16- ** Execution** : Run scripts using absolute path from this skill's directory with your environment's Python.
16+ ** Script Path** : Use absolute path ` {SKILL_DIR}/scripts/run_subagent.py ` where ` {SKILL_DIR} ` is the directory containing this SKILL.md file.
17+
18+ ## CLI-Specific Notes
19+
20+ Check the corresponding reference for your environment:
21+ - ** Codex** : Read [ references/codex.md] ( references/codex.md ) BEFORE first execution
1722
1823## Interpreting User Requests
1924
2025Extract parameters from user's natural language request:
2126
2227| Parameter | Source |
2328| -----------| --------|
24- | --agent | Agent name from user request (if not specified, use --list to show candidates and ask user ) |
29+ | --agent | Agent name from user request (see selection rules below ) |
2530| --prompt | Task instruction part (excluding agent specification) |
26- | --cwd | Current working directory |
31+ | --cwd | Current working directory (absolute path) |
32+
33+ ** Agent Selection Rules** (when user doesn't specify agent name):
34+ 1 . Run ` --list ` to get available agents
35+ 2 . ** 0 agents** : Inform user no agents available, show setup instructions (see [ Agent Definition Format] ( #agent-definition-format ) )
36+ 3 . ** 1 agent** : Auto-select without asking
37+ 4 . ** 2+ agents** : Show list with descriptions, ask user to choose
2738
2839** Example** :
2940"Run code-reviewer on src/"
3041→ ` --agent code-reviewer --prompt "Review src/" --cwd $(pwd) `
3142
3243## When to Use This Skill
3344
34- | Scenario | Use Sub-Agent | Reason |
35- | ----------| ---------------| --------|
36- | Complex multi-step task | ** Yes** | Isolated context prevents interference |
37- | Parallel investigation | ** Yes** | Multiple agents can run simultaneously |
38- | Task needs fresh context | ** Yes** | Sub-agent starts without conversation history |
39- | Specialized agent definition exists | ** Yes** | Leverage pre-defined expert prompts |
40- | Simple single-step task | No | Direct execution is faster |
41- | Task requires current conversation context | No | Sub-agent cannot access parent context |
45+ ** Use sub-agent when ANY of these apply:**
46+ - Complex multi-step task (isolated context prevents interference)
47+ - Parallel investigation (multiple agents can run simultaneously)
48+ - Task needs fresh context (sub-agent starts without conversation history)
49+ - Specialized agent definition exists (leverage pre-defined expert prompts)
50+
51+ ## Important: Permission and Timeout
52+
53+ This script executes external CLIs that require elevated permissions.
54+
55+ ** Before first execution:**
56+ 1 . Request elevated permissions via your CLI's tool parameters
57+ 2 . Set tool timeout to match ` --timeout ` argument (default: 600000ms)
58+
59+ ** For Codex CLI** (most common permission issues): See [ references/codex.md] ( references/codex.md ) for exact JSON parameter format.
4260
4361## Workflow
4462
63+ ### Step 0: Read CLI-Specific Setup (if applicable)
64+
65+ If you are running on Codex, read [ references/codex.md] ( references/codex.md ) first.
66+
4567### Step 1: List Available Agents
4668
4769** Always list agents first** to discover available definitions:
4870
4971``` bash
50- python scripts/run_subagent.py --list
72+ scripts/run_subagent.py --list
5173```
5274
5375Output:
5476``` json
5577{"agents" : [{"name" : " code-reviewer" , "description" : " Reviews code..." }], "agents_dir" : " /path/.agents" }
5678```
5779
58- ** If agents list is empty** : Agent definitions must be placed in ` {cwd}/.agents/ ` directory.
80+ ** If agents list is empty** :
81+ 1 . Create ` {cwd}/.agents/ ` directory
82+ 2 . Add agent definition file (see [ Agent Definition Format] ( #agent-definition-format ) )
83+ 3 . Re-run ` --list ` to verify
5984
6085### Step 2: Execute Agent
6186
6287``` bash
63- python scripts/run_subagent.py \
88+ scripts/run_subagent.py \
6489 --agent < name> \
6590 --prompt " <task>" \
6691 --cwd < absolute-path>
@@ -74,11 +99,22 @@ Parse JSON output and check `status` field:
7499{"result" : " ..." , "exit_code" : 0 , "status" : " success" , "cli" : " claude" }
75100```
76101
102+ ** By status:**
103+
77104| status | Meaning | Action |
78105| --------| ---------| --------|
79106| ` success ` | Task completed | Use ` result ` directly |
80107| ` partial ` | Timeout but has output | Review partial ` result ` , may need retry |
81- | ` error ` | Execution failed | Check ` error ` field, fix and retry |
108+ | ` error ` | Execution failed | Check ` error ` field and ` exit_code ` , fix and retry |
109+
110+ ** By exit_code** (when status is ` error ` ):
111+
112+ | exit_code | Meaning | Resolution |
113+ | -----------| ---------| ------------|
114+ | 0 | Success | - |
115+ | 124 | Timeout | Increase ` --timeout ` or simplify task |
116+ | 127 | CLI not found | Install required CLI (claude, codex, etc.) |
117+ | 1 | General error | Check ` error ` field in response |
82118
83119## Parameters
84120
@@ -88,7 +124,7 @@ Parse JSON output and check `status` field:
88124| ` --agent ` | Yes* | Agent definition name from --list |
89125| ` --prompt ` | Yes* | Task description to delegate |
90126| ` --cwd ` | Yes* | Working directory (absolute path) |
91- | ` --timeout ` | No | Timeout ms (default: 300000 ) |
127+ | ` --timeout ` | No | Timeout ms (default: 600000 ) |
92128| ` --cli ` | No | Force CLI: ` claude ` , ` cursor-agent ` , ` codex ` , ` gemini ` |
93129
94130* Required when not using --list
@@ -131,20 +167,11 @@ How results should be structured.
1311673 . Auto-detect caller environment
1321684 . Default: ` codex `
133169
134- ## Error Handling
135-
136- | exit_code | Meaning | Resolution |
137- | -----------| ---------| ------------|
138- | 0 | Success | - |
139- | 124 | Timeout | Increase ` --timeout ` or simplify task |
140- | 127 | CLI not found | Install required CLI (claude, codex, etc.) |
141- | 1 | General error | Check ` error ` field in response |
142-
143- ## Anti-patterns
170+ ## Common Mistakes
144171
145- | Anti-pattern | Problem | Correct Approach |
146- | -------------- | --------- | ------------- -----|
147- | Not listing agents first | Unknown agent name causes error | Always run ` --list ` first |
148- | Relative path for --cwd | Validation fails | Use absolute path |
149- | Ignoring status field | Missing errors | Always check status before using result |
172+ | Mistake | Result | Fix |
173+ | ---------| --------| -----|
174+ | Skip ` --list ` before execution | Agent not found error | Always run ` --list ` first |
175+ | Use relative path for ` --cwd ` | Validation fails | Use absolute path |
176+ | Ignore ` status ` field in response | Undetected errors | Always check ` status ` before using ` result ` |
150177| Very long prompts | May exceed CLI limits | Break into smaller tasks |
0 commit comments