Repository navigation
feat(bin): select a Claude account per crew dispatch profile - #5444
Open
gus-fraser wants to merge 4 commits into
Open
gus-fraser wants to merge 4 commits into
gus-fraser wants to merge 4 commits into
Conversation
A dispatch profile can now name an account from config/claude-accounts, and fm-spawn --account launches that Claude worker with the account's CLAUDE_CONFIG_DIR and registers workspace trust in the same store. The account is recorded in task meta and reused on relaunch, validated by bootstrap and the typed resolver, and bound only to its own quota-axi accountKey row.
…measured-account resolver gap
… for Claude accounts
…and relaunch docs
Contributor
|
A design question affecting this PR's account-file inheritance has been opened: #5481 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Add account selection to crew dispatch rules so a dispatch profile can choose which Claude subscription a worker runs on.
The setup behind the ask: one Codex subscription and two Claude subscriptions.
The second Claude subscription is signed in under its own Claude config directory (for example
~/.claude-second, referred to as the accountclaude-second), while the first uses the default~/.claude.Today a dispatch profile can only choose harness, model, and effort, and
bin/fm-spawn.shforwards only firstmate's own ambientCLAUDE_CONFIG_DIRonto every Claude worker launch, so every Claude worker lands on whichever account firstmate itself runs under and there is no way to route some jobs to the second account.Do the upstream change so that
claude-secondcan be selected per dispatch profile for the native Claude Code runtime.Routing through the Pi runtime is not wanted as the way to reach the second account.
What Changed
config/claude-accountsregistry that maps an account name (for exampleclaude-second) to an absolute Claude config directory. The newbin/fm-claude-accounts-lib.shparses it and validates the whole file on every lookup. It refuses invalid or reserved names (defaultis reserved), unknown names, duplicate or malformed entries, and relative or missing directories.accountfield, which is valid only with"harness": "claude".fm-bootstrap.shandfm-dispatch-resolve.shvalidate it and resolve its name. Two profiles that differ only by account now count as distinct candidates. The resolver passes--account <name>tofm-spawn.sh, and quota for a named account comes only from a schema 6 quota-axi row whoseaccountKeymatches exactly. It never falls back to the default account's row, so until such a row exists, a profile that names an account is left unmeasured and unranked. Given--account,fm-spawn.shlaunches the native Claude worker with that account's directory asCLAUDE_CONFIG_DIR, replacing Firstmate's own, and pre-registers workspace trust in that account's store. It recordsaccount=in the task metadata and refuses the flag for secondmates, raw launch commands, and non-Claude harnesses before any endpoint or worktree is created. With no account, launches run exactly as before.fm-control.sh relaunchkeeps the recorded account when the task stays on Claude and drops it when switching to another harness. It accepts--account <name>to move the task to another account, or--account defaultto return it to the default account. An account that doesn't resolve is refused before the running agent is stopped. Docs, skills, andAGENTS.mdnow describe the account axis, including that each account's Claude config directory must already have accepted Bypass Permissions mode. Tests cover bootstrap validation, resolver output and quota binding, spawn launch behavior, and relaunch.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The account axis only takes effect when a profile, spawn, or relaunch names an account, so launches without one behave as before. Every account refusal (unknown, reserved, relative or missing directory, wrong harness, secondmate) fires before any endpoint, record, or running agent is touched. Both prior-round items are in the current code as the user asked: the relaunch account override and the documented typed-resolver limitation.
Testing
I drove the change live in a throwaway Herdr lab with a scratch Firstmate home and scratch Claude config stores. Spawn routes a Claude worker onto the named account's store, confirmed from the live process env, task meta, and per-store trust registration. A spawn with no account keeps using the ambient store. Seven adversarial spawn refusals left no task record and no lab tab. Five relaunch refusals left the running worker alive. Four relaunch moves each landed on the right store and journaled from_account and to_account. A store that has not accepted Bypass Permissions visibly parks on the dialog, as the new docs state. The real resolver and bootstrap accepted valid account profiles and refused bad ones with exit 2 before any network call. Two lab setup problems were fixed and re-driven. Brand-new scratch stores stopped on Claude's first-run theme picker, so I marked onboarding complete in them. A
//in the mktemp path confused teardown's exclusivity check, so I switched to canonical paths. All four targeted test files (dispatch-resolve, spawn-dispatch-profile, control-relaunch, bootstrap) passed. The lab is torn down and the worktree is clean.Evidence: Spawn account refusals (live lab)
Source: Spawn account refusals (live lab)
Evidence: Spawn on claude-second vs no account: meta, process env, trust stores
Source: Spawn on claude-second vs no account: meta, process env, trust stores
Evidence: Relaunch account refusals leave worker running
Source: Relaunch account refusals leave worker running
Evidence: Relaunch account moves (default, back, keep, default->second)
Source: Relaunch account moves (default, back, keep, default->second)
Evidence: Unaccepted store shows Bypass Permissions dialog (documented precondition)
Source: Unaccepted store shows Bypass Permissions dialog (documented precondition)
Evidence: Resolver + bootstrap crew-dispatch account validation
Source: Resolver + bootstrap crew-dispatch account validation
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 2 issues found → auto-fixed ✅
bin/fm-quota-axi-lib.sh:58- Under typed dispatch resolution, a profile that names a Claude account can never be ranked with the quota-axi installed today.quota_bound_rowbinds an account only to a schema-6 row whoseaccountKeyequals the account name, and returns null under schema 5. The installed quota-axi (quota-axi --json --provider claude) reportsschemaVersion: 5and one claude row withaccountKey: null. It has no multi-Claude-account snapshot; a second store can only be read separately withCLAUDE_CONFIG_DIR=<dir> quota-axi --profile-only. So in the user's setup: (a) a quota-balanced array such as[{claude, account: claude-second}, {claude}]always resolvesclearto the default account whenever the default row is measured, and the second subscription is never chosen, which is exactly what the new test at tests/fm-dispatch-resolve.test.sh asserts; (b) a rule whose only profile isclaude@claude-secondalways escalates with 'no rankable eligible candidate' and falls back to manual intake. Refusing to borrow the default row is correct. The gap is that the second subscription is never measured, so quota-balanced routing across the two Claude accounts cannot work on the typed path. The remedy would be measuring each configured account, for example by runningquota-axi --profile-onlyonce perconfig/claude-accountsentry and merging the rows. That adds new snapshot-collection machinery beyond the stated intent, so the remedy, not the defect, is what needs authorization. Alternatively, document the limitation explicitly for the typed path.bin/fm-spawn.sh:797- A relaunch can keep or drop a Claude account but cannot change it.fm-spawn --relaunchrefuses--account(line 797), andfm-control relaunchhas no--accountoption. A relaunch that stays on claude always reuses the recorded account (line 2283), andfm-controlrefuses before the stop if that account no longer resolves (bin/fm-control.sh:851). Common case: a worker onclaude-secondhits that subscription's usage limit. The natural recovery, relaunching onto the default Claude account, is impossible; the only way off the account is switching to another harness entirely. The design is deliberate and the intent does not require it, so this is for the author to confirm. Remedy if wanted: let a claude relaunch take an explicit account override, including an explicit 'no account'.🔧 Fix applied.
✅ Re-checked - no issues remain.
🔧 **Test** - 1 issue found → auto-fixed ✅
docs/configuration.md:401- Workers launch with--dangerously-skip-permissions. If the selected account's Claude store has never accepted Bypass Permissions mode (noskipDangerousModePermissionPromptin<dir>/settings.json), Claude shows the Bypass Permissions warning with the cursor on 'No, exit'. Firstmate cannot answer that dialog. Seen live in the lab:fm-spawn.sh … --account claude-secondstill printed 'spawned' while the worker sat on the dialog (evidence 02). A follow-upfm-control.sh relaunch --account defaultthen failed with a misleading 'composer visibly holds pending text' error and left the task with no running agent (evidence 04a). Addingsettings.json {"skipDangerousModePermissionPrompt":true}to the store removed the dialog, and every later relaunch succeeded. So the cause is per-store, not machine-wide asdocs/verification/runtime-backends.md:461suggests. That doc dismissed the gate because 'a normal environment has already accepted it'; this change makes a second, separate store a normal production path. The user's real~/.claude-second(checked read-only, key names only) is signed in (oauthAccount) but has nosettings.json, so the first real dispatch ontoclaude-secondwould likely wedge. The 'Claude accounts' section of docs/configuration.md says only that the account must be signed in. Possible remedies, for the author to choose: document the precondition (runCLAUDE_CONFIG_DIR=<dir> claude --dangerously-skip-permissionsonce and accept, or setskipDangerousModePermissionPromptin that store), and/or have bootstrap or spawn flag an account store that has not accepted it.fm-control relaunch --account defaultmoves it to the default (ambient) store, drops account= from meta, and the journal records from_account=claude-second to…fm-control relaunch --account claude-secondmoves a default-store worker onto claude-second, and a plain relaunch keeps the recorded accountprofile: --harness claude … --account claude-secondfor fm-spawnbin/fm-herdr-lab.sh name acct-select+provision/teardown fm-lab-acct-select-21198-10115(guarded lab lifecycle; the default-session tripwire matched at teardown)fm-spawn.sh acct0 <proj> --mode local-only --yolo off --backend herdr --harness claude --account {claude-third,default,Claude-Second}and--harness codex --account claude-second, plus relative-dir and missing-dirconfig/claude-accounts(all refused; no tab or meta created)fm-spawn.sh acct1 <proj> --mode local-only --yolo off --backend herdr --harness claude --account claude-secondwith ambientCLAUDE_CONFIG_DIRset to a different scratch store; checked the live worker's env withherdr pane process-info+ps eww, the task meta, and the.claude.jsontrust entries in both storesfm-control.sh acct1 relaunch --account claude-third | --harness codex --account claude-second | --account Claude-Second, plus a plain relaunch after removing the account dir (all refused before the stop; worker pid still alive)fm-control.sh acct1 relaunch --account default(first attempt blocked by the per-store Bypass Permissions dialog; succeeded after the store accepted bypass mode), then--account claude-second, then a plain relaunch; checked worker env, meta and theacct1.control-relaunchjournal each timefm-dispatch-resolve.sh <brief> --project projwith rules naming an unknown account, an account on codex, duplicate account profiles and an empty account (a dummy key reached only the pre-network validation;curlwas shimmed and never called)bash tests/fm-dispatch-resolve.test.sh,bash tests/fm-control-relaunch.test.sh,bash tests/fm-spawn-dispatch-profile.test.sh,bash tests/fm-bootstrap.test.sh(targeted to this change: 189 ok, 0 not ok)🔧 Fix applied.
✅ Re-checked - no issues remain.
bin/fm-herdr-lab.sh provision fm-lab-acct-r2-25675-6330…teardown(a throwaway lab; the default session was untouched afterwards)fm-spawn.sh acct1 <proj> --mode local-only --yolo off --backend herdr --harness claude --account <claude-third|default|Claude-Second>,--harness codex --account claude-second, and claude-accounts files with a relative dir, a missing dir, and a duplicate entry (7 refusals)fm-spawn.sh acct1 … --harness claude --account claude-secondandfm-spawn.sh acct2 … --harness claude(no account); checked task meta,ps ewwCLAUDE_CONFIG_DIR of the live claude process, and each store's.claude.jsontrust entriesfm-control.sh acct1 relaunch --account <claude-third|Claude-Second>,--harness codex --account claude-second, a relative-dir config, and the account directory removed; checked the worker pid is still alive and meta unchanged after eachfm-control.sh acct1 relaunch --account default, then--account claude-second, then a plain relaunch;fm-control.sh acct2 relaunch --account claude-second; checked meta, the replacement process env, and the control-relaunch journalfm-spawn.sh acct3 … --account claude-third, a store with no skipDangerousModePermissionPrompt; captured the pane viewportfm-dispatch-resolve.sh <brief> --project projwith TYPESAFE_API_KEY set and curl shimmed, plusfm-bootstrap.shdetect, against 6 crew-dispatch.json variantsbash tests/fm-dispatch-resolve.test.sh(passed)bash tests/fm-control-relaunch.test.sh(passed)bash tests/fm-bootstrap.test.sh(passed)bash tests/fm-spawn-dispatch-profile.test.sh(passed)✅ **Document** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.