A bash wrapper that runs multiple Claude CLI instances in parallel, each looping continuously.
Make sure the script is executable and in your PATH:
chmod +x claude-while
# Option 1: symlink to a directory in PATH
ln -s "$(pwd)/claude-while" ~/.local/bin/claude-while
# Option 2: add the directory to PATH
export PATH="$PATH:$(pwd)"claude-while --instances N [--delay SECONDS] -- <claude args...>
| Option | Description |
|---|---|
--instances N or -n N |
Number of parallel Claude instances to run |
--delay SECONDS |
Seconds to wait between each worker's iterations (default: 0, or set via WHILECLAUDE_DELAY env var) |
-- |
Separator between claude-while options and claude arguments |
Everything after -- is passed directly to the claude CLI. If you forget -p, it will be added automatically.
Run 3 instances with a simple prompt:
claude-while --instances 3 -- -p "Find and fix TODO comments in the codebase"Run multiple agents working on related tasks, using a shared file to coordinate:
claude-while --instances 3 -- -p "Find something important related to this concern: we havent released in a week and have a lot of changes. I'm not sure how to get this released without having to do a major QA session. any bug fixes or improvements to recently created items would be good. I'm currently blocked by having to run migrations without db access in prod, the migrations are failing so we built a ux around it. lets really make it solid so the release goes well. There are multiple agents doing this. commit and push when done. update WHILE before you start, make sure not to do the same thing, then edit WHILE when you are done." --allowedTools "Read,Edit,Bash"Limit what tools Claude can use:
claude-while --instances 2 -- -p "Review code for security issues" --allowedTools "Read,Grep,Glob"Add a 5-second delay between each worker's runs:
claude-while --instances 2 --delay 5 -- -p "Monitor for changes and report"When running multiple agents on the same codebase, use a shared coordination file (e.g., WHILE) to prevent duplicate work:
- Each agent reads
WHILEat the start to see what others are doing - Agent updates
WHILEwith what it plans to work on - Agent does the work
- Agent updates
WHILEwhen finished
Example WHILE file content:
Agent 1: Working on fixing login validation - IN PROGRESS
Agent 2: Improving error messages in API - DONE
Agent 3: Adding tests for user service - IN PROGRESS
- Spawns N worker processes in parallel
- Each worker runs
claudewith the provided arguments - When a Claude instance exits, the worker immediately starts a new one
- Continues until you kill the process (Ctrl+C)
Press Ctrl+C to stop all workers. The script handles cleanup automatically.