Loading...
Loading...
Spawn Codex subagents via background shell to offload context-heavy work. Use for: deep research (3+ searches), codebase exploration (8+ files), multi-step workflows, exploratory tasks, long-running operations, documentation generation, or any other task where the intermediate steps will use large numbers of tokens.
npx skill4agent add am-will/codex-skills codex-subagent[TASK CONTEXT]
You are researching/analyzing [SPECIFIC TOPIC] in [LOCATION/CODEBASE/DOMAIN].
[OBJECTIVES]
Your goals:
1. [1st objective with specifics]
2. [2nd objective]
3. [3rd objective if needed]
[CONSTRAINTS]
- Focus on: [specific areas/files/sources]
- Prioritize: [what matters most]
- Ignore: [what to skip]
[OUTPUT FORMAT]
Return: [exactly what format parent needs]
[SUCCESS CRITERIA]
Complete when: [specific conditions met]codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check \
-m gpt-5.1-codex-mini -c 'model_reasoning_effort="medium"' \
"Search web for [TOPIC] and summarize findings"codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check `
-m gpt-5.1-codex-mini -c 'model_reasoning_effort="medium"' `
"Search web for [TOPIC] and summarize findings"codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check \
-m "$MODEL" -c "model_reasoning_effort=\"$REASONING\"" \
"Find auth files THEN analyze security patterns and propose improvements"codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check `
-m $MODEL -c "model_reasoning_effort=`"$REASONING`"" `
"Find auth files THEN analyze security patterns and propose improvements"Is task PURELY search/gather?
├─ YES: Any work after gathering?
│ ├─ NO → mini model
│ └─ YES → inherit parent
└─ NO → inherit parent# Get parent session settings (respects active profile; falls back to top-level)
# NOTE: codex-parent-settings.sh prints two lines; use mapfile to avoid empty REASONING.
mapfile -t _settings < <(scripts/codex-parent-settings.sh)
MODEL="${_settings[0]}"
REASONING="${_settings[1]}"
# Spawn subagent (inherit parent)
codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check \
-m "$MODEL" -c "model_reasoning_effort=\"$REASONING\"" \
"DETAILED_PROMPT_WITH_CONTEXT"
# Safer prompt construction (no backticks / command substitution)
PROMPT=$(cat <<'EOF'
[TASK CONTEXT]
You are analyzing /path/to/repo.
[OBJECTIVES]
1. Do X
2. Do Y
[OUTPUT FORMAT]
Return: path - purpose
EOF
)
codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check \
-m "$MODEL" -c "model_reasoning_effort=\"$REASONING\"" \
"$PROMPT"
# Pure search (use mini)
codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check \
-m gpt-5.1-codex-mini -c 'model_reasoning_effort="medium"' \
"SEARCH_ONLY_PROMPT"
# JSON output for parsing
codex exec --dangerously-bypass-approvals-and-sandbox --json "PROMPT" | jq -r 'select(.event=="turn.completed") | .content'# Get parent session settings (respects active profile; falls back to top-level)
$scriptPath = Join-Path $env:USERPROFILE ".codex\skills\codex-subagent\scripts\codex-parent-settings.ps1"
$settings = & $scriptPath
$MODEL = $settings[0]
$REASONING = $settings[1]
# Spawn subagent (inherit parent)
codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check `
-m $MODEL -c "model_reasoning_effort=`"$REASONING`"" `
"DETAILED_PROMPT_WITH_CONTEXT"
# Use here-string for multi-line prompts (avoids escaping issues)
$PROMPT = @'
[TASK CONTEXT]
You are analyzing /path/to/repo.
[OBJECTIVES]
1. Do X
2. Do Y
[OUTPUT FORMAT]
Return: path - purpose
'@
codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check `
-m $MODEL -c "model_reasoning_effort=`"$REASONING`"" `
$PROMPT
# Pure search (use mini)
codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check `
-m gpt-5.1-codex-mini -c 'model_reasoning_effort="medium"' `
"SEARCH_ONLY_PROMPT"
# Method 1 (Recommended): Use -o to output directly to file
codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check `
-m $MODEL -c "model_reasoning_effort=`"$REASONING`"" `
-o output.txt "PROMPT"
$content = Get-Content -Path output.txt -Raw
# Method 2: Parse JSONL event stream
$jsonl = codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check --json "PROMPT"
$events = $jsonl -split "`n" | Where-Object { $_ } | ForEach-Object { $_ | ConvertFrom-Json }
$content = $events |
Where-Object -Property type -EQ "item.completed" |
Where-Object { $_.item.type -eq "agent_message" } |
Select-Object -ExpandProperty item |
Select-Object -ExpandProperty text# Research different topics simultaneously
codex exec --dangerously-bypass-approvals-and-sandbox -m "$MODEL" -c "model_reasoning_effort=\"$REASONING\"" "Research topic A..." &
codex exec --dangerously-bypass-approvals-and-sandbox -m "$MODEL" -c "model_reasoning_effort=\"$REASONING\"" "Research topic B..." &
wait-o# Parallel execution with file output
$job1 = Start-Job -ScriptBlock {
param($m, $r, $out)
codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check `
-m $m -c "model_reasoning_effort=`"$r`"" -o $out "Research topic A..."
} -ArgumentList $MODEL, $REASONING, "output1.txt"
$job2 = Start-Job -ScriptBlock {
param($m, $r, $out)
codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check `
-m $m -c "model_reasoning_effort=`"$r`"" -o $out "Research topic B..."
} -ArgumentList $MODEL, $REASONING, "output2.txt"
# Wait for all jobs to complete
$job1, $job2 | Wait-Job | Remove-Job
# Read results
$result1 = Get-Content -Path output1.txt -Raw
$result2 = Get-Content -Path output2.txt -Raw-o--output-last-messagecodex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check \
-m "$MODEL" -c "model_reasoning_effort=\"$REASONING\"" \
-o result.txt "YOUR_PROMPT"
content=$(cat result.txt)codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check `
-m $MODEL -c "model_reasoning_effort=`"$REASONING`"" `
-o result.txt "YOUR_PROMPT"
$content = Get-Content -Path result.txt -Raw--jsoncodex exec --dangerously-bypass-approvals-and-sandbox --json "PROMPT" | jq -r 'select(.event=="turn.completed") | .content'$jsonl = codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check --json "PROMPT"
$events = $jsonl -split "`n" | Where-Object { $_ } | ForEach-Object { $_ | ConvertFrom-Json }
$content = $events |
Where-Object -Property type -EQ "item.completed" |
Where-Object { $_.item.type -eq "agent_message" } |
Select-Object -ExpandProperty item |
Select-Object -ExpandProperty text{"type":"item.completed","item":{"id":"item_3","type":"agent_message","text":"..."}}
{"type":"turn.completed","usage":{"input_tokens":24763,"output_tokens":122}}type == "item.completed"item.type == "agent_message"item.texttype == "turn.completed"codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check \
-m gpt-5.1-codex-mini -c 'model_reasoning_effort="medium"' \
"Search for the latest release notes of Rust 2024 edition. Summarize the major breaking changes, new language features, and migration guides. Focus on the official rust-lang.org blog and documentation."codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check `
-m gpt-5.1-codex-mini -c 'model_reasoning_effort="medium"' `
"Search for the latest release notes of Rust 2024 edition. Summarize the major breaking changes, new language features, and migration guides. Focus on the official rust-lang.org blog and documentation."codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check \
-m "$MODEL" -c "model_reasoning_effort=\"$REASONING\"" \
"Analyze authentication in this Next.js app. Check /app, /lib/auth, middleware. Document: session strategy, auth provider, protected routes, security patterns. Return architecture diagram (mermaid) + findings."codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check `
-m $MODEL -c "model_reasoning_effort=`"$REASONING`"" `
"Analyze authentication in this Next.js app. Check /app, /lib/auth, middleware. Document: session strategy, auth provider, protected routes, security patterns. Return architecture diagram (mermaid) + findings."codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check \
-m "$MODEL" -c "model_reasoning_effort=\"$REASONING\"" \
"Research WebGPU browser adoption (support tables, benchmarks, frameworks). THEN analyze feasibility for our React app. Consider: performance gains, browser compatibility, implementation effort. Return recommendation with pros/cons."codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check `
-m $MODEL -c "model_reasoning_effort=`"$REASONING`"" `
"Research WebGPU browser adoption (support tables, benchmarks, frameworks). THEN analyze feasibility for our React app. Consider: performance gains, browser compatibility, implementation effort. Return recommendation with pros/cons."~/.codex/config.tomlmodel = "gpt-5.2-codex"
model_reasoning_effort = "high" # none | minimal | low | medium | high | xhigh
profile = "yolo" # optional; when set, profile values override top-level