Spawn

Launch N parallel subagents in isolated git worktrees to compete on the session task

What Is Spawn?

The "Spawn" skill is a powerful development utility for Claude Code agent workflows that enables the launch of multiple parallel subagents, each operating in an isolated git worktree, to tackle the same session task concurrently. Designed for integration with the agenthub suite, Spawn lets you rapidly explore diverse approaches to a problem by running several isolated agent processes, each with its own strategy and git state.

This parallelization facilitates competitive problem-solving, iterative optimization, and robust solution discovery—critical for complex software engineering tasks where no single approach is guaranteed to be optimal. The Spawn command is invoked using /hub:spawn and supports a variety of arguments, including session targeting and agent prompt templates.

By isolating each subagent in its own git worktree, Spawn ensures that their changes are sandboxed, allowing for safe experimentation and head-to-head comparison of results.

Why Use Spawn?

Software development often involves ambiguous or open-ended tasks—such as optimization, bug fixing, refactoring, or test writing—where multiple solutions exist. Relying on a single agent or approach can lead to suboptimal results and missed opportunities for discovery. Spawn addresses this by:

  • Parallelizing Exploration: Multiple agents work on the same problem, each potentially using a different strategy, algorithm, or methodology.
  • Isolating Workspaces: Each agent works in a dedicated git worktree, preventing cross-contamination of changes and making it easy to compare and merge results.
  • Competitive Evaluation: By running agents in parallel, you can directly compare the quality, performance, or correctness of each approach before selecting the best outcome.
  • Accelerating Iteration: Diverse solution paths are explored simultaneously, reducing overall time to optimal solutions. Typical use cases for Spawn include performance optimization, code refactoring, test suite expansion, and competitive bug fixing.

How to Get Started

Getting started with Spawn requires a properly configured agenthub environment and a session task to work on. Below are the basic steps and example commands.

Basic Usage

To spawn agents for the latest session:

/hub:spawn

To spawn agents for a specific session (replace the session ID as appropriate):

/hub:spawn 20260317-143022

Using Templates Templates define distinct agent strategies, tailored to the task at hand.

To use a template, add the --template flag:

/hub:spawn --template optimizer

Available templates include optimizer, refactorer, test-writer, and bug-fixer. Each template applies a different workflow, as described below.

Example:

Competing Optimizers Suppose you want to optimize a function for performance.

You could run:

/hub:spawn --template optimizer

This will launch several agents, each using a unique optimization strategy (e.g., algorithmic refinement, caching, code inlining) in their own isolated git worktree.

Key Features Spawn offers several distinct features that enhance agent-driven development workflows:

  • Isolated Git Worktrees: Each agent operates in a separate git worktree, ensuring that changes are tracked and sandboxed.
  • Parallel Agent Execution: Launches N agents (configurable in your session) to work on the same problem in parallel.
  • Template-Driven Dispatch: Supports templates for common workflows—such as optimization, refactoring, test writing, and bug fixing—enabling agents to follow specialized, repeatable patterns.
  • Configurable Strategies: When using a template, each agent is assigned a distinct strategy, maximizing the diversity of explored solutions.
  • Session Awareness: Spawn can target the latest session or a specific session by ID, ensuring flexibility in managing ongoing or retrospective tasks.
  • Safe Experimentation: By isolating agent changes, you can safely test, compare, and merge only the most promising results.

Template Patterns | Template |

Pattern | Use Case | |---------------|-------------------------------------------|---------------------------| | optimizer | Edit → eval → keep/discard → repeat x10 | Performance, size, latency| | refactorer | Restructure → test → iterate until green | Code quality, tech debt | | test-writer | Write tests → measure coverage → repeat | Test coverage | | bug-fixer | Reproduce → diagnose → fix → verify | Bug fixing |

Best Practices

To maximize the effectiveness of Spawn, consider the following best practices:

  • Assign Diverse Strategies: When using templates, ensure each agent is dispatched with a unique, well-defined strategy. For example, one optimizer might focus on loop unrolling, while another explores memoization.
  • Limit Agent Count Appropriately: Launching too many agents can overwhelm system resources. Start with a manageable number and scale up as needed.
  • Review and Compare Outcomes: After agents complete their tasks, systematically review their worktrees, run tests, and benchmark results before merging the best changes.
  • Automate Evaluation: Where possible, script evaluation criteria (e.g., test coverage, benchmark scores) to objectively compare agent outputs.
  • Maintain Clean Worktrees: Regularly prune unused or obsolete worktrees to keep your repository organized and performant.

Important Notes - **Session

Configuration:** Spawn relies on the session configuration to parameterize agent promptsand strategies. Ensure your session YAML or configuration files are up-to-date and specify any required agent parameters, templates, or resource limits.

  • Resource Usage: Each spawned agent consumes CPU, memory, and disk space (for its worktree). Monitor system resources, especially when running many agents in parallel, to avoid performance degradation.
  • Git State: Spawned worktrees are isolated, but underlying repository issues (e.g., uncommitted changes, merge conflicts) can impact agent execution. Always start from a clean, stable base commit.
  • Security: Agents may execute arbitrary code depending on their prompts and templates. Review template definitions and agent permissions to mitigate risks, especially in shared or production environments.

By leveraging Spawn, you can systematically harness the creativity and efficiency of parallel agent workflows. This approach not only accelerates solution discovery but also raises the bar for code quality and innovation in your development process.