Divide and Conquer
Pick up a task and execute it by splitting the work into independent workstreams. Each workstream runs in its own subagent, in its own git worktree, on its own branch — subagents never touch the primary repo checkout. Parallelize only workstreams whose scopes don't overlap; serialize the rest.
Instructions
The user's query is in $ARGUMENTS (a task ID like 077 or a task name/keyword).
- Look up the task: Run
taskmd get $ARGUMENTS to find the task
- If not found, run
taskmd list to show available tasks and ask the user which one they meant
- Read the task file with the
Read tool to get the full description, subtasks, touches scopes, and acceptance criteria
- Mark the task as in-progress: Run
taskmd set <ID> --status in-progress
- Start a worklog entry (if worklogs are enabled):
- Check
.taskmd.yaml for worklogs: true -- worklogs are opt-in, so skip this step unless the key is explicitly set to true
- If enabled, find or create the worklog file at
tasks/<group>/.worklogs/<ID>.md (or tasks/.worklogs/<ID>.md for root tasks)
- Append a timestamped entry noting your approach and initial findings
- Determine the base branch:
- Default to the current local branch:
git rev-parse --abbrev-ref HEAD
- Use a different base only if the user explicitly asked for one
- All subagent branches are created off this base
- Plan workstreams and partition by scope:
- Use
EnterPlanMode to design the overall approach
- In the plan, include a reference to the original task ID and task file path
- Break the task into candidate workstreams — pieces of work that could proceed independently. Examples:
- Implementation code vs. tests vs. documentation
- Changes to separate packages or modules
- Backend changes vs. frontend changes
- Assign scopes to each workstream: list the abstract scopes (from the task's
touches field and the scopes map in .taskmd.yaml) plus the concrete file areas each workstream will modify. Resolve scope→path mappings with taskmd context <ID> when helpful.
- Detect overlap: build a scope→workstream map. Two workstreams that share a scope (or otherwise write the same files) must not run in parallel — they would produce merge conflicts.
- Group into batches:
- Workstreams with disjoint scopes go in the same parallel batch.
- Overlapping workstreams are serialized: pick an order, and have the later one branch off the earlier one's completed branch (not the base) so it builds on that work conflict-free.
- If the task is simple enough that a single workstream covers it, just do it directly (skip to step 9)
- Launch subagents — one worktree + branch each:
- Use the
Agent tool with isolation: "worktree" for every subagent that modifies files, so each gets an isolated worktree
- Launch all subagents in a parallel batch in a single message so they run concurrently; run serialized (overlapping) workstreams in later messages, after their predecessor finishes
- Give each subagent a self-contained prompt that includes:
- Exactly what to do, with relevant file paths and context
- Its assigned branch name (e.g.
dnc/<task-id>/<workstream-slug>) and its base branch (the task base, or a predecessor's branch for serialized work)
- These non-negotiable rules for the subagent:
- "Work only inside your own worktree (your cwd). Do not read-modify-write,
cd into, or otherwise touch the primary repo checkout at any other path."
- "Run any
taskmd command from your own worktree. Reads see the merged cross-worktree view (a task claimed in-progress in a sibling worktree is excluded from taskmd next), and writes are CLI-guarded: taskmd set refuses a task that exists only in a sibling worktree — if you hit that error, leave the task alone and report back instead of cd-ing to work around it."
- "First run
git checkout -b <assigned-branch> <base-branch> so all your commits land on your branch."
- "When done, commit your work to your branch with a clear message, then run all verification steps relevant to your changes (build, tests, lint — e.g.
make check) and fix anything that fails before committing the fix."
- "Report back: your branch name, final commit SHA, a summary of what changed, and the verification results (pass/fail with details)."
- Wait, then collect results:
- Wait for all subagents in the batch to complete before moving on
- Review each subagent's reported branch, commits, and verification status for correctness
- If a subagent failed or its verification did not pass, handle it directly (inspect its branch, fix, re-verify) rather than blindly re-launching
- Check off subtasks (
- [x]) in the task file as they are completed
- Append worklog entries for key decisions, blockers, and completed workstreams
- Write a final worklog entry summarizing what was done, which workstreams ran in parallel vs. serialized, the branches produced, decisions made, and any open items
- Ask the user how to finish — do not auto-commit to the base branch:
- Present a short summary: each workstream, its branch, commit SHA, and verification status
- Ask the user whether they want you to integrate the work now (merge the workstream branches into the base branch and mark the task done) or leave the branches in place for them to review and commit themselves
- Only if the user asks you to integrate:
- Merge each workstream branch into the base branch, resolving any conflicts, and run the full verification suite on the integrated result
- Then mark the task done per
.taskmd.yaml workflow:
- Solo workflow (default):
taskmd set <ID> --status completed --verify (the --verify flag runs the task's verification checks first; if it fails, fix and retry)
- PR-review workflow: open a PR, then
taskmd set <ID> --status in-review --add-pr <PR-URL> and stop
- If the user prefers to handle it themselves, leave the branches untouched and stop — do not merge or change task status
Worklog Format
Each worklog entry uses a timestamp heading followed by free-form notes:
## 2026-02-15T10:30:00Z
Started divide-and-conquer execution of the search feature task.
Base branch: `main`.
**Workstreams (scope-partitioned):**
Parallel batch (disjoint scopes):
1. Core search implementation — scope `cli/search` — branch `dnc/077/core` (worktree)
2. Documentation updates — scope `docs` — branch `dnc/077/docs` (worktree)
Serialized (shares `cli/search` with #1):
3. Search test suite — branch `dnc/077/tests`, based off `dnc/077/core`
**Results:**
- [x] All subagents committed to their branches; verification passed on each
- Branches ready for integration; awaiting user decision on merge
**Decisions:** Used full-text search with SQLite rather than Elasticsearch.
1---2name: divide-and-conquer3description: Pick up a task and execute it using subagents to parallelize independent workstreams. Use when the user wants to work on a task with maximum concurrency.4---56# Divide and Conquer78Pick up a task and execute it by splitting the work into independent workstreams. Each workstream runs in its **own subagent, in its own git worktree, on its own branch** — subagents never touch the primary repo checkout. Parallelize only workstreams whose scopes don't overlap; serialize the rest.910## Instructions1112The user's query is in `$ARGUMENTS` (a task ID like `077` or a task name/keyword).13141. **Look up the task**: Run `taskmd get $ARGUMENTS` to find the task15 - If not found, run `taskmd list` to show available tasks and ask the user which one they meant162. **Read the task file** with the `Read` tool to get the full description, subtasks, `touches` scopes, and acceptance criteria173. **Mark the task as in-progress**: Run `taskmd set <ID> --status in-progress`184. **Start a worklog entry** (if worklogs are enabled):19 - Check `.taskmd.yaml` for `worklogs: true` -- worklogs are opt-in, so skip this step unless the key is explicitly set to `true`20 - If enabled, find or create the worklog file at `tasks/<group>/.worklogs/<ID>.md` (or `tasks/.worklogs/<ID>.md` for root tasks)21 - Append a timestamped entry noting your approach and initial findings225. **Determine the base branch**:23 - Default to the **current local branch**: `git rev-parse --abbrev-ref HEAD`24 - Use a different base **only** if the user explicitly asked for one25 - All subagent branches are created off this base266. **Plan workstreams and partition by scope**:27 - Use `EnterPlanMode` to design the overall approach28 - In the plan, include a reference to the original task ID and task file path29 - Break the task into candidate **workstreams** — pieces of work that could proceed independently. Examples:30 - Implementation code vs. tests vs. documentation31 - Changes to separate packages or modules32 - Backend changes vs. frontend changes33 - **Assign scopes to each workstream**: list the abstract scopes (from the task's `touches` field and the `scopes` map in `.taskmd.yaml`) plus the concrete file areas each workstream will modify. Resolve scope→path mappings with `taskmd context <ID>` when helpful.34 - **Detect overlap**: build a scope→workstream map. Two workstreams that share a scope (or otherwise write the same files) **must not** run in parallel — they would produce merge conflicts.35 - **Group into batches**:36 - Workstreams with **disjoint** scopes go in the same parallel batch.37 - Overlapping workstreams are **serialized**: pick an order, and have the later one branch off the **earlier one's completed branch** (not the base) so it builds on that work conflict-free.38 - If the task is simple enough that a single workstream covers it, just do it directly (skip to step 9)397. **Launch subagents — one worktree + branch each**:40 - Use the `Agent` tool with `isolation: "worktree"` for **every** subagent that modifies files, so each gets an isolated worktree41 - Launch all subagents in a parallel batch in a **single message** so they run concurrently; run serialized (overlapping) workstreams in later messages, after their predecessor finishes42 - Give each subagent a self-contained prompt that includes:43 - Exactly what to do, with relevant file paths and context44 - Its **assigned branch name** (e.g. `dnc/<task-id>/<workstream-slug>`) and its **base branch** (the task base, or a predecessor's branch for serialized work)45 - These non-negotiable rules for the subagent:46 - "**Work only inside your own worktree** (your cwd). Do **not** read-modify-write, `cd` into, or otherwise touch the primary repo checkout at any other path."47 - "Run any `taskmd` command from your own worktree. Reads see the merged cross-worktree view (a task claimed `in-progress` in a sibling worktree is excluded from `taskmd next`), and writes are CLI-guarded: `taskmd set` refuses a task that exists only in a sibling worktree — if you hit that error, leave the task alone and report back instead of `cd`-ing to work around it."48 - "First run `git checkout -b <assigned-branch> <base-branch>` so all your commits land on your branch."49 - "When done, **commit your work** to your branch with a clear message, then **run all verification steps** relevant to your changes (build, tests, lint — e.g. `make check`) and fix anything that fails before committing the fix."50 - "Report back: your branch name, final commit SHA, a summary of what changed, and the verification results (pass/fail with details)."518. **Wait, then collect results**:52 - Wait for **all** subagents in the batch to complete before moving on53 - Review each subagent's reported branch, commits, and verification status for correctness54 - If a subagent failed or its verification did not pass, handle it directly (inspect its branch, fix, re-verify) rather than blindly re-launching55 - Check off subtasks (`- [x]`) in the task file as they are completed56 - Append worklog entries for key decisions, blockers, and completed workstreams579. **Write a final worklog entry** summarizing what was done, which workstreams ran in parallel vs. serialized, the branches produced, decisions made, and any open items5810. **Ask the user how to finish — do not auto-commit to the base branch**:59 - Present a short summary: each workstream, its branch, commit SHA, and verification status60 - **Ask the user** whether they want you to integrate the work now (merge the workstream branches into the base branch and mark the task done) **or** leave the branches in place for them to review and commit themselves61 - Only if the user asks you to integrate:62 - Merge each workstream branch into the base branch, resolving any conflicts, and run the full verification suite on the integrated result63 - Then mark the task done per `.taskmd.yaml` `workflow`:64 - **Solo workflow** (default): `taskmd set <ID> --status completed --verify` (the `--verify` flag runs the task's verification checks first; if it fails, fix and retry)65 - **PR-review workflow**: open a PR, then `taskmd set <ID> --status in-review --add-pr <PR-URL>` and stop66 - If the user prefers to handle it themselves, leave the branches untouched and stop — do not merge or change task status6768## Worklog Format6970Each worklog entry uses a timestamp heading followed by free-form notes:7172```markdown73## 2026-02-15T10:30:00Z7475Started divide-and-conquer execution of the search feature task.76Base branch: `main`.7778**Workstreams (scope-partitioned):**7980Parallel batch (disjoint scopes):811. Core search implementation — scope `cli/search` — branch `dnc/077/core` (worktree)822. Documentation updates — scope `docs` — branch `dnc/077/docs` (worktree)8384Serialized (shares `cli/search` with #1):853. Search test suite — branch `dnc/077/tests`, based off `dnc/077/core`8687**Results:**8889- [x] All subagents committed to their branches; verification passed on each90- Branches ready for integration; awaiting user decision on merge9192**Decisions:** Used full-text search with SQLite rather than Elasticsearch.93```