Skip to content

Conversation

@dandye
Copy link
Collaborator

@dandye dandye commented Aug 15, 2025

Summary

This PR introduces a comprehensive subagent management system for Gemini CLI, enabling parallel execution of multiple Gemini instances through tmux session orchestration.

Features

Core Commands

  • spawn: Create new Gemini subagents in detached tmux sessions with configurable models and initial prompts
  • send: Send messages to running subagents with intelligent handling for:
    • Regular text prompts (uses literal mode to prevent shell interpretation)
    • Shell commands (prefixed with !, executed immediately)
    • Slash commands (/help, /model, etc.)
  • get-output: Retrieve subagent output with configurable line limits or full history
  • list: View all active subagent sessions in simple or detailed format
  • kill: Cleanly terminate subagent sessions
  • attach: Provides instructions for interactive session attachment
  • status: Debug and monitor subagent health and activity

Advanced Commands

  • spawn-split: Create subagents in split panes for side-by-side operation
  • broadcast: Send messages to multiple subagents simultaneously

Technical Implementation

  • Uses tmux sessions to maintain persistent Gemini instances that survive main process exits
  • Starts bash shell first, then launches Gemini to ensure session stability
  • Implements 5-second initialization delay to accommodate Gemini startup sequence (banner, MCP loading, etc.)
  • Intelligent message routing based on content prefix detection (! for commands, plain text for prompts)
  • Uses tmux send-keys with -l flag for literal text to prevent unintended shell interpretation
  • Handles Gemini's interactive input model (requires double Enter for prompt submission)

Use Cases

  • Parallel research tasks with specialized agents
  • Distributed analysis workflows
  • Long-running background monitoring
  • Multi-agent coordination for complex tasks
  • Side-by-side comparison of different model outputs

Testing

All commands have been tested with:

  • Basic prompt sending and response retrieval
  • Shell command execution
  • Multiple concurrent subagents
  • Session persistence and cleanup

Example Usage

# Create a test subagent
/subagent spawn --name=test1 --prompt="Hello\! I am a test agent. Please tell me about yourself."

# Check its status
/subagent status --name=test1

# List all subagents
/subagent list

# Get the initial output
/subagent get-output --name=test1

# Send a follow-up message
/subagent send --name=test1 --message="What are your capabilities?"

# Wait a moment, then get output again
/subagent get-output --name=test1 --lines=30

# Send another message
/subagent send --name=test1 --message="Can you write a haiku about tmux?"

# Get all output
/subagent get-output --name=test1 --all=true

# Create a second subagent with a different model
/subagent spawn --name=test2 --prompt="You are a code reviewer. Say hello\!" --model=sonnet

# List all subagents with details
/subagent list --format=detailed

# Broadcast to both
/subagent broadcast --names="test1,test2" --message="What time is it?"

# Clean up
/subagent kill --name=test1
/subagent kill --name=test2

Manual tmux verification

# See all tmux sessions
tmux list-sessions

# Attach to view a subagent live
tmux attach-session -t test1

# Detach with Ctrl+B, then D

Implements a comprehensive tmux-based subagent orchestration system that enables
running multiple Gemini instances in parallel for complex workflows.

Key features:
- spawn: Create new Gemini subagents in detached tmux sessions
- send: Send messages to running subagents with intelligent handling of:
  - Regular prompts (literal text with double Enter submission)
  - Shell commands (starting with !, single Enter execution)
  - Slash commands (/help, /model, etc.)
- get-output: Retrieve subagent output with configurable line limits
- list: View all active subagent sessions with simple or detailed format
- kill: Terminate subagent sessions cleanly
- attach: Instructions for interactive session viewing
- status: Debug and monitor subagent health
- spawn-split: Create subagents in split panes
- broadcast: Send messages to multiple subagents simultaneously

Technical implementation:
- Uses tmux sessions to maintain persistent Gemini instances
- Starts bash shell first, then launches Gemini to ensure session stability
- 5-second initialization delay to allow Gemini startup sequence
- Intelligent message routing based on content prefix detection
- Literal text mode (-l flag) for regular prompts to prevent shell interpretation

This enables advanced use cases like parallel research tasks, distributed analysis,
and multi-agent coordination workflows.
@dandye dandye requested a review from a team August 15, 2025 20:03
@dandye dandye changed the base branch from main to gemini_slash_commands August 15, 2025 20:04
@dandye dandye marked this pull request as draft August 18, 2025 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant