gemini-sub-agent
Skill3 starsChanged 3 months agoMITView on GitHub
Launch Gemini 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 task to a Gemini agent subprocess with live observability. Triggers include "run gemini agent", "delegate to gemini", "gemini sub-agent", or any request to run gemini headlessly and monitor it.
- Reads credentials
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
- claude-sub-agentSkill
- 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
- 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
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 202
Prompt truncated by shell: Use cat /tmp/file | gemini ...
- Very specific: line 204
Stuck with no
resultline: Check if --yolo is set; without it, Gemini pauses for tool approval.
≈ “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
Gemini Sub-Agent Skill
Launch gemini 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 Gemini CLI running autonomously
- Parallel execution alongside other sub-agents (copilot-sub-agent, claude-sub-agent, pi-sub-agent)
- Tasks where Gemini's explicit exit codes (41–53) are useful for error handling in scripts
Output format
Gemini streams newline-delimited JSON via --output-format stream-json. Key event types:
init— startup, containssession_id,modelmessagewithrole: user— echoes the promptmessagewithrole: assistant,delta: true— streaming text chunksresult— final line, containsstatus,stats(tokens, duration_ms, tool_calls)
Completion signal: "type":"result" line in the stream.
{"type":"result","status":"success","stats":{"total_tokens":11386,"input_tokens":10774,"output_tokens":71,"cached":6250,"duration_ms":5815,"tool_calls":0}}Exit codes (unique to Gemini — use these in scripts):
0— success41— authentication error42— invalid input44— sandbox error52— configuration error53— turn limit exceeded
Non-interactive invocation
Lean / headless invocation
cat /tmp/task-prompt.md | gemini \
--yolo \
--output-format stream-json \
--model flash \
> /tmp/gemini-output.jsonl 2>&1What each flag does:
| Flag | Why |
--yolo | Auto-approve all tool calls — required for headless |
--output-format stream-json | JSONL stream for monitoring; completion signalled by "type":"result" line |
--model flash | Use flash (fast) instead of auto or pro — significantly faster for agentic tasks |
Gemini's startup footprint is controlled by what's in ~/.gemini/settings.json and GEMINI.md. There is no flag to suppress MCP loading — configure allowed-mcp-server-names with an empty list if you need to exclude all MCP servers:
cat /tmp/task-prompt.md | gemini \
--yolo \
--output-format stream-json \
--model flash \
--allowed-mcp-server-names "" \
> /tmp/gemini-output.jsonl 2>&1Gemini's baseline system prompt is ~10–11k tokens and is cached by default on warm runs. There are no flags to reduce this further — the lean knob is model selection (flash vs pro) and avoiding GEMINI.md bloat when injecting personas.
Other useful flags:
--model flash-lite— fastest/cheapest option--temperature 0— deterministic output for automation--timeout <ms>— execution timeout in milliseconds--include-directories /path— add workspace directories
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 gemini + monitor in the pane
TARGET="{session}:{window}.{pane}"
tmux send-keys -t "$TARGET" \
"cd /path/to/repo && cat /tmp/task-prompt.md | gemini --yolo --output-format stream-json > /tmp/gemini-output.jsonl 2>&1 &" Enter
sleep 3
tmux send-keys -t "$TARGET" \
"python3 {SKILLS_DIR}/gemini-sub-agent/scripts/monitor.py /tmp/gemini-output.jsonl" Enter4. Poll for completion
python3 {SKILLS_DIR}/gemini-sub-agent/scripts/poll.py "$TARGET" --interval 305. Check exit code and verify
tmux send-keys -t "$TARGET" C-c # kill monitor
# Extract exit code from result line
python3 -c "
import json
for line in open('/tmp/gemini-output.jsonl'):
d = json.loads(line.strip())
if d.get('type') == 'result':
print('Status:', d['status'])
print('Stats:', json.dumps(d['stats'], indent=2))
"
git log --oneline -5Full 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 && cat /tmp/task-prompt.md | gemini --yolo --output-format stream-json --model flash > /tmp/gemini-output.jsonl 2>&1 &" Enter
sleep 3
tmux send-keys -t "$TARGET" \
"python3 {SKILLS_DIR}/gemini-sub-agent/scripts/monitor.py /tmp/gemini-output.jsonl" Enter
python3 {SKILLS_DIR}/gemini-sub-agent/scripts/poll.py "$TARGET" --interval 30
tmux send-keys -t "$TARGET" C-c
git log --oneline -5Agent / persona injection
Gemini has no --system-prompt CLI flag. Persona injection works via GEMINI.md in the current working directory — Gemini automatically loads it as system context before any prompt.
# Write the persona to GEMINI.md in the working directory
cat {SKILLS_DIR}/bart-adversarial-reviewer/references/bart.md > /path/to/repo/GEMINI.md
# Run gemini from that directory — it will load GEMINI.md automatically
cd /path/to/repo
cat /tmp/task.md | gemini --yolo --output-format stream-json > /tmp/gemini-output.jsonl 2>&1
# Clean up after (or leave if you want the persona persistent)
rm /path/to/repo/GEMINI.mdThe GEMINI.md file is a plain markdown system prompt — no frontmatter required. Gemini loads it from $CWD/GEMINI.md (also checks ~/.gemini/GEMINI.md as a user-level default).
For headless sub-agent use, write the persona before launching:
cat > /path/to/repo/GEMINI.md << 'EOF'
You are Bart Simpson, adversarial reviewer. Find bugs. Be snarky.
EOF
tmux send-keys -t "$TARGET" \
"cd /path/to/repo && cat /tmp/task-prompt.md | gemini --yolo --output-format stream-json > /tmp/gemini-output.jsonl 2>&1 &" EnterModel selection
gemini "task" --model flash-lite --yolo # fastest, cheapest
gemini "task" --model flash --yolo # fast, balanced (default)
gemini "task" --model pro --yolo # most capableScript integration (using exit codes)
cat /tmp/task-prompt.md | gemini --yolo --output-format stream-json > /tmp/out.jsonl 2>&1
case $? in
0) echo "Success" ;;
41) echo "Auth error — check GEMINI_API_KEY" ; exit 1 ;;
42) echo "Invalid input" ; exit 1 ;;
52) echo "Config error" ; exit 1 ;;
53) echo "Turn limit exceeded" ; exit 1 ;;
*) echo "Unknown error $?" ; exit 1 ;;
esacTroubleshooting
Prompt truncated by shell: Use cat /tmp/file | gemini ... (stdin pipe) for long prompts.
Stuck with no result line: Check if --yolo is set; without it, Gemini pauses for tool approval.
tool_calls: 0 but task needed tools: Gemini may need --approval-mode yolo explicitly if --yolo alone doesn't propagate.
Parse the result stats:
grep '"type":"result"' /tmp/gemini-output.jsonl | python3 -c "import json,sys; d=json.loads(sys.stdin.read()); print(json.dumps(d['stats'], indent=2))"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.

