Spawn a single background agent for specific analysis
Spawn specialized background agents for continuous code analysis. Use for automated reviews, type checking, or finding silent failures while you work on other tasks.
/plugin marketplace add arevlo/claude-code-workflows/plugin install arevlo-swarm@claude-code-workflowsSpawn a single specialized agent to run analysis in the background.
/spawn <agent> [--watch <pattern>] [--once]
Arguments:
agent - Agent type (reviewer, simplifier, type-analyzer, silent-hunter, comment-analyzer, test-analyzer)--watch - File pattern to watch (default: src/**/*.ts)--once - Run once and exit (no watch mode)Validate agent type:
Initialize if needed:
bash/zsh (macOS, Linux, Git Bash, WSL):
mkdir -p .claude/swarm/{reports,issues,logs,pids,progress}
PowerShell (Windows):
$dirs = @('reports','issues','logs','pids','progress')
$dirs | ForEach-Object { New-Item -ItemType Directory -Force -Path ".claude/swarm/$_" }
Check for existing agent:
.claude/swarm/pids/<agent>.pidLoad agent instructions:
agents/<agent>.md in plugin directorySpawn agent:
bash/zsh (macOS, Linux, Git Bash, WSL):
# Watch mode (default)
nohup claude --agent <agent> \
--system "$(cat agents/<agent>.md)" \
--watch "<pattern>" \
--output ".claude/swarm/reports/<agent>-$(date +%s).md" \
--dangerously-skip-permissions \
> .claude/swarm/logs/<agent>.log 2>&1 &
echo $! > .claude/swarm/pids/<agent>.pid
# One-shot mode
claude --agent <agent> \
--system "$(cat agents/<agent>.md)" \
--path "src/" \
--output ".claude/swarm/reports/<agent>-$(date +%s).md" \
--dangerously-skip-permissions
PowerShell (Windows):
# Watch mode (default)
$timestamp = [int](Get-Date -UFormat %s)
$agentInstructions = Get-Content "agents/<agent>.md" -Raw
$process = Start-Process claude -ArgumentList @(
'--agent', '<agent>',
'--system', $agentInstructions,
'--watch', '<pattern>',
'--output', ".claude/swarm/reports/<agent>-$timestamp.md",
'--dangerously-skip-permissions'
) -RedirectStandardOutput ".claude/swarm/logs/<agent>.log" `
-RedirectStandardError ".claude/swarm/logs/<agent>-err.log" `
-PassThru -NoNewWindow
$process.Id | Out-File .claude/swarm/pids/<agent>.pid
# One-shot mode
$timestamp = [int](Get-Date -UFormat %s)
claude --agent <agent> `
--system (Get-Content "agents/<agent>.md" -Raw) `
--path "src/" `
--output ".claude/swarm/reports/<agent>-$timestamp.md" `
--dangerously-skip-permissions
Confirm spawn:
/hive for status| Agent | Focus | Output |
|---|---|---|
reviewer | Code quality, patterns, best practices | Issues + suggestions |
simplifier | Complexity reduction, DRY violations | Refactor suggestions |
type-analyzer | Type safety, inference issues | Type errors + fixes |
silent-hunter | Unhandled promises, silent failures | Critical async issues |
comment-analyzer | TODOs, FIXMEs, outdated comments | Documentation tasks |
test-analyzer | Coverage gaps, test quality | Test suggestions |
# Spawn code reviewer watching TypeScript files
/spawn reviewer --watch "src/**/*.ts"
# Run silent failure analysis once
/spawn silent-hunter --once
# Spawn type analyzer for specific directory
/spawn type-analyzer --watch "src/plugins/**/*.tsx"
Every spawned agent receives these instructions as part of their system prompt:
## Context Protocol
You have a finite context window. Follow these rules to work efficiently:
1. **Work efficiently** — Don't load unnecessary files. Read only what you need.
2. **Checkpoint at natural breakpoints** — If your task is complex, save progress to
`.claude/swarm/progress/{agent-name}-{timestamp}.md` before moving to the next subtask.
3. **Complete gracefully** — If you sense you're running long or approaching limits,
wrap up your current work and document next steps rather than getting cut off.
4. **Structured outputs** — Write findings to `.claude/swarm/reports/` in structured
markdown format. Use tables, bullet points, and clear sections.
5. **Limit file reads** — Summarize relevant code rather than copying entire files.
Reference file paths and line numbers instead of full content.
Checkpoint format:
Timestamp: {ISO timestamp} Task: {what you were analyzing}
{Key discoveries written to reports}
{What continuation should do}
This protocol is automatically injected when spawning agents.
.claude/swarm/reports/.claude/swarm/logs/<agent>.log