# Parallel work

What can run in parallel, and how two agents work in two worktrees on one store.

## What can run in parallel

`tkt plan parallel SG-127 SG-159 [--json]` judges each pair: `serial` (a `blockedBy` path between them, transitive), `review` (a shared repo path or a shared risky pattern: `parallelRiskPaths`), `unknown` (one of them has no own repo refs: `no_repo_refs`, the overlap cannot be judged), else `parallel`. The worst pair wins (serial > review > unknown > parallel). Read-only, no AI; exit 0 all parallel, 1 a review, 2 a serial, 3 unknown, 4 could not run.

### Details

- `serial` paths run either way through any ticket. `review` compares each ticket's own `location: repo` refs (effective `repoAnchor.repo`) on whole segments (`src/api` contains `src/api/app.py`, not `src/apix`, not two files of one folder); no file read, no Stage 2. Patterns: `**/migrations/**`, `**/schema*` (`tkt config set parallelRiskPaths '["**/db/**"]'`); a shared path matching one is "higher risk".
- Info only: a shared epic (`same_parent`), milestone (`same_milestone`), group (`shared_group`) unless it is either ticket's primary group (`groups[0]`).
- A ticket without repo refs: its pairs are `unknown`, plus a note; judge the overlap yourself (shared groups, bodies, migrations).

- `tkt plan parallel --json`: `{pairs: [{a, b, verdict, reasons: [{kind, detail}]}], notes: [{ticket, message}]}`, `verdict`: `serial|review|unknown|parallel`, `kind`: `blocked_by|shared_path|risky_pattern|no_repo_refs|same_parent|same_milestone|shared_group`.

## Parallel worktrees

In a git repo every worktree shares one id counter (`$(git-common-dir)/aitodo/counters.json`) and one claim record (`$(git-common-dir)/aitodo/claims.json`): parallel worktrees never mint the same id or start the same ticket (one ticket, one worktree).

- `tkt worktree new` makes a branch and a worktree and claims the ticket there; `tkt worktree done SG-128 --remove` releases it and removes the clean worktree.
- `tkt ticket claims` shows who works on what, on which branch and worktree; `tkt ticket release --stale` clears the stale ones (`STALE_CLAIM`).

### Details

- **Counter:** keyed by store path; `.aitodo/counters.json` follows. Outside git or after `tkt config set sharedCounter false` each worktree counts alone. `tkt doctor` prints `counter: store` / `counter: git: <path>`.
- **Claims:** every worktree sees the record; rules: [Claiming and giving back](/en/docs/guides/loop/claim.md#loop-claim). A claim is stale when its worktree is not in `git worktree list`. Renumber and move keep it; outside git a claim is `in_progress` + assignee.
- **Live state:** a ticket claimed in another worktree shows its state there (status, AC, last note) next to the committed status in `tkt ticket get --brief`, `tkt tree`, `tkt milestone get` and `tkt ticket list`: `in_review (worktree feat/x)`. `tkt ticket get` (the Context Bundle) prints it in the header, `status: todo (live: in_review in worktree feat/x, 1/2 AC)` and a `live note`; its `--json` `live` field is `--brief`'s. It is read from the ticket file in the claim's worktree store, working copy (an uncommitted edit counts). Nothing is written. None for your own claim, a stale claim, equal state (e.g. after the merge), an unreadable file, outside git, `sharedCounter: false` or a server store (REST `view=brief`: always `null`). `tkt board` and `tkt graph` (every format) mark it too: a card stays in its committed column (the columns agree with the progress; unmerged work is not done) and the board says `N cards live in other worktrees`. `--watch` also redraws when a claim is made or released or a claimed ticket file there changes (`claims.json` and those files' mtime). Status filters use the committed status; `--live` (`tkt ticket list`, `tkt tree`, `tkt graph`) the live one.
- Refused, nothing created: already claimed (`ERR_ALREADY_CLAIMED`, checked first); not startable, or the ticket file missing at the base or (base `HEAD`) different from it ("commit the ticket first"): `ERR_NOT_STARTABLE`; git refuses (branch or dir exists, bad `--base`): `ERR_GIT_FAILED`. `worktree add`/`remove` stop after 120 s; half-done work is rolled back.
- **Setup:** `worktreeSetup` (e.g. `scripts/worktree.sh` + args, no shell) runs in the new worktree with `AITODO_TICKET`, `AITODO_WORKTREE`, `AITODO_WORKSPACE_DIR`, after `Setup: <command>`; a failure is a warning (exit 0, worktree kept). The hook's output goes to stderr.
- **`tkt worktree done SG-128 --remove --assignee X --force --json`:** releases like `tkt ticket release`, in the ticket's worktree (`todo` there); `done`/`canceled`: only `--remove`. `--remove` deletes a clean, non-main worktree (commit the claim's status edit too), else `ERR_WORKTREE_REFUSED` listing changes. The branch stays.

- **`tkt worktree new SG-128 slug --base REV --assignee X --no-setup --json`:** branch off `--base` (else `HEAD`) named `worktreeBranch` (else `feat/{id}-{slug}`), worktree at `worktreeDir` (default `../{repo}-{id}`, beside the main worktree; `{repo}` its dir name, `{id}` lower case, `{slug}` from the title, ASCII, `-`-joined, at most 40 characters); only these three; quote a template starting with `{` (YAML). It claims in the new store. A `--base` at another commit than `HEAD` judges the ticket as it is there (status and blockers in the new worktree); this tree's copy, even an uncommitted edit, does not count, and the refusal names the ref ("on main").

- Live state in JSON: `live: {status, acDone, acTotal, lastNote, branch, worktree}` or `null` next to the committed `status`; `tkt milestone get --json` and `tkt board --json` add `liveStatus` (count by status). No shared git-ignored overlay (rejected: every write would have to keep it in step, stale entries need a cleanup).
- `tkt ticket claims --json`: `{claims: [{id, ulid, assignee, branch, worktree, claimedAt, ageSeconds, here, stale}]}`.
- `tkt worktree new --json`: `{path, branch, ticket, base, store, setup: {command, exitCode, error} | null}`.
- `tkt worktree done --json`: `{path, branch, ticket, released, removed}`.

## Commands on this page

- [`tkt plan parallel`](/en/docs/reference/commands/plan.md#tkt-plan-parallel): Can these tickets run in parallel worktrees?
- [`tkt worktree new`](/en/docs/reference/commands/maintenance.md#tkt-worktree-new): Branch (worktreeBranch, default feat/{id}-{slug}) + worktree (worktreeDir, default ../{repo}-{id}) + the claim there, in one step; then the worktreeSetup script
- [`tkt worktree done`](/en/docs/reference/commands/maintenance.md#tkt-worktree-done): Give the ticket's claim back (from any worktree); --remove also removes its worktree once clean, else refuses (ERR\_WORKTREE\_REFUSED) and says why
- [`tkt ticket claims`](/en/docs/reference/commands/ticket.md#tkt-ticket-claims): List the claims: assignee, branch, worktree and age; `stale` when the worktree is gone

## Related

- Guide: [Claiming and giving back](/en/docs/guides/loop/claim.md): tkt ticket claim PAY-001 --assignee \<you\> claims a given ticket by the tkt next rule; tkt ticket release PAY-001 gives it back (in\_progress → todo, assignee…
- Config key: [`parallelRiskPaths`](/en/docs/reference/config.md#parallelRiskPaths): Path globs tkt plan parallel treats as a risk when two tickets touch them
- Error code · 409: [`ERR_WORKTREE_REFUSED`](/en/docs/reference/errors.md#ERR_WORKTREE_REFUSED): tkt worktree done --remove: changes in it, or the main worktree
- Error code · 500: [`ERR_GIT_FAILED`](/en/docs/reference/errors.md#ERR_GIT_FAILED): A git operation failed; carries git's stderr
- Doctor · warning: [`STALE_CLAIM`](/en/docs/reference/doctor.md#doctor-STALE_CLAIM): A claim whose worktree is gone: tkt ticket release --stale
- Config key: [`sharedCounter`](/en/docs/reference/config.md#sharedCounter): Every worktree of the repo shares one id counter
- Config key: [`worktreeBranch`](/en/docs/reference/config.md#worktreeBranch): The branch name template of tkt worktree new
- Config key: [`worktreeDir`](/en/docs/reference/config.md#worktreeDir): The directory template of tkt worktree new
- Config key: [`worktreeSetup`](/en/docs/reference/config.md#worktreeSetup): A command tkt worktree new runs in the new worktree
- Env var: [`AITODO_TICKET`](/en/docs/reference/env.md#AITODO_TICKET): The ticket id the new worktree is for
- Env var: [`AITODO_WORKTREE`](/en/docs/reference/env.md#AITODO_WORKTREE): The new worktree's path
