Skip to content

feat: let each firstmate home choose its own Claude account - #3

Merged
ktapa merged 2 commits into
mainfrom
fm/claude-account-split
Sep 22, 2026
Merged

ktapa merged 2 commits into
mainfrom
fm/claude-account-split

Conversation

@ktapa

@ktapa ktapa commented Sep 22, 2026

Copy link
Copy Markdown
Owner

Summary

Lets each firstmate home choose which Claude account (the CLAUDE_CONFIG_DIR login folder) its Claude agents run on, with a per-worker override, and makes that choice survive every relaunch and automatic recovery.

Previously fm-spawn.sh only forwarded firstmate's own CLAUDE_CONFIG_DIR, and fm-control.sh relaunch re-ran the launch in the caller's environment, so an automatic restart (bootstrap liveness sweep, stuck-worker recovery) could silently move a worker or secondmate to a different account.

What changed

  • config/claude-config-dir (home-local, gitignored, not inherited by secondmate homes): one absolute folder path, or default for Claude's own default store.
  • Resolution for claude launches, first match wins:
    1. explicit --claude-config-dir <folder|default> on fm-spawn.sh or fm-control.sh <id> relaunch
    2. on a relaunch or same-home secondmate respawn, the value recorded by the task's previous launch
    3. the target home's config/claude-config-dir (the secondmate's own home for --secondmate)
    4. the launching firstmate's own CLAUDE_CONFIG_DIR
    5. Claude's default store
  • Validation: every source must be default or an existing absolute directory; otherwise the launch refuses before any endpoint exists. fm-control relaunch checks an explicit override before stopping the running agent.
  • Durability: the resolved value is recorded as claude_config_dir= among the launch-time keys (after model=/effort=), is owned by the relaunch rewrite so it is never duplicated, and stays ahead of the terminal PR identity block. Switching a worker off claude drops it.
  • The override is refused for non-claude harnesses and for remote secondmates (whose remote home's own setting governs).
  • default is distinct from naming ~/.claude: Claude (2.1.278) keeps a separate .claude.json inside any explicitly named folder.
  • New sourced helper bin/fm-claude-account-lib.sh; docs in docs/configuration.md "Claude account", plus pointers in AGENTS.md, docs/agent-control.md, the claude harness reference, and secondmate-provisioning.

Tests

  • New tests/fm-spawn-claude-account.test.sh: precedence, default pinning, non-claude launches, batch forwarding, secondmate own-home account, secondmate respawn reuse, and refusals (non-claude override, missing/relative/empty folders from every source, unreadable config, remote secondmate).
  • tests/fm-control-relaunch.test.sh: recorded account reused regardless of caller environment or home setting, explicit move persists through later restarts, override refusals happen before the agent stops, harness switch drops the key, and a regression that a task carrying claude_config_dir= plus pr= keeps its merge poll armed before and after relaunch.
  • Mutation check: disabling recorded reuse makes the secondmate respawn test fail with the exact original bug.
  • Validated through the no-mistakes pipeline (review, test, document, lint, push all passed; PR and CI steps skipped because this fork has no CI).

Known environment-only failures on the development host, unrelated to this change and reproduced on the unmodified base: tests/fm-test-run.test.sh needs ruby, and two 2-second trace-timing waits in tests/fm-control-relaunch.test.sh are too short for a slow host (the whole file passes with those waits lengthened).

🤖 Generated with Claude Code

A claude launch now resolves its login folder (CLAUDE_CONFIG_DIR) from, in
order: an explicit per-worker --claude-config-dir, the folder recorded by the
task's previous launch on a relaunch or secondmate respawn, the target home's
config/claude-config-dir (the secondmate's own home for --secondmate), the
launching firstmate's own CLAUDE_CONFIG_DIR, then Claude's default store.

Every source is validated as `default` or an existing absolute directory
before any endpoint exists, and the resolved value is recorded as
claude_config_dir= among the launch-time keys, ahead of the PR identity
block, so relaunch and automatic recovery never silently move a worker to
another account. fm-control relaunch accepts the same override and checks it
before stopping the running agent. The setting is home-local and is not
inherited by secondmate homes.
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.

1 participant