claude-sub-agent
Skill3 starsChanged 3 months agoMITView on GitHub
Launch Claude Code CLI as a headless sub-agent in a tmux pane, monitor its stream-json JSONL output, and poll for completion. Use when delegating a well-defined coding task (bug fix, feature, refactor) to a Claude agent subprocess with live observability. Triggers include "run claude agent", "delegate to claude", "claude sub-agent", or any request to run claude headlessly and monitor it.
In this repository86 other files it gives its agents.
- AGENTS.mdAGENTS.md
- adrSkill
- adzic-bddSkill
- agent-md-refactorSkill
- agent-muxSkill
- agent-role-impersonatorSkill
- agilquest-reservationsSkill
- ai-text-humanizerSkill
- architecture-decision-recordsSkill
- ast-grepSkill
- atacSkill
- aws-cliSkill
- bart-adversarial-reviewerSkill
- bddSkill
- branch-doctorSkill
- c4-architectureSkill
- c4Skill
- codemap-config-setupSkill
- codemap-exploreSkill
- codemap-handoffSkill
- codemap-hub-safetySkill
- codemapSkill
- commitSkill
- copilot-sub-agentSkill
- daily-standupSkill
- daily-statusSkill
- debugSkill
- design-thinkingSkill
- doctorSkill
- docx-word-processorSkill
- farley-tddSkill
- forensicsSkill
- gemini-sub-agentSkill
- git-commit-formatterSkill
- git-forensicsSkill
- github-actions-permissionsSkill
- github-cliSkill
- git-repo-discoverySkill
- git-safety-guardrailsSkill
- harness-idpSkill
- humanizeSkill
- iteration-plannerSkill
- jira-issue-managerSkill
- justfile-assistantSkill
- kiro-sub-agentSkill
- lessons-learnedSkill
- lessonsSkill
- lisa-planning-agentSkill
- lovejoy-release-agentSkill
- lsp-code-analysisSkill
- macro-to-microSkill
- marge-product-agentSkill
- meeting-notesSkill
- mermaid-diagram-generatorSkill
- modern-cli-overridesSkill
- native-web-searchSkill
- obsidian-notetakerSkill
- outlook-headlessSkill
- pdf-document-processorSkill
- pi-sub-agentSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 190
Prompt mangled by shell quoting: Always use -p @/tmp/file.md — never inline long prompts.
- Very specific: line 192
Permission prompts blocking headless run: Ensure --dangerously-skip-permissions is set.
- Very specific: line 194
--baremissing CLAUDE.md context: If your repo's CLAUDE.md has important guardrails, omit --bare or use --append-system-prompt @CLAUDE.md … - Distinctive: line 196
Agent runs forever: Check if stuck in a retry loop:
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Claude Sub-Agent Skill
Launch claude as a headless sub-agent in a tmux pane with live JSONL monitoring. Depends on the tmux skill for pane interaction.
When to use
- Delegating a scoped task to Claude CLI running autonomously
- Parallel execution alongside other sub-agents (gemini-sub-agent, pi-sub-agent)
- Running Ralph or Bart loops where each iteration is a separate claude process
- Tasks where cost tracking (
total_cost_usd) per agent run matters
Output format
Claude CLI streams newline-delimited JSON via --output-format stream-json. Key event types:
| Type | Meaning |
system / subtype: init | Startup: session_id, model, tools list |
assistant | Model turn: message.content array with tool_use and text blocks |
user | Tool result: tool_use_result.content[].text |
result | Completion signal: subtype, is_error, total_cost_usd, duration_ms, num_turns |
Tool calls live inside assistant.message.content[] as {"type":"tool_use","name":"Bash","input":{"command":"..."}}.
Completion signal:
{"type":"result","subtype":"success","is_error":false,"total_cost_usd":0.039,"duration_ms":11300,"num_turns":2,"result":"..."}Non-interactive invocation
Lean / headless flags
claude \
--print \
--output-format stream-json \
--dangerously-skip-permissions \
--no-session-persistence \
-p @/tmp/task-prompt.md \
> /tmp/claude-output.jsonl 2>&1| Flag | Why |
--print | Non-interactive: process prompt and exit |
--output-format stream-json | JSONL stream for monitoring; completion signalled by "type":"result" |
--dangerously-skip-permissions | Auto-approve all tool calls — required for headless use in trusted sandboxes |
--no-session-persistence | Ephemeral — no session written to disk, no prior context loaded |
-p @file | Load prompt from file (avoids shell quoting issues) |
Additional useful flags:
--model sonnet/--model opus/--model haiku— model selection--system-prompt @file— replace system prompt (e.g. for persona injection)--append-system-prompt @file— append persona on top of default prompt--max-budget-usd 1.00— hard spending cap for the run--tools "Bash,Edit,Read,Write"— restrict available tools--bare— minimal mode: skip hooks, LSP, CLAUDE.md discovery, plugins (fastest cold start)
Bare mode (fastest, for simple tasks)
claude --print --output-format stream-json \
--dangerously-skip-permissions \
--no-session-persistence \
--bare \
-p @/tmp/task-prompt.md \
> /tmp/claude-output.jsonl 2>&1--bare skips CLAUDE.md auto-discovery, extensions, MCP, plugins, and keychain reads. Use when the worktree has no CLAUDE.md persona you need loaded.
Workflow
1. Write the task prompt to a file
cat > /tmp/task-prompt.md << 'EOF'
Your task description here.
EOF2. Identify a free tmux pane
bash {SKILLS_DIR}/tmux-remote-control/scripts/tmux-list.sh3. Launch claude + monitor in the pane
TARGET="{session}:{window}.{pane}"
tmux send-keys -t "$TARGET" \
"cd /path/to/repo && claude --print --output-format stream-json --dangerously-skip-permissions --no-session-persistence -p @/tmp/task-prompt.md > /tmp/claude-output.jsonl 2>&1 &" Enter
sleep 5
tmux send-keys -t "$TARGET" \
"python3 {SKILLS_DIR}/claude-sub-agent/scripts/monitor.py /tmp/claude-output.jsonl" Enter4. Poll for completion
python3 {SKILLS_DIR}/claude-sub-agent/scripts/poll.py "$TARGET" --interval 305. Verify results
tmux send-keys -t "$TARGET" C-c # kill monitor
git log --oneline -5
uv run pytest tests/ -x -q # or project test commandFull copy-paste pattern
cat > /tmp/task-prompt.md << 'EOF'
Your task here.
EOF
TARGET="{session}:{window}.{pane}"
tmux send-keys -t "$TARGET" \
"cd /path/to/repo && claude --print --output-format stream-json --dangerously-skip-permissions --no-session-persistence -p @/tmp/task-prompt.md > /tmp/claude-output.jsonl 2>&1 &" Enter
sleep 5
tmux send-keys -t "$TARGET" \
"python3 {SKILLS_DIR}/claude-sub-agent/scripts/monitor.py /tmp/claude-output.jsonl" Enter
python3 {SKILLS_DIR}/claude-sub-agent/scripts/poll.py "$TARGET" --interval 30
tmux send-keys -t "$TARGET" C-c
git log --oneline -5Agent / persona injection
# Append a persona on top of claude's default system prompt
claude --print --output-format stream-json \
--dangerously-skip-permissions --no-session-persistence \
--append-system-prompt @{SKILLS_DIR}/bart-adversarial-reviewer/references/bart.md \
-p @/tmp/task.md \
> /tmp/claude-output.jsonl 2>&1 &In tmux:
tmux send-keys -t "$TARGET" \
"cd /repo && claude --print --output-format stream-json --dangerously-skip-permissions --no-session-persistence --append-system-prompt @{SKILLS_DIR}/bart-adversarial-reviewer/references/bart.md -p @/tmp/task.md > /tmp/claude-output.jsonl 2>&1 &" EnterUnlike Gemini (which uses GEMINI.md), Claude supports --system-prompt and --append-system-prompt flags directly — no CWD file needed.
Model selection
claude --model haiku # fastest, cheapest (claude-haiku-4-5)
claude --model sonnet # balanced (claude-sonnet-4-6) — default
claude --model opus # most capable (claude-opus-4-5)Cost control
# Hard cap — agent stops if budget exceeded
claude --print --output-format stream-json \
--dangerously-skip-permissions \
--max-budget-usd 0.50 \
-p @/tmp/task.md \
> /tmp/claude-output.jsonl 2>&1Final cost is in the result line:
grep '"type":"result"' /tmp/claude-output.jsonl | python3 -c "
import json, sys
d = json.loads(sys.stdin.read())
print(f'Cost: \${d[\"total_cost_usd\"]:.4f} Duration: {d[\"duration_ms\"]/1000:.1f}s Turns: {d[\"num_turns\"]}')
"Troubleshooting
Prompt mangled by shell quoting: Always use -p @/tmp/file.md — never inline long prompts.
Permission prompts blocking headless run: Ensure --dangerously-skip-permissions is set. Without it, claude pauses for approval.
--bare missing CLAUDE.md context: If your repo's CLAUDE.md has important guardrails, omit --bare or use --append-system-prompt @CLAUDE.md explicitly.
Agent runs forever: Check if stuck in a retry loop:
tail -3 /tmp/claude-output.jsonl | python3 -c "import json,sys; [print(json.loads(l).get('type','?')) for l in sys.stdin]"Parse the result stats:
python3 -c "
import json
for line in open('/tmp/claude-output.jsonl'):
d = json.loads(line)
if d.get('type') == 'result':
print('Status:', d['subtype'], '| Error:', d['is_error'])
print('Cost: \$' + str(d['total_cost_usd']))
print('Duration:', d['duration_ms'] / 1000, 's')
print('Turns:', d['num_turns'])
"Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

