Skip to main content

Shared Task Queue (Cross-Worktree)

A filesystem-based task inbox shared across all parallel worktree agents. Agents pull tasks at session start without a central dispatcher. The missing coordination layer between worktree isolation (filesystem) and the Pocock/SandCastle planner model (centralized assignment).

The Problem

Worktrees are filesystem-isolated — a directory inside worktree A is not visible to worktree B. The natural instinct is to put the task inbox inside the repo, but that inbox lands inside each worktree’s own checkout, so agents can’t see each other’s task state. The fix: the inbox lives in the main checkout, not in any worktree. Every worktree can locate the main checkout via git rev-parse --git-common-dir, which always returns the path to the shared .git regardless of which worktree the agent is running in.

Directory Layout

.agents/ can be committed (tasks become part of repo history) or gitignored (ephemeral, recreated per session). Committing is preferred: the task state is auditable and survives machine restarts.

Atomic Claim Protocol

mv is atomic on POSIX for renames within the same filesystem. Two agents racing to claim the same task file: exactly one mv succeeds, the other gets ENOENT. No lock files, no polling loop for the lock.

Completion


Three Startup Layers

Pick the depth appropriate to your setup.

Layer 1: CLAUDE.md instruction (lightest)

All worktrees inherit this CLAUDE.md from the main branch. The instruction is always in context. Relies on the agent following it.

Layer 2: Orchestrator pre-claims (reliable)

The orchestrator claims tasks before spawning Claude. Claude never sees the inbox — it receives its task in the initial prompt.
This is the Pocock/SandCastle pattern extended with pre-claim. The planner populates inbox; the orchestrator claims and spawns.

Layer 3: Skill (agent-pull model)

Per Agent Skills: skills are the right primitive for “do this at startup” — they’re loaded on demand, show up as meta-tools, and the CLAUDE.md can instruct agents to invoke them before anything else.

Task File Format

Task files should be self-contained — the agent should be able to start from nothing but the file.
The blocking/blocked-by fields mirror the Pocock DAG — the orchestrator or planner uses these to decide what’s claimable; agents don’t need to parse them.

Inbox Population Sources


State Machine

Failure return: orchestrator monitors claimed/ for tasks older than timeout threshold and mvs them back to inbox/.

Relation to Existing Patterns