Skip to content

fix(codex): respect CODEX_HOME when reading auth for usage - #1138

Open
AndrewSB wants to merge 1 commit into
get-bb:mainfrom
AndrewSB:fix/codex-home-usage-respect-env
Open

fix(codex): respect CODEX_HOME when reading auth for usage#1138
AndrewSB wants to merge 1 commit into
get-bb:mainfrom
AndrewSB:fix/codex-home-usage-respect-env

Conversation

@AndrewSB

@AndrewSB AndrewSB commented Aug 7, 2026

Copy link
Copy Markdown

Problem

Codex thread execution correctly respected CODEX_HOME via resolveCodexHome() in list-commands.ts (process.env.CODEX_HOME?.trim() || path.join(homeDir, ".codex")), but codex-auth.ts (used for bb settings usage) hardcoded ~/.codex/auth.json.

This caused a split state when using a second account via CODEX_HOME:

Fix

Extract resolveCodexHome() helper in codex-auth.ts that checks process.env.CODEX_HOME first, matching existing logic in list-commands.ts and archive-codex-tmp-bb-sessions.ts.

function resolveCodexHome(): string {
  return process.env.CODEX_HOME?.trim() || path.join(os.homedir(), ".codex");
}
function codexAuthPath(): string {
  return path.join(resolveCodexHome(), CODEX_AUTH_RELATIVE_PATH[1]);
}

Repro

  1. Have two Codex auths: ~/.codex and ~/.codex-second with different accounts
  2. Add systemd override /root/.config/systemd/user/bb-server.service.d/codex-home.conf:
    [Service]
    Environment=CODEX_HOME=/root/.codex-second
  3. systemctl --user restart bb-server
  4. Spawn Codex thread: shows second account ✅
  5. bb settings usage --json: shows first account ❌ (before fix), second after fix ✅

Verification

After patch + restart:

bb settings usage --json now returns:

{
  "codex": {
    "accountEmail": "asbreckenridge+automation@gmail.com",
    "planLabel": "Team",
    "usedPercent": 0
  }
}

Matches actual thread auth.

Codex thread execution already respected CODEX_HOME via
resolveCodexHome() in list-commands.ts, but codex-auth.ts used
a hardcoded ~/.codex path for bb settings usage.

This caused:
- threads spawned via bb used the correct account (second account via CODEX_HOME env on host-daemon)
- Settings -> Usage / bb settings usage --json still showed the main account from ~/.codex/auth.json

Fix by extracting resolveCodexHome() that checks process.env.CODEX_HOME first,
matching the logic in list-commands.ts and archive-codex-tmp scripts.

Repro:
1. Set CODEX_HOME=/root/.codex-second with different auth
2. Add systemd drop-in Environment=CODEX_HOME=...
3. Restart bb-server
4. Spawned threads correctly show second account, but usage shows first

After fix: usage shows asbreckenridge+automation@gmail.com (0% used) instead of asbreckenridge@gmail.com (64%).
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