Skip to content

fix(daemon): persist CODEX_SWITCH_HOME into installed services (#60) - #64

Merged
xjoker merged 1 commit into
devfrom
cursor/daemon-persist-codex-switch-home-5a91
Aug 26, 2026
Merged

fix(daemon): persist CODEX_SWITCH_HOME into installed services (#60)#64
xjoker merged 1 commit into
devfrom
cursor/daemon-persist-codex-switch-home-5a91

Conversation

@xjoker

@xjoker xjoker commented Aug 25, 2026

Copy link
Copy Markdown
Owner

Fixes #60.

Problem

daemon install writes a LaunchAgent (macOS), systemd user unit (Linux), or Task Scheduler command (Windows) that forwards only HOME and CODEX_HOME into the daemon's environment. If the user relocated state with CODEX_SWITCH_HOME, the installed service still read the default ~/.codex-switch — so it could poll a stale/empty profile set and rewrite the wrong account's live ~/.codex/auth.json.

Fix

At install time, capture CODEX_SWITCH_HOME from the installing process (when set and non-empty) and bake it into the generated service definition on all three platforms:

  • macOS: an extra CODEX_SWITCH_HOME key in the plist EnvironmentVariables dict (XML-escaped).
  • Linux: an extra Environment="CODEX_SWITCH_HOME=…" line (systemd-quoted).
  • Windows: an extra set "CODEX_SWITCH_HOME=…" && in the Task Scheduler command.

When the variable is unset/empty, the definitions are byte-for-byte unchanged, so default installs are unaffected. The value is read at install time; changing it later requires re-running daemon install (documented).

Tests

src/daemon/service.rs:

  • Existing generator tests updated to the new signature and assert the key is absent when no override is set.
  • New: launchd_plist_forwards_codex_switch_home_when_set, systemd_unit_forwards_codex_switch_home_when_set, windows_task_scheduler_command_forwards_codex_switch_home_when_set (including escaping/quoting of special characters).

Docs

Updated the wiki Configuration.md caveat and Troubleshooting.md row to describe the new capture-at-install behavior instead of the manual workaround.

Verification (Linux)

cargo fmt --check, cargo clippy --all-targets --all-features -- -D warnings, cargo test --all — all pass, 0 failed.

Note: the CI Format and audit job will be red until #63 (webbrowser RUSTSEC-2026-0257 lockfile bump) merges to dev; that failure is pre-existing and unrelated to this change.

Open in Web Open in Cursor 

@xjoker
xjoker marked this pull request as ready for review August 25, 2026 23:43
daemon install wrote a LaunchAgent/systemd/Task Scheduler definition that
forwarded only HOME and CODEX_HOME. With a relocated store the installed
service fell back to the default ~/.codex-switch, so it could poll a stale
profile set and rewrite the wrong account's live ~/.codex/auth.json.

Capture CODEX_SWITCH_HOME from the installing process (when set and
non-empty) and bake it into the generated service definition on all three
platforms. Unset leaves the definitions unchanged. Update the wiki caveat
and troubleshooting entry to match.

Co-authored-by: xJoker <xjoker@users.noreply.github.com>
@cursor
cursor Bot force-pushed the cursor/daemon-persist-codex-switch-home-5a91 branch from 520c9d5 to dbf19e5 Compare August 26, 2026 06:52
@xjoker
xjoker merged commit 4e00810 into dev Aug 26, 2026
4 checks passed
@cursor
cursor Bot deleted the cursor/daemon-persist-codex-switch-home-5a91 branch August 26, 2026 07:04
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