Skip to content

feat(bin): choose a Claude account per ship or scout from a declared list - #7892

Closed
omkarbhale wants to merge 4 commits into
kunchenguid:mainfrom
omkarbhale:fm/fm-7638-accounts
Closed

omkarbhale wants to merge 4 commits into
kunchenguid:mainfrom
omkarbhale:fm/fm-7638-accounts

Conversation

@omkarbhale

@omkarbhale omkarbhale commented Oct 28, 2026 •

Copy link
Copy Markdown

Intent

Contribute an implementation of the upstream issue #7638 to firstmate ("Can we contribute here?"). The issue is labelled ready-for-pr.

The issue asks for this. Let Firstmate choose the Claude account per crewmate (ship/scout worker) instead of per home, and pick the account using each account's remaining quota, so several Claude subscriptions can serve one fleet at the same time. Today config/claude-account pins one CLAUDE_CONFIG_DIR for every Claude worker a home launches. Dispatch profiles and quota-array-dispatch choose harness, model and effort but not account, and quota-axi reports Claude as a single provider.

Its sketch:

  • Declare several Claude accounts (each an existing CLAUDE_CONFIG_DIR) as a list, e.g. config/claude-accounts.
  • Add an account axis to dispatch profiles, or let the quota-aware selection pick among declared accounts.
  • quota-axi reports each account separately so spendPriority and runway can rank them.
  • Record the chosen account in the task meta so relaunch and recovery reuse it, and allow an explicit relaunch onto another account when the current one is exhausted.
  • Keep the existing sign-in check (claude auth status) per account before launch.

The maintainer's triage set what a PR must hold to:

  • Off by default. With no account list present, every launch is byte-for-byte today's behaviour, including the single-pin path.
  • Captain-declared only. Firstmate picks only among accounts the captain listed. It never discovers, adds or copies a login, and never changes a global login.
  • Same refusals per account. claude auth status with the stripped environment, the credential unsetting, and refusal on a malformed or signed-out entry. Never a silent fallback to the ambient account.
  • Inspectable. The chosen account goes in the spawn line and the task meta (as account= is today), and relaunch and recovery reuse it.
  • Switching stays explicit. Moving a running worker to another account goes through the normal relaunch path on an explicit request, never automatically mid-task.
  • Quota stays data-only. Per-account quota rows come from quota-axi or a deterministic mapping. Ranking stays in the existing dispatch procedure, with no new composite score or daemon.
  • Any always-loaded AGENTS.md text must fit the 9,000-word ceiling; detail belongs in docs/configuration.md and the skill.

The person contributing has two separate Claude subscriptions.

What Changed

  • Adds opt-in config/claude-accounts (a list of ordinary or absolute Claude config dirs). When it is present, every Claude ship or scout spawn must name a declared entry with --account, and that entry goes through the same claude auth status check and credential unsetting as the single pin. A malformed or signed-out entry refuses, and so does a home that has both the list and config/claude-account. The chosen account is written to the spawn line and the task meta as account=. Without the list, launches behave exactly as before.
  • Relaunch and recovery reuse the recorded account. fm-control.sh <id> relaunch --account <entry> moves a task to another declared account explicitly. A task with no recorded account, or with one that is no longer declared, refuses a plain relaunch.
  • Adds bin/fm-claude-account-quota.sh. It runs quota-axi --profile-only under each declared account's config dir and prints one data-only quota row per account. It does not rank or pick an account. Choosing the account stays in the quota-array-dispatch skill. The change also updates docs/configuration.md, AGENTS.md, the related skills, and the tests.

🤖 Generated with Claude Code

Risk Assessment

⚠️ Medium: The account list is off by default, and I found no defect in the new paths. They check each entry, refuse bad ones, and stay explicit about which account is used, but they touch spawn and relaunch launch decisions, so a human should still look.

Testing

I ran the three targeted test files for this change: the quota helper, spawn and the account library, and relaunch. All three exited 0. I also drove bin/fm-claude-account-quota.sh live in a throwaway lab home with the real quota-axi and ~/.claude login. With no list or a malformed list it refused with exit 2. With a declared account it printed one row of facts per account (remaining, spendPriority, runway, confidence) and chose nothing. The spawn and relaunch scenarios were covered only by script tests, not live. I could not launch a live worker on a second Claude account because only one login exists on this machine.

  • Live validation: ✅ go - 2 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Quota helper reports a declared real account as a data-only row, with no verdict or choice ✅ pass live quota-helper-live.txt
Quota helper refuses with exit 2 when the account list is absent or malformed ✅ pass live quota-helper-live.txt
Spawn with --account launches only on a declared, signed-in account and records it; with no list, launches are unchanged ⏸️ untested no The prior payload did not establish a live result. Only the script test (fm-worker-account.log) covered this, not a live Claude worker spawn.
Relaunch keeps the recorded account, moves only on an explicit --account, and refuses undeclared or signed-out accounts ⏸️ untested no The prior payload did not establish a live result. Only the script test (fm-control-relaunch.log) covered this. A live two-account relaunch needs a second signed-in CLAUDE_CONFIG_DIR.
Live lab spawn of a Claude worker on a second subscription ⏸️ untested no Only one Claude login (~/.claude) exists on this host, and signing in a second account is forbidden here. To run it, provide a second signed-in CLAUDE_CONFIG_DIR.
Evidence: Live quota helper transcript

Source: Live quota helper transcript

\### no list
error: this home declares no config/claude-accounts; there is nothing to measure
exit=2
\### malformed
error: config/claude-accounts must hold one account per line, each 'ordinary' or an absolute path, with no blank lines or control characters: /tmp/fm-lab.fa5vmj/config/claude-accounts
exit=2
\### real ~/.claude
claude-account-quota:
  row: ~/.claude  root=~/.claude  scope=all_models  status=known  remaining=35%  spendPriority=-1.0359  runway=projected_exhaustion  usableRunwaySeconds=111815  confidence=established
exit=0
Evidence: worker-account test log

Source: worker-account test log

ok - Claude, Pi, and pi-signed secondmates use their own pins without changing other launches
warning: re-init: ignored --initial-branch=main
warning: re-init: ignored --initial-branch=main
warning: re-init: ignored --initial-branch=main
warning: re-init: ignored --initial-branch=main
warning: re-init: ignored --initial-branch=main
warning: re-init: ignored --initial-branch=main
warning: re-init: ignored --initial-branch=main
warning: re-init: ignored --initial-branch=main
warning: re-init: ignored --initial-branch=main
warning: re-init: ignored --initial-branch=main
ok - unusable per-mate pins name the setting and refuse rather than use the primary's usable account
ok - a remote route refuses a primary-side account override instead of silently ignoring it
ok - a remote secondmate refuses --account instead of launching on the remote home's account
ok - an absent pin leaves Claude and Pi launches exactly as they were
ok - a Claude pin selects its root and sheds the credentials that would outrank it
ok - a Claude pin refuses a signed-out root even when the invoking process has a usable login and API key
ok - an ordinary Claude pin selects the default login and drops an ambient root
ok - malformed, relative, CR-terminated, empty, extra-line, missing-root, and non-file pins refuse before launch
ok - a Pi pin selects its root and passes the declared provider
ok - a Pi pin refuses unqualified, missing, undeclared, signed-out, and raw launches
ok - extension providers and a Pi without auth check fall back to an exact model-listing match
ok - a Claude pin leaves codex and Pi launches unchanged
ok - a raw Claude launch command receives the home's pin
ok - a pinned home refuses a raw Claude command that overrides the account
ok - an unpinned home keeps a raw Claude account override
ok - a local secondmate reads the launching home's pin and its own home's file is never inherited over
ok - without config/claude-accounts the launch, the single pin, and the record are unchanged, and --account refuses
ok - a declared account named with --account is checked, launched, and recorded like a pin
ok - a list refuses a missing, undeclared, signed-out, wrong-runner, raw-override, doubled, or malformed choice
warning: re-init: ignored --initial-branch=main
warning: re-init: ignored --initial-branch=main
ok - a list never chooses a secondmate's account: it needs its own pin and refuses --account
# all fm-worker-account tests passed
Evidence: relaunch test log

Source: relaunch test log

ok - fm-spawn --relaunch: tracked opencode wiring is retired as on main
ok - fm-control removes the dialog file after exit and after relaunch
ok - fm-control exit removes the dialog file before it releases the control lock
ok - fm-control relaunch: a same-harness relaunch replaces the agent in the same endpoint and worktree
ok - fm-control relaunch: pending composer text refuses before the exit command is typed
ok - fm-control relaunch: an unreadable composer fails safe before the exit command is typed
ok - fm-control relaunch: a linked spawning home preserves committed and unfinished work in the recorded copy
ok - fm-control relaunch: durable task metadata survives replacement launch publication
ok - fm-control relaunch: delivery and concurrent task metadata publication serialize
ok - fm-control relaunch: disabling tracing clears metadata and pane context
ok - fm-control relaunch: progress and the Firstmate-worktree worker identity reach the replacement
ok - fm-control relaunch: the progress note's inbox listing is silent on an empty inbox
ok - fm-control relaunch: a ship task refuses without the progress note its replacement needs
ok - fm-control relaunch: switching harness is one ordinary relaunch, and the old wiring goes with the old agent
ok - fm-control relaunch: a refused relaunch onto polytoken keeps the project's own hook layer and the running agent
ok - fm-control relaunch: a refused polytoken profile leaves the running agent untouched
ok - fm-spawn --relaunch: retiring a raw polytoken launch's wiring keeps the project's own layers
ok - fm-control relaunch: a harness switch resets model and effort unless they are named too
ok - fm-control relaunch: a prefixed recorded harness can switch adapters transactionally
ok - fm-control relaunch: a prefixed command requires an explicit replacement harness
ok - fm-control relaunch: a same-harness relaunch keeps the profile axes it was running with
ok - native Ultra relaunch preserves its profile and rejects an unsupported model before stopping
ok - fm-control relaunch: a signed-out worker account pin refuses before the old agent stops
ok - fm-control relaunch: the replacement follows the home's current worker account pin
ok - fm-control relaunch: a declared account list keeps the account the task records
ok - fm-control relaunch: only an explicit --account moves a task to another declared account
ok - fm-control relaunch: undeclared, newline-split, signed-out, unrecorded, retired, and wrong-runner accounts refuse before the old agent stops
ok - fm-control relaunch: mate pins are re-read for Claude and Pi, and unusable pins refuse before stopping the agent
ok - fm-control relaunch: a Pi replacement keeps the home's tool exclusions
ok - fm-control relaunch: exclusion-list refusals happen before the running agent stops
ok - fm-control relaunch: explicit model and effort win over the recorded ones
ok - fm-control relaunch: refuses to relaunch onto an adapter with no verified mechanics
ok - fm-control relaunch: the retired incarnation's global turn-end token is revoked
ok - fm-control relaunch: wiring cleanup failure refuses replacement arming
ok - fm-control-lib: one owner resolves each harness's turn-end registry entry, and refuses a malformed token
ok - fm-control relaunch: a secondmate relaunch re-resolves its durable configured harness pin
ok - fm-control relaunch: a claude secondmate keeps settings.local.json and retires the state settings file and the Stop pointer
ok - fm-control relaunch: a mate with a per-mate override line lands on that override, not the default pin
ok - fm-control relaunch: a mate with no override line still resolves the default pin
ok - fm-control relaunch: a legacy secondmate pin file still relaunches the mate onto its first line
ok - fm-control relaunch: an unparseable secondmate pin refuses before anything is stopped
ok - fm-control relaunch: invalid configured effort is ignored before stop
ok - fm-control relaunch: an adapter unverified for this task kind refuses before the agent is stopped
ok - fm-control relaunch: explicit secondmate harness resets unnamed profile axes
ok - fm-control relaunch: a ship task keeps its recorded harness instead of re-reading crew config
ok - fm-spawn --relaunch: with no explicit harness it reuses the task's recorded one, never the crew default
ok - fm-spawn --relaunch: a promoted scout with a recorded custom branch relaunches on it instead of being refused
ok - fm-promote/fm-spawn --relaunch: the current ship contract supersedes stale scout delivery text
ok - fm-spawn --relaunch: wiring armed under a prefixed harness name is still retired
ok - fm-spawn --relaunch: switching away from muse retires its session binding
ok - fm-spawn --relaunch: switching away from cursor retires its session binding
ok - fm-control relaunch: an unaccountable local copy refuses before the agent is touched
ok - fm-control relaunch: a worker with nothing to work from is never launched
ok - fm-control relaunch: a refusal before the agent is stopped leaves the durable record untouched
ok - fm-control relaunch: checkpoint inspection failures refuse before stopping
ok - fm-control relaunch: a launch failure after the stop keeps the prior record and reports the real state
ok - fm-control relaunch: unpublished rollback keeps concurrent durable metadata
ok - fm-control relaunch: post-publication failure keeps the new durable record
ok - fm-control relaunch: partial stop reconciles actual agent state
ok - fm-control relaunch: failed journal replacement preserves durable phase
ok - fm-spawn relaunch: prepublication abort removes replacement state
ok - fm-control relaunch: the checkpoint records the exact unlanded work it preserved
ok - fm-control relaunch: a secondmate's child work is accounted for and its charter is left alone
ok - fm-control relaunch: a secondmate home that is not this secondmate's is refused
ok - fm-control relaunch: unreadable child records fail checkpoint
ok - fm-control relaunch: unlistable state fails checkpoint
ok - fm-control relaunch: a vanished watcher scratch file does not fail the child-record checkpoint
ok - fm-control relaunch: two control actions on one task serialize instead of interleaving
ok - fm-spawn relaunch: direct entry participates in lifecycle serialization
ok - fm-promote: promotion participates in lifecycle serialization
ok - fm-spawn --relaunch: refuses to launch a second agent into a live endpoint
ok - fm-spawn --relaunch: symlinked records refuse before inspection
ok - fm-spawn --relaunch: keeps its early meta lock continuous
ok - fm-spawn --relaunch: pending closes refuse before replacement begins
ok - fm-spawn --relaunch: every identity axis comes from the record, and a contradicting flag refuses
ok - fm-spawn --relaunch: an unrecorded task is refused
ok - fm-spawn --relaunch: refuses to start a replacement outside the copy holding its work
ok - tmux: a window absent from its session refuses both verbs rather than being assumed gone
ok - tmux: an unfindable session refuses both verbs, so a live agent is never duplicated
ok - tmux: a dead server on this socket refuses both verbs rather than proving absence
ok - reclaim: an unclassifiable endpoint is still refused, so two agents cannot share one
ok - fm-spawn --relaunch: resumes the bound Pi session only for a Pi registration
ok - reclaim: a herdr pane that outlived its stopped server is adopted, never orphaned beside a new tab
ok - fm-control exit: a herdr pane that outlived its stopped server is already-stopped, not gone
ok - reclaim: a herdr rebind is created in the session the record names, never the ambient one
ok - reclaim: a herdr agent that came back with its server refuses, so one worktree keeps one agent
ok - reclaim: a herdr reclaim rebinds the endpoint and leaves the whole rest of the task alone
ok - reclaim: a herdr secondmate whose endpoint is gone is sent to its own respawn owner
ok - reclaim: a rebind refused from a plain shell reports the real cause, not a fabricated session mismatch
ok - relaunch re-reads the backlog item instead of blindly re-running the transition
ok - relaunch heals an item that drifted out of In flight while the task stayed live
ok - away supervision relaunches existing In-flight and queued items under the saturated fresh-spawn spend cap
Evidence: quota helper test log

Source: quota helper test log

ok - each declared account prints its own quota row, read under its own root
ok - a model-specific scope is printed only for that model
ok - exhausted, 0%, and unreadable accounts print facts and uncertainty without a verdict
ok - a projected exhaustion prints each account's own runway seconds and confidence without a verdict
ok - a rate-limited account names the vendor's reason
ok - ordinary is measured from the default ~/.claude root
ok - an absent or malformed list refuses before any quota read
# all fm-claude-account-quota tests passed

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - medium risk

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 2 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Quota helper reports a declared real account as a data-only row, with no verdict or choice ✅ pass live quota-helper-live.txt
Quota helper refuses with exit 2 when the account list is absent or malformed ✅ pass live quota-helper-live.txt
Spawn with --account launches only on a declared, signed-in account and records it; with no list, launches are unchanged ⏸️ untested no The prior payload did not establish a live result. Only the script test (fm-worker-account.log) covered this, not a live Claude worker spawn.
Relaunch keeps the recorded account, moves only on an explicit --account, and refuses undeclared or signed-out accounts ⏸️ untested no The prior payload did not establish a live result. Only the script test (fm-control-relaunch.log) covered this. A live two-account relaunch needs a second signed-in CLAUDE_CONFIG_DIR.
Live lab spawn of a Claude worker on a second subscription ⏸️ untested no Only one Claude login (~/.claude) exists on this host, and signing in a second account is forbidden here. To run it, provide a second signed-in CLAUDE_CONFIG_DIR.
  • bash tests/fm-claude-account-quota.test.sh
  • bash tests/fm-worker-account.test.sh
  • bash tests/fm-control-relaunch.test.sh
  • FM_HOME=$LAB bin/fm-claude-account-quota.sh in a disposable lab home with no list, a malformed list, and a list naming the real ~/.claude
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; all previous findings are addressed and no new blocking issue was found.

Reviews (2) · Last reviewed commit: "fix(bin): close account-list review gaps..." · Reviewed by Greptile

Comment thread bin/fm-worker-account-lib.sh Resolved
Comment thread bin/fm-claude-account-quota.sh Resolved
Comment thread bin/fm-spawn.sh Resolved
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @omkarbhale. This is a careful take on #7638, and the design notes made the diff quick to follow. Holding the quota helper to data only, with no choice of its own, is the right call.

What I checked (head d85f6955, main 3fbace9f): without config/claude-accounts, fm_worker_account_list prints nothing and fm_worker_account_select takes today's pin path unchanged. --account refuses without the list, and having the list and the single pin together refuses too. A listed entry goes through the same directory check, sign-in check and credential stripping as a pin, and it's recorded as account=. Relaunch reuses the recorded entry unless you pass an explicit --account. No workflow, network or credential-write changes. Your fork runs needed a first-time approval, and I've approved them: CI 40664738139 and Require no-mistakes 40668353085. The no-mistakes attestation matches this head.

Before this can merge, please look at Greptile's three P1s. They match what I see in the code:

  1. Account membership check (bin/fm-worker-account-lib.sh, grep -qxF -- "$account"): a --account value containing a newline is split into several patterns, so $'/some/dir\nordinary' passes when ordinary is declared. Please refuse control characters in the argument, or compare whole entries (for example a while read loop with string equality). A regression test for that would be great.
  2. Runway time (bin/fm-claude-account-quota.sh): rows show runway=<status> but not the finite runway seconds. The skill's completion-time gate needs those seconds, so please print them for each applicable scope, from the same snapshot.
  3. Remote second mates (bin/fm-spawn.sh): --account is accepted and then silently dropped on the remote second mate route. Please refuse it there before the remote branch, the same way the local second mate path already does.

On live validation: your body describes live runs against two real subscriptions for spawn, relaunch and the refusals, and that covers the two scenarios the pipeline marked untested. Thank you. After the fixes, a git push no-mistakes re-raise will bind the attestation to the new head and give us fresh CI.

For context, #5444 and #5288 are still open in this area. Your credits section already notes this PR is the narrower, current one, so I'm leaving both as they are.

contract-class: opt-in. Everything is gated on a new captain-declared config/claude-accounts, and with no list the launch path is unchanged. VISION: aligns rule by rule. One captain: fewer stalls on a single exhausted account. Authority: only accounts the captain declares, choice at intake, explicit switching. Scripts/agents: the helper prints facts and the skill ranks. Restart: the account is recorded and reused. Delegation: same refusals. Vendor: Claude-only, inside the existing harness adapter. Scope: no new daemon or score, and AGENTS.md grows by only two lines.

This is waiting on you for the three fixes above plus a re-raise. Thanks again!

…list

Add an opt-in config/claude-accounts list of Claude config directories.
When it is present, every Claude ship or scout spawn names one declared
entry with --account; that entry passes the same root, raw-command, and
stripped-environment `claude auth status` refusals as config/claude-account,
and is recorded as account= on the spawn line and in the task record.
A relaunch or recovery keeps the recorded account, and only an explicit
`fm-control.sh <id> relaunch --account <entry>` moves a task to another
declared account. Without the list nothing changes and --account refuses.

bin/fm-claude-account-quota.sh measures each declared account in isolation
with `quota-axi --provider claude --profile-only` and shows the highest
known spendPriority, escalating on a tie or when nothing is rankable, so
the existing quota-array-dispatch procedure can rank accounts.

Refs kunchenguid#7638
quota-axi exits nonzero when it cannot measure a provider, such as when the
Claude quota endpoint rate-limits a burst of reads, but still prints a valid
snapshot naming that state. fm-claude-account-quota.sh now keeps that
snapshot, so the account is reported unmeasured with the vendor's reason
instead of as an unreadable root.
…condmates

- Refuse an --account value holding a control character, and match it
  against each whole declared entry, so a newline can no longer pass
  membership on one line or split the account= record.
- Print each scope's usableRunwaySeconds and the runway's
  projectionConfidence in fm-claude-account-quota.sh rows, so the
  runway floor has the time it needs; confidence was previously always
  dropped because the snapshot carries it under runway.
- Refuse --account on every secondmate spawn before the remote route,
  which previously accepted and ignored it.
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @omkarbhale. Your four commits landed through #8121, which rebased them onto current main and kept your authorship, so I'm closing this one as superseded. Really appreciate the careful work on #7638.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants