Claude Code /batch runs hundreds of agents in Git worktrees

1 min read
claude-codeparallel-agentsorchestrationgit-worktrees
View as Markdown
Originally from tiktok.com
View source

My notes

Watch on TikTok Tap to open video

Summary

Claude Code has a built-in /batch slash command that orchestrates dozens to hundreds of background agent sessions in parallel for large, complex codebase changes. A lead session first researches the codebase to plan non-overlapping scoped subtasks and the contracts between them, then dispatches each subtask to its own full Claude Code session running in a separate Git worktree.

Key Insight

  • /batch is distinct from spawning a single subagent. It is built for fan-out at scale (dozens to hundreds of parallel sessions), not a handful of tasks.
  • The orchestration runs in two phases: a research and planning pass over the existing codebase that decomposes work into scoped subtasks and defines the “contracts” (interfaces and boundaries) between them so subtasks don’t collide, then dispatch, where each subtask runs as a full independent session in its own Git worktree.
  • Worktree isolation is the mechanism that lets that many agents touch the same repo concurrently without stepping on each other’s changes. Each session gets its own working copy, merged and validated at the end.
  • This is positioned as Claude Code’s answer to “dynamic workflows” style parallelization: the same idea of decompose, distribute, validate, but built into the CLI rather than hand-rolled.
  • Usage is trivial: /batch <instructions>. The planning and contract writing is handled automatically by the lead session, not specified manually by the user.
  • Best reserved for genuinely large, parallelizable refactors or codebase-wide changes, not for work that is naturally single-threaded or where subtasks share too much state to isolate cleanly. The contract definition between subtasks is the part most likely to need human review before trusting an unattended hundred-agent run.