Skip to content

fix: resolve default Codex home from USERPROFILE on Windows#21

Merged
Wangnov merged 1 commit into
mainfrom
fix/windows-codex-home-userprofile
Jun 18, 2026
Merged

fix: resolve default Codex home from USERPROFILE on Windows#21
Wangnov merged 1 commit into
mainfrom
fix/windows-codex-home-userprofile

Conversation

@Wangnov

@Wangnov Wangnov commented Jun 18, 2026

Copy link
Copy Markdown
Owner

Problem

On Windows, when neither CODEX_HOME nor --codex-home is set, codex-threadripper derived the default Codex home as $HOME/.codex, reading only the HOME environment variable.

Codex itself locates its home on Windows via dirs::home_dir(), which resolves from USERPROFILE and ignores HOME. When a process injects HOME into the environment (e.g. an app pointing it at %APPDATA%\<app>), the two diverge: Codex writes its DB under C:\Users\<user>\.codex, while threadripper looked under %APPDATA%\<app>\.codex and failed with:

no Codex state database found under C:\Users\...\AppData\Roaming\SPB_16.6\.codex (looked at state_5.sqlite and sqlite/state_5.sqlite) — run Codex at least once to create it

Fix

Introduce a pure home_base_from_env(userprofile, home, is_windows) that resolves the default home base:

  • Windows: prefer USERPROFILE, fall back to HOME (for shells like Git Bash/MSYS that only set HOME)
  • Unix: keep HOME
  • empty values are skipped

The call site passes the platform via cfg!(windows), so both branches compile and are unit-tested on every platform.

Testing

  • New home_base_prefers_userprofile_on_windows covers: Windows prefers USERPROFILE (ignoring a hijacked HOME), falls back to HOME when USERPROFILE is missing/empty, Unix uses only HOME, plus an end-to-end repro of the reported issue.
  • Local cargo fmt --check / cargo test --locked (73 passed) / cargo clippy --locked --all-targets -- -D warnings all green.
  • codex exec review --commit HEAD: no actionable regressions.

Compatibility

  • Unix behavior unchanged.
  • On Windows where HOME == USERPROFILE (the common case) the result is unchanged; only when HOME is overridden does it now follow USERPROFILE, matching Codex.
  • Explicit --codex-home / CODEX_HOME precedence is unchanged.

When neither --codex-home nor CODEX_HOME is set, the default home base
was taken solely from $HOME. On Windows a process that injects HOME
(e.g. an app pointing it at %APPDATA%\<app>) sent threadripper to the
wrong .codex, while Codex itself locates its home via dirs::home_dir(),
which resolves from USERPROFILE and ignores HOME there. That mismatch
surfaced as "no Codex state database found under ...\<app>\.codex".

Resolve the default home base through a new home_base_from_env(): prefer
USERPROFILE on Windows (HOME stays as a fallback for Git Bash/MSYS),
keep HOME on Unix. Add cross-platform unit coverage and correct the
--codex-home help text.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Wangnov Wangnov merged commit 1104349 into main Jun 18, 2026
8 checks passed
@Wangnov Wangnov deleted the fix/windows-codex-home-userprofile branch June 18, 2026 05:31
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