Work
Enter autonomous worker mode: continuous claim → code → close → push → next loop until budget exhausted, queue empty, or hard blo…
# /work — Worker Mode
Enter autonomous worker mode: continuous claim → code → close → push → next loop until budget exhausted, queue empty, or hard blocker hit.
**This is a canonical command** — synced from `standards/.claude/commands/work.md` into every project's `.claude/commands/work.md` by `preflight.sh` §5. Do NOT edit this file in your project — edit the canonical in `standards/` (or override locally for transitional purposes; see "Per-project customization" at the bottom).
## Syntax
/work # all ready tasks, no budget cap
/work --max-tasks
Arguments are passed as `$ARGUMENTS`. Parse to extract epic short_ids (e.g., `Citadel-3n3`, `LoRa-abc`), a `--group <name>` value, and `--max-tasks <N>`. Unknown flags should print a brief usage block and exit.
## Project resolution
Run all `dw` calls with explicit `--project <name>`. Resolve the project name in this order:
1. `$DW_PROJECT` env var (most reliable — user-set per session)
2. `git -C "$(git rev-parse --show-toplevel)" remote get-url origin` → parse `github_repo` → look up `name` in `dw projects` (some workspace dir names don't match the Citadel project name; this resolves the asymmetry)
3. Fall back to `basename "$(git rev-parse --show-toplevel)"` only if 1 and 2 both fail, and surface a warning
If the project name can't be resolved at all, STOP and tell the user.
## Startup Protocol — MANDATORY, IN ORDER
ALL steps complete before any code change.
### 1. Refresh context
/refresh-context
This validates date/time (mandatory; never assume), runs preflight (Citadel + Agent Mail health + canonical command sync + session-state read), reads the 5 canonical references, and surfaces any prior-session in-flight state via `session-state.py read`.
### 2. Register with Agent Mail + write identity file
ensure_project(human_key="
Write your agent name to `.agent-identity` in the project root:
```bash
echo "<YourAgentName>" > "$(git rev-parse --show-toplevel)/.agent-identity"
The .agent-identity file is what pre-commit reads to enforce HEAD/main blocks and Agent Mail file-reservation checks. No identity = no commits.
3. Check inbox for coordination messages
fetch_inbox(project_key="<absolute project dir>",
agent_name="<your-name>",
include_bodies=true)
Read every message before claiming work. If another agent has flagged a file lock, a handoff, or an unresolved coordination issue on a task you might claim, acknowledge first.
4. Initialize / recover session state
python "$(git rev-parse --show-toplevel)/.claude/hooks/session-state.py" read
If read produces output: a prior session left state (claimed tasks, active worktree, open PRs). You are recovering from compaction OR resuming an earlier session.
- Audit each claimed task with
dw --project <name> show <short_id> - For any active worktree,
cdin and checkgit statusfor uncommitted work - Decide for each: resume, hand off, or release. Do NOT claim new work until the inherited state is reconciled.
If read produces no output: clean start, continue to step 5.
5. Find available work
dw --project <name> ready # all unblocked ready tasks
dw --project <name> ready --group <name> # scoped to a task group
If epic ID(s) were passed as $ARGUMENTS, filter to tasks whose depends_on includes the epic.
If dw ready returns nothing AND no open task is recoverable from step 4 state: STOP. Worker has nothing to do.
6. Claim exactly ONE task
dw --project <name> claim <short_id> --agent "<your-name>"
claim is atomic — two agents racing for the same task safely produce one winner and one HTTP 409. On 409 (already_claimed), pick the next ready task.
The work loop
Per task, follow this exact order. Each step is a tollgate the next step depends on.
┌─────────────────────────────────────────┐
│ 1. Plan + verify scope vs. task title │
│ 2. Create worktree + branch from main │
│ 3. Reserve files via Agent Mail │
│ 4. CODE (test-driven where applicable) │
│ 5. Verify (BUILD_COMMAND per CLAUDE.md) │
│ 6. Commit (pre-commit + commit-msg gates)│
│ 7. Close Citadel task BEFORE push │
│ 8. Push (pre-push close-check) │
│ 9. Open PR (gh pr create) │
│10. Report PR to user — STOP for review │
│11. On user approval: gh pr merge --auto │
│ --rebase │
│12. Wait for merge, sync local main │
│13. Post close-out comment (triple-write) │
│14. Release file reservations │
│15. Clean up worktree │
│16. Update session-state.py write │
└─────────────────────────────────────────┘
↓
Check budget; if remaining → next claim
Critical anti-patterns from prior sessions — DO NOT REPEAT
- No squash merges. Canonical convention is
gh pr merge --auto --rebase. Squash is never agent-default; the user explicitly opts in if they want it. - No manual merges. Agent enables auto-merge after user approval; GitHub does the merge. Manual me
Maintain Work?
Let people know it's listed here — add the badge (live metrics, light/dark aware) or a plain link to your README or docs.
[Work on getagentictools](https://getagentictools.com/loops/offbandmesh-work-worker-mode?ref=badge)