Execute batch operations on multiple files in parallel. Automatically discovers files, splits into chunks, and processes with parallel worker agents. Use `/batch` followed by operation and file pattern.
You are orchestrating a batch operation across multiple files. Your job is to:
First, parse the user's request to identify:
src/**/*.ts, **/*.js)If the user didn't specify a pattern, infer it from context or ask for clarification.
Use the glob tool to discover matching files.
If no files match the pattern:
Apply these common exclusions automatically:
node_modules/**dist/**build/**.git/****/*.test.ts, **/*.test.js**/*.spec.ts, **/*.spec.js**/__tests__/****/test/**, **/tests/****/package-lock.json**/yarn.lock**/*.min.jsImportant: If more than 50 files match, inform the user with the exact count and the file list, then proceed. The user can cancel (Ctrl+C) if needed. If the count exceeds 100 files, warn the user and suggest a more specific pattern instead of proceeding.
Split the discovered files into chunks based on these rules:
| Total Files | Chunk Count | Files Per Chunk |
|---|---|---|
| 1-5 | 1 | All files |
| 6-15 | 2 | 3-8 each |
| 16-30 | 3 | ~10 each |
| 31-50 | 4 | ~10-12 each |
| 51-75 | 5 | ~10-15 each |
| 76-100 | 5 | ~15-20 each |
Chunking algorithm:
Example: 24 files → 3 chunks of ~8 files each
Launch worker agents in parallel by invoking the task tool (the Agent tool) multiple times in a SINGLE message.
Note: The task tool in allowedTools is the Agent tool used to spawn worker agents.
Each worker agent should receive:
Use the general-purpose subagent type for workers.
CRITICAL: All Agent tool calls MUST be in a single response to enable parallel execution. The system automatically runs multiple Agent calls concurrently.
For each chunk, use this prompt format:
You are a worker agent processing a batch of files.
**Operation**: [describe the operation, e.g., "Add JSDoc comments to all exported functions"]
**Files to process**:
- [file1.ts]
- [file2.ts]
- ...
**Instructions**:
1. Process each file independently
2. For each file, report one of:
- SUCCESS: [file path] - [brief description of change]
- FAILED: [file path] - [reason for failure]
- SKIPPED: [file path] - [reason for skipping]
3. If a file fails or is skipped, continue with the next file - do not abort
4. At the end, provide a summary of what was done
**Constraints**:
- Do not modify test files unless explicitly requested
- Preserve existing code style and formatting
- Make minimal necessary changes to accomplish the operation
<Agent tool call 1>