crew/bin/gstack-crew lets one local controller run multiple coding-agent workers in parallel on a single machine using plain Claude Code (claude -p) or Codex CLI (codex exec) inside isolated git worktrees. You do not need Capy, cloud threads, or external orchestration services.
This is Phase 1 (local-only). Cloud worker backends such as Claude Code on the web and Codex cloud are intentionally out of scope until their task APIs stabilize; passing a cloud harness name is refused explicitly.
- Git with worktree support (Git 2.20+).
- Bun >= 1.4.2 on
PATH(runscrew/bin/gstack-crewandbin/gstack-ship-queue). - At least one authenticated local coding CLI:
- Claude Code (
claudeonPATH, or setGSTACK_CLAUDE_BIN), or - Codex CLI (
codexonPATH, or setGSTACK_CODEX_BIN).
- Claude Code (
- GitHub CLI (
gh) authenticated for the target repository if you hand finished branches off togstack-ship-queue.
Run gstack-crew directly from your gstack checkout (for example ~/.claude/skills/gstack/crew/bin/gstack-crew) or add crew/bin to your PATH.
Unattended local workers operate on your own machine, so gstack-crew enforces four hard limits on every worker:
- Scoped permissions — explicit worktree allowlist.
- Claude Code (
claude -p): runs with--permission-mode dontAsk,--setting-sources ""(isolating user/project settings), explicit--tools Read,Edit,Write,Glob,Grep,Bash,--strict-mcp-config, hooks disabled, and a per-worktree--allowedToolsallowlist (Read,Edit,Write,Glob,Greprestricted strictly to the worker's worktree path plus a small allowlist of local git and test commands).--disallowedToolsexplicitly blocksmcp__*,WebFetch,WebSearch,git merge,gh pr merge, force-push,git -c/--output/--no-index/commit -F,sudo, and network fetch commands. Passing--allow-bash <prefix>adds one safe command prefix (for examplevitest); unrestricted shells, bare roots, path-qualified binaries, and merge/push/flag bypasses are refused. Note: allowlisted test runners (bun test,npm test,bun run,npm run) execute repo test scripts under your local user permissions unless you wrap the run in an OS sandbox. - Codex CLI (
codex exec): always runs with--sandbox workspace-write,-C <worktree>,approval_policy="never",sandbox_workspace_write.network_access=false, andmcp_servers={}(clearing inherited~/.codex/config.tomlMCP servers so external tools cannot bypass the sandbox). Full-access and bypass flags are never emitted. Note: Codex'sworkspace-writesandbox keeps linked worktree.gitmetadata outside-C <worktree>read-only, so if a Codex worker leaves clean verified edits uncommitted, commit them in its worktree before runningreadyorland.
- Claude Code (
- Per-worker spend cap and wall-clock timeout.
- Every worker requires positive
--spend-cap <usd>(default$10) and--timeout <seconds>(default1800s). - For Claude Code,
--max-budget-usdis passed to the CLI and the controller parses streaming JSONL output in real time, terminating the process group as soon as accumulated spend reaches--spend-cap. - For Codex CLI,
codex exec --jsonreports token usage onturn.completed(at the end of each turn), so--timeoutis the live mid-turn bound and--spend-capis checked immediately onturn.completed(marking an over-cap runstoppedwithstop_reason=spend_capand blocking furtherresumeuntil--spend-capis raised). When--modelis omitted or absent fromlib/pricing.ts, Codex token usage is priced conservatively atgpt-6.2-astrarates ($8/$40per MTok) so caps do not undercount pricier models. Keep--timeouttight on unattended Codex workers. - Whenever elapsed time reaches
--timeoutor live spend reaches--spend-cap, the controller terminates the worker's entire process group (SIGTERM, grace period, thenSIGKILL) and records the exact stop reason (spend_caportimeout) in the state file.
- Every worker requires positive
- Merges only through
gstack-ship-queue.- Workers commit to their own worktree branch and never merge.
gstack-crew landvalidates that the worker is stopped and its worktree is clean, then delegates strictly tobin/gstack-ship-queue land --pr <n> --pin <sha>.gstack-crewnever runs rawgit mergeorgh pr merge.
- Durable state and crash recovery.
- State lives under gstack's state root (
$GSTACK_STATE_ROOT/crew-local/<repo>-<hash>/state.json, mode0600, written atomically under a file lock; override with--state-dir), alongside a shared spend file (spend.json), per-run stdout JSONL logs (logs/<id>-<run_id>.jsonl), and separate stderr logs (logs/<id>-<run_id>.stderr.log). gstack-crew statuschecks OS process liveness for every running worker. If a worker was killed or crashed (OOM, SIGKILL, laptop sleep/reboot),statustransitions it cleanly tocrashed, recovers spend and session ID from its JSONL log, settles the open spend reservation, and leaves its worktree and branch intact.gstack-crew resume --lane <id>picks up in that exact worktree and branch with the remaining budget (and passes--resume <session_id>for Claude Code unless--fresh-sessionis set).
- State lives under gstack's state root (
crew/bin/gstack-crew start \
--lane auth-retry \
--harness claude \
--planned "src/auth/**" --planned "test/auth.test.ts" \
--spend-cap 5 \
--timeout 900 \
--prompt "Add exponential backoff to token refresh and cover it with unit tests."To launch in the background so your shell returns immediately, add --detach:
crew/bin/gstack-crew start \
--lane docs-api \
--harness codex \
--planned "docs/api.md" \
--spend-cap 3 \
--timeout 600 \
--detach \
--prompt "Document the v2 pagination query parameters in docs/api.md."Create workers.json:
{
"lanes": [
{
"lane": "auth-retry",
"harness": "claude",
"planned": ["src/auth/**", "test/auth.test.ts"],
"spend_cap": 5,
"timeout": 900,
"prompt": "Add exponential backoff to token refresh and add tests."
},
{
"lane": "docs-api",
"harness": "codex",
"planned": ["docs/api.md"],
"spend_cap": 3,
"timeout": 600,
"prompt": "Document the v2 pagination query parameters in docs/api.md."
}
]
}Run them together:
crew/bin/gstack-crew run --manifest workers.json --concurrency 2Before creating any worktree, gstack-crew checks every worker's planned paths against sibling workers and existing branch diffs (using crew/lib/lane-ownership.ts) and refuses to start if two workers claim overlapping files.
crew/bin/gstack-crew status
crew/bin/gstack-crew status --jsonIf a worker was killed (status=crashed) or hit a cap (status=stopped, stop_reason=spend_cap or stop_reason=timeout), resume it in the same worktree and branch:
# Recover a crashed worker with its remaining budget
crew/bin/gstack-crew resume --lane auth-retry
# Raise the cap to continue a worker that stopped at its spend limit
crew/bin/gstack-crew resume --lane auth-retry --spend-cap 10 --timeout 1200# Stop a running worker cleanly (keeps its worktree and branch)
crew/bin/gstack-crew stop --lane auth-retry
# Once the worker's branch has a PR with /gstack-ship verification:
crew/bin/gstack-crew ready --lane auth-retry --pr 42 --no-screen
# Land exclusively through gstack-ship-queue (dry-run first to inspect)
crew/bin/gstack-crew land --lane auth-retry --pr 42 --dry-run
crew/bin/gstack-crew land --lane auth-retry --pr 42
# Remove finished worktrees
crew/bin/gstack-crew clean --finished| Command | Purpose |
|---|---|
start |
Create one git worktree and branch, persist state, and run a local claude or codex worker (foreground or --detach). |
run |
Validate pairwise file ownership across a JSON manifest and run workers in parallel up to --concurrency. |
status |
Reconcile process liveness, recover crashed workers, and show worktree SHA, dirty state, spend vs cap, and stop reason. |
resume |
Restart a crashed, stopped, failed, or completed (non-landed) worker in its existing worktree and branch (reattaching the worktree from the branch if needed). |
stop |
Send SIGTERM then SIGKILL to one worker's process group (or --all), settle the current attempt's spend, and preserve its worktree and branch. |
ready |
Verify the worker is stopped and clean, run gstack-ship-queue ready from its worktree, and record the PR number and HEAD SHA on success. |
land |
Verify the worker is stopped and clean, then run gstack-ship-queue land --pr <n> --pin <sha>. |
clean |
Remove worktrees for --lane <id> or --finished (completed and landed only, preserving crashed/stopped/failed lanes); refuses live workers and dirty worktrees unless --force is passed (optional --delete-branch). |
Common flags supported on every command: --repo <path>, --state-dir <dir>, and --json.
- Local machine only: every worker runs as a local process in a local git worktree. Cloud execution backends are planned for Phase 2.
- No automatic PR creation: workers commit to their branch; open the PR and run
/gstack-shipbefore callinggstack-crew readyandgstack-crew land. - Token-based spend estimation for Codex CLI: when
codex exec --jsonemits token counts without a direct dollar figure, spend is estimated from gstack's model price table (lib/pricing.ts).