Repository navigation
feat(bin): switch Claude seats for new workers without moving running ones - #4
Merged
Merged
Conversation
Add a way to choose which Claude account (seat) new workers run on, with a one-command manual switch and an optional configurable threshold. A seat is a Claude Code profile directory named by CLAUDE_CONFIG_DIR. Claude Code derives that profile's macOS Keychain service name from a hash of the directory path, so each seat has its own credential store and a worker pointed at a profile that was never logged in stops with "Not logged in" rather than spending the default account. The safety property: a switch changes only what the NEXT worker gets. fm-spawn resolves the seat once per fresh spawn, pre-registers Claude workspace trust in that same profile, and records it as claude_seat= in the task's own record. Every relaunch reads that record instead of re-resolving the setting, so a switch never moves a live or relaunched worker. That is a correctness requirement, not only a billing one: a task's session history lives under its profile directory, so moving it would strand the session. bin/fm-seat.sh is the one command: list, status, probe, add, switch <name>, switch --next, threshold, arm, retire. A switch to a profile with no credentials is refused. `add` creates an empty profile directory and prints the login command; nothing here logs in, copies a credential, or touches the Keychain - the account owner signs a seat in personally. The automatic path reuses the existing condition-to-action watch rather than adding a daemon: condition `threshold-reached`, action `switch --next`. It fires at most once, which is the edge trigger, and is off until a threshold is configured. An unreadable quota is an error, never a crossing. Settings are absent by default, so an unconfigured home behaves exactly as before, and are inherited into secondmate homes.
Rotation now covers only named seats under the seats root. The default profile is the account owner's own interactive login: it changes account whenever they sign in somewhere else, and nothing here can tell which account it currently holds, so an automatic switch must never land workers on it. `switch default` stays available as an explicit, manual choice. The seat set is read fresh from the seats root on every step, so nothing assumes which seats exist or that any particular one is present. Also fix a narrow relaunch regression this change surfaced: a task recorded before seats existed carries no claude_seat line, and its launches always took firstmate's own ambient CLAUDE_CONFIG_DIR. Falling through to the bare default would have moved exactly the kind of task the recorded-seat rule exists to leave alone, so a relaunch now keeps that ambient profile. The home's active seat is still never consulted on a relaunch. Docs state plainly that the sign-in prompts in a fresh profile, and the effect of a second login on the default session, are written from documented behaviour rather than an observed sign-in, because verifying them would mean logging in.
A directory literally named "default" under the seats root was listed as a seat but refused by every switch, because that name is reserved for the ambient login. Skip it in the listing, and refuse "add default" with the reason.
…ude seat recording
`fm_seat_logged_in` reported "not logged in" whenever every credential source was skipped, including when the Keychain itself could not be read. That conflates "the store says there is no login" with "the store could not be consulted", and the second establishes nothing. Measured read-only against the installed quota-axi on macOS, with no sign-in performed: a profile that was never logged into and a profile that IS signed in but whose one-time Keychain approval has not been granted produce the same report - every source skipped, the keychain unreachable. A signed-in and approved profile instead reports the keychain read as successful. So the unreachable shape cannot tell the first two apart, and treating it as proof of absence refused a correctly signed-in seat with no way through - the state an owner is in moments after logging a seat in, and one that `--force` could not cross because `--force` must never cross a proven-empty verdict. A not-logged-in verdict now requires that every credential source was actually consulted and came back empty. On macOS that is rarely reachable, because an absent Keychain entry reads as unreadable; on a file-backed store, where an empty profile really can be read and found empty, it is reported as before. An undecided read is what `--force` may cross, and crossing it is safe: a forced switch to a genuinely empty seat stops the next worker on its first message with "Not logged in" rather than spending another account. The docs already described this behaviour, so this brings the code up to them and states which probe states can be told apart and which cannot.
…chine-local and propagated
…es via --local-only
max-metaplanet
added a commit
that referenced
this pull request
Oct 6, 2026
… ones Carried from fork commit bd1c981 (#4). Conflict resolutions: AGENTS.md takes upstream's restructure, which replaced the inline operational-home layout tree with a one-line pointer to the `operational-home-layout` skill. The seat entry this commit added to that tree is re-homed into the skill beside the worker account pin, so the layout keeps exactly one owner and the always-loaded file does not regain the lines upstream moved out. bin/fm-config-inherit-lib.sh unions the inheritable set: upstream's newer `dispatch-never-send`, `keep-ai-trailers`, and `supervision-host-off` items stay alongside the three seat items. The machine-local list is kept as its own fork divergence, because a seat is a per-machine profile the owner logged in here and a remote home handed its name would resolve a profile nobody logged in there. bin/fm-spawn.sh keeps upstream's worktree re-assert and then resolves the seat, which must stay ahead of trust pre-registration so the trust entry lands in the profile the worker will actually read. The relaunch-preserved metadata key list unions both sides: upstream's `branch`, `base_branch`, and `control_relaunch_tx` with this commit's `claude_seat`. docs/scripts.md unions the two row descriptions, which gained independent detail: upstream's ship-branch prefix on `fm-project-mode.sh` and this commit's `--local-only` on `fm-config-push.sh`.
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.
Why this was built now
The captain stopped the whole fleet to change Claude seats: four homes interrupted, one worker needing two interrupts. Switching accounts should not cost a fleet-wide interruption, which is what this change removes.
Which probe states can be told apart, and which cannot
Measured read-only against the installed
quota-axion macOS, with no sign-in performed:status: successand the provider source isoauth.keychain_unreachable.Because those two collapse into one observable state, the probe reports them as undecided rather than as "not logged in". A plain
switchrefuses both;switch --forceis the owner accepting that uncertainty, which is safe because a forced switch to a genuinely empty seat stops the next worker on its first message withNot logged inrather than spending another account. Anot-logged-inverdict, which--forcenever crosses, requires that every credential source was actually consulted and came back empty - rarely reachable on macOS, reported normally on a file-backed store.Follow-up worth considering
This change and the usage-warner feature being built in parallel now make the same
quota-axi --json --full --no-credential-refreshcall. They may want to become one shared read rather than two independent pollers.Intent
i want to see if it unblocks a way for easy switching of seats when threshold is approached
no lets not wait for 5pm -- build the thing now we can test by building and testing switching not waiting. the threshold should be configurable and also manually triggered e.g. if i want to switch 'now' then mechanism should allow for it easy
Build a way to switch which Claude account (seat) firstmate's workers run on. Three parts were asked for explicitly: the switching mechanism itself; a configurable threshold, not a hardcoded one; and a manual trigger - "switch now" must be one easy command, independent of any threshold. The manual trigger is the primitive the automatic path sits on and the half that can be tested immediately.
The safety property that stands: switching must never disturb a worker already running. New workers go to the new seat; existing ones finish where they started. A mechanism that moves live work is an outage, not a switch. A worker's seat must survive relaunch and resume, because a silent fallback to the default profile is that same failure in disguise.
Credentials: the account owner logs into the second seat personally. Nothing here logs in, copies a credential between profiles, or writes to a credential store. Exactly what the owner must do to set up a second seat is part of the deliverable.
Context: an earlier review of the third-party tool claude-swap argued against automatic switching because it fires exactly at the limit, when every worker is mid-task, so all of them move accounts at once. That decision is held with two blockers - upstream token-destroying bugs, and an unanswered terms-of-service question about the tool presenting itself as Claude Code - and stays untouched: this is firstmate's own mechanism on a Claude Code primitive, CLAUDE_CONFIG_DIR, that the review found underneath that tool's safe isolation. Do not install claude-swap or borrow its code.
What Changed
bin/fm-seat.shandbin/fm-seat-lib.sh, which choose the Claude account ("seat") that new claude workers launch on. A seat is a separateCLAUDE_CONFIG_DIRprofile. The command has these subcommands:status,list,switch <name|default>/switch --next(manual switch, refused for a seat that isn't logged in unless--forceis given),probe,add(creates an empty profile directory and prints the login command for the account owner, but never logs in or touches a credential),threshold [<percent>|off],threshold-reached, andarm/retire.armsets up a one-shotfm-procevent-when.shwatch that runsswitch --nextwhen the active seat's remaining quota falls to the configured threshold. There is no default threshold. Automatic rotation only uses named, logged-in seats and never picks the default profile. After a switch,fm-config-push.sh --local-only(new flag, which skips remote routes) sends the setting to local secondmate homes.bin/fm-spawn.shworks out the seat once for each fresh Claude spawn. It pre-registers workspace trust in that profile, launches withCLAUDE_CONFIG_DIRset to it, and writesclaude_seat=to the task record. A Claude-to-Claude relaunch reuses the recorded seat, so a switch never moves a live, relaunched or resumed worker. Records from before seats existed keep the ambient default. Non-claude harnesses record no seat.config/claude-seat,config/claude-seats-rootandconfig/claude-seat-thresholdfiles are inherited by local secondmates but marked machine-local, so they are never sent to remote routes. The quota "most constraining availability" jq logic moved into a sharedquota_effectivehelper infm-quota-axi-lib.sh, andfm-quota-choose.shnow uses it. Addeddocs/claude-seats.md(operator and owner login procedure) plus updates to the configuration and scripts docs. Addedtests/fm-seat.test.sh, and extendedtests/fm-control-relaunch.test.shto cover relaunches keeping their seat.Risk Assessment
Testing
I ran the two targeted suites (fm-seat and fm-control-relaunch) and both passed. I drove the real fm-seat.sh CLI in a throwaway home, first with the installed quota-axi on freshly created empty seat profiles, then with a stubbed quota report covering signed-in seats, threshold crossings and rotation. I fired the armed threshold watch through its real watcher child. In a guarded Herdr lab I spawned two real Claude workers either side of a seat switch. Every live scenario passed: the running worker's record and live process kept seats/work after the switch to spare, and the new worker launched on spare. The lab was torn down with its tripwire intact, and I removed the scratch treehouse pool. Relaunch/resume seat preservation, secondmate propagation and remote exclusion were proven only by the automated tests with fake backends, not live. No UI surface is involved; the evidence is CLI transcripts.
fm-seat.sh add workcreates an empty profile dir, prints the exact login command, and touches no credentialCLAUDE_CONFIG_DIR=... claude+ /login instructionsfm-seat.sh switch work --force, then the real fm-spawn claude worker ran with CLAUDE_CONFIG_DIR=seats/work and its record carried claude_seat=seats/work; after `switch spare…fm-seat.sh statuslisted A on work and B on spareunknown(exit 2),switch workwas refused with config unchanged, andswitch work --forcesucceededswitch nosuch --forcegave error 'has no profile directory' (exit 1),switch ../escape --forcegave 'invalid seat name' (exit 1), and the active seat stayed workthreshold 15set it; threshold-reached on an unreadable real quota still exited 2switch --nextonce when the threshold is crossed, rotating only among named seatsarm, then the realfm-procevent-when.sh run when-claude-seatchild moved the active seat work -> spare;retirestopped the watch. Part B also showed that --next rotates…tests/fm-control-relaunch.test.sh, which uses a fake backend. A live check needs a lab session where the earlier real…tests/fm-seat.test.sh; the live CLI switches found no live secondmate homes. A live check needs a r…Evidence: Live CLI transcript: manual switch, guards, threshold, rotation, armed watch firing
Source: Live CLI transcript: manual switch, guards, threshold, rotation, armed watch firing
Evidence: CLI transcript driver script
Source: CLI transcript driver script
Evidence: Live Herdr lab: real claude workers across a seat switch (records + process env)
Source: Live Herdr lab: real claude workers across a seat switch (records + process env)
Evidence: Herdr lab driver script
Source: Herdr lab driver script
Evidence: tests/fm-seat.test.sh output
Source: tests/fm-seat.test.sh output
Evidence: tests/fm-control-relaunch.test.sh output
Source: tests/fm-control-relaunch.test.sh output
Evidence: Running worker keeps its seat across a switch (lab excerpt)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-spawn.sh:1666- A relaunch that changes harness gets the wrong seat, or leaves a stale seat line. fm-control.sh supportsrelaunch --harness <name>. (1) Codex to claude: a codex task spawned while seatspareis active records no claude_seat line, as the earlier decision requires. Afterfm-control.sh <id> relaunch --harness claude, SEAT_CONFIG_DIR falls back to firstmate's ambient CLAUDE_CONFIG_DIR. The new claude session, which has no prior Claude history to protect, therefore launches silently on the default profile, not the active seat. That is the owner's interactive login, which rotation deliberately avoids and which may be the account that just hit its threshold. Line 4513 also never writes claude_seat on a relaunch. (2) Claude to codex: preserve_relaunch_meta carries claude_seat forward onto the codex record, sofm-seat.sh statuslists a codex worker as running on a Claude seat. That reintroduces the misreporting the user asked to fix in seat-recorded-for-non-claude. Suggested fix: when a relaunch's prior harness is not claude and the new harness is claude, resolve fm_seat_spawn_config_dir and record it. When the new harness is not claude, drop the claude_seat line. Which account a harness-switched relaunch should bill to is a product choice, so confirming it is needed.bin/fm-config-inherit-lib.sh:71- claude-seat and claude-seats-root are added to FM_INHERITABLE_CONFIG. The header of that file says the same list is the allowlist for remote routes (fm-remote-inherit-push.sh / fm-remote-inherit.sh). A remote secondmate on another machine therefore receivesclaude-seat=work. It resolves the seat to$HOME/.claude-seats/workon the remote host, or to the primary's absolute claude-seats-root path, which may not exist there. The owner never logged that profile in, so every claude crewmate the remote home spawns stops withNot logged in. Before this change those crewmates used the remote's working default login. A seat is a per-machine Keychain-backed profile, and docs/claude-seats.md itself says 'every home on the machine'. Options: keep the seat items local-only for remote routes, or make spawn fall back or refuse when the seat directory is missing. Which one is right is a policy decision about inheritance scope.bin/fm-seat.sh:214- write_active changes only the primary's config/claude-seat. Inherited items are copied only at convergence points: secondmate spawn, bootstrap, and fm-config-push. So after a manualswitch nowor an automatic threshold switch, a running secondmate keeps spawning claude crewmates on the old seat until the next convergence. The docs say secondmates 'launch on the same seat as the primary's'. It is worth either running the config push after a switch or saying in the docs that a push is required.🔧 Fix applied.
1 warning still open:
bin/fm-seat.sh:277- The user asked for the existing convergence to run 'for local secondmate homes', but propagate_to_secondmates runs the whole bin/fm-config-push.sh. That script also walks every remote secondmate record (fm-config-push.sh:122-170). So every manual or automatic seat switch opens an SSH inherit push to each remote host, carries any other pending inherited config across with it, and can send remote reread nudges, even though remote homes never receive seat settings. If a remote host is down, the push exits non-zero, and cmd_switch prints 'not every secondmate home was updated ... those homes keep spawning on their previous seat'. That is wrong for a remote home, which never had a seat to begin with. It also means an automatic threshold switch waits on SSH to other machines. Concrete case: the primary has one local and one unreachable remote secondmate, and the owner runsfm-seat.sh switch work. The local home updates, the remote SSH fails, and the owner is told a home is still on the previous seat when that home has no seat. The smallest fix is to limit the push to local routes, for example a local-only mode in fm-config-push.sh that skips records with remote_host. That adds an option to a shared script, and the user said to reuse the script and write no new propagation path, so the remedy needs the user's sign-off.🔧 Fix applied.
1 info still open:
bin/fm-seat.sh:129-live_task_seatsprints a line for everystate/*.metarecord, whatever its harness. A codex, opencode or other non-Claude task, which now correctly records noclaude_seat, still shows up under 'live workers keep the seat they launched with' as(ambient default login). That tells the reader the task runs on the owner's default Claude login. Concrete case: seatspareis active, a codex task is spawned, andfm-seat.sh statuslists it as<id> (ambient default login). That weakens status as evidence of which workers a switch left alone, which is the goal behind the round-1 seat-recorded-for-non-claude fix. Fix: skip records whoseharness=is not claude, or print the harness in place of the seat for them.🔧 **Test** - 1 issue found → auto-fixed ✅
bin/fm-seat.sh:238-fm-seat.sh switch nosuch --forcesucceeds (live: 'switched: default -> nosuch') even though no directory exists under the seats root. fm_seat_dir only builds the path and never checks that it exists, and the missing profile probes as unknown, which --force crosses. So one typo in a forced manual switch sends every new claude worker to a profile that doesn't exist, andlistnever shows that seat. Those workers stop at login or onboarding, so no other account gets spent, but the error message 'does not resolve to a profile directory' suggests a missing seat was meant to be refused. Suggested fix: refuse a named seat whose directory does not exist, even with --force.fm-seat.sh switch seat-maxand the active seat for new workers changes immediately (one command, no threshold needed)switch --nextwhen the threshold is crossed, oncefm-seat.sh statuslists both separately; each worktree's trust entry…fm-spawn.sh w1 --relaunchwith lab-b active writes a new launch script with CLAUDE_CONFIG_DIR=.../lab-a; the meta still says lab-a; the new claude pid has lab-a in its en…CLAUDE_CONFIG_DIR=... claudeand /login instructions; 'default' and '../evil' are refusedswitch --nextandarmboth refusebin/fm-seat.sh list / probe seat-max / status / switch seat-max(isolated FM_HOME, seats root ~/.claude-seats, real quota-axi)bin/fm-seat.sh threshold abc|0|101|-5|15%|15|60|100|offandthreshold-reachedagainst real quota for seat-max (stale, rate-limited) and seat-max2 (fresh, ~39%)bin/fm-seat.sh add lab-a,add default,add ../evil,probe lab-a,switch lab-a,switch lab-a --force,switch --next,armwith a single empty seatbin/fm-seat.sh arm --interval 20 --stable 1thenbin/fm-procevent-when.sh run when-claude-seat(fired: seat-max2 -> seat-max), thenretireHerdr labfm-lab-seatlab-94718-30252via bin/fm-herdr-lab.sh provision/run/teardown:fm-spawn.sh w1 --harness claude --backend herdron seat lab-a,fm-seat.sh switch lab-b --force,fm-spawn.sh w2, checked meta, the launch script, the process env, the trust entry per profile, and the pane screenstopped the lab w1 claude process, thenfm-spawn.sh w1 --relaunchwhile lab-b was active; checked the recorded seat, the new launch script, and the process envbash tests/fm-seat.test.sh(31 ok)bash tests/fm-control-relaunch.test.sh(72 ok)🔧 Fix applied.
✅ Re-checked - no issues remain.
fm-seat.sh add workcreates an empty profile dir, prints the exact login command, and touches no credentialCLAUDE_CONFIG_DIR=... claude+ /login instructionsfm-seat.sh switch work --force, then the real fm-spawn claude worker ran with CLAUDE_CONFIG_DIR=seats/work and its record carried claude_seat=seats/work; after `switch spare…fm-seat.sh statuslisted A on work and B on spareunknown(exit 2),switch workwas refused with config unchanged, andswitch work --forcesucceededswitch nosuch --forcegave error 'has no profile directory' (exit 1),switch ../escape --forcegave 'invalid seat name' (exit 1), and the active seat stayed workthreshold 15set it; threshold-reached on an unreadable real quota still exited 2switch --nextonce when the threshold is crossed, rotating only among named seatsarm, then the realfm-procevent-when.sh run when-claude-seatchild moved the active seat work -> spare;retirestopped the watch. Part B also showed that --next rotates…tests/fm-control-relaunch.test.sh, which uses a fake backend. A live check needs a lab session where the earlier real…tests/fm-seat.test.sh; the live CLI switches found no live secondmate homes. A live check needs a r…bash tests/fm-seat.test.sh(all fm-seat tests passed)bash tests/fm-control-relaunch.test.sh(all passed, including the claude->claude, codex->claude and claude->codex seat transitions)seat-cli-live.shPart A: realfm-seat.shin a throwaway FM_HOME with the REAL installed quota-axi: status, add work/spare, list, probe, refused switch,switch work --force,switch nosuch --force,switch ../escape --force, threshold unset/set 15, threshold-reached, switch defaultseat-cli-live.shPart B: stubbed quota report (work/spare signed in): list, switch, status, threshold-reached with all_models 50%/model:opus 1% (exit 1) and all_models 12% (exit 0),switch --nextrotation work->spare->workseat-cli-live.shPart C:fm-seat.sh arm --interval 1 --stable 1, then the real watcher childfm-procevent-when.sh run when-claude-seatfiredswitch --next(work -> spare), thenfm-seat.sh retireseat-herdr-lab-live.sh: guardedfm-herdr-lab.shsession fm-lab-seatlive-*:fm-seat.sh switch work --force, realfm-spawn.sh seat-lab-a --backend herdrlaunching real claude,ps ewwof that claude pid,fm-seat.sh switch spare --force,fm-spawn.sh seat-lab-b, re-inspected A's record and process,fm-seat.sh status, fm-teardown, lab teardown✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.