Skip to content

Expand leading ~ in Codex home paths before exporting CODEX_HOME#2210

Merged
juliusmarminge merged 3 commits intopingdotgg:mainfrom
altjx:tilde-expansion
Apr 20, 2026
Merged

Expand leading ~ in Codex home paths before exporting CODEX_HOME#2210
juliusmarminge merged 3 commits intopingdotgg:mainfrom
altjx:tilde-expansion

Conversation

@altjx
Copy link
Copy Markdown
Contributor

@altjx altjx commented Apr 19, 2026

Summary

Spawned processes don't inherit shell tilde expansion, so a Codex homePath of ~/.codex-work in the server settings was being passed to the child Codex process verbatim as CODEX_HOME=~/.codex-work. The receiver then treats ~ as a relative directory name rather than $HOME, so state ends up in the wrong place (or fails to load existing config).

This PR adds a small expandHomePath() helper and applies it everywhere the Codex homePath setting flows into a CODEX_HOME env var passed to a spawned child:

  • CodexAppServerManager spawn + CLI version check
  • CodexTextGeneration spawn
  • CodexProvider.runCodexCommand spawn (health check)
  • probeCodexDiscovery spawn

The helper handles ~ alone, ~/…, and ~\… — matching the behavior of the other three expandHomePath implementations already in the tree (os-jank.ts, WorkspaceEntries.ts, WorkspacePaths.ts). Only ~ and ~//~\ are expanded; ~user (other-user) is intentionally left alone, same as the existing helpers.

Notes for reviewers

  • Scope is narrow on purpose: only the CODEX_HOME env var that gets propagated to child processes. readCodexConfigModelProvider in CodexProvider.ts also uses homePath as a direct filesystem path (for config.toml) and has the same latent bug, but that's a separate read path — happy to fold that in if you'd prefer a single PR, or leave as a follow-up.
  • There are now four expandHomePath helpers in apps/server/src/. Consolidating them is an easy follow-up, but I kept this PR focused on the user-visible bug. The new helper is a plain function (not Effect-based) because some of the call sites (probeCodexDiscovery, parts of codexAppServerManager) are plain async functions.

Test plan

  • vitest run src/pathExpansion.test.ts — new unit tests (empty, ~, ~/…, ~\…, ~user pass-through, non-tilde pass-through) all pass
  • vitest run for the touched files (codexAppServerManager.test.ts, CodexTextGeneration.test.ts, pathExpansion.test.ts) — 60 passing, 1 skipped, 0 failing
  • tsc --noEmit clean
  • Manually verified locally: Codex sessions with homePath: ~/.codex-work now land in the correct home directory instead of a literal ~ folder

Note

Low Risk
Low risk: a small, well-tested path normalization helper applied only to CODEX_HOME env propagation for spawned Codex CLI/app-server processes.

Overview
Fixes Codex homePath values like ~/.codex-work being passed literally to child Codex processes by expanding a leading ~ before exporting CODEX_HOME.

Adds a new expandHomePath() utility (with unit tests) and applies it across all Codex process spawn points, including app-server startup, CLI version checks, provider health checks, discovery probing, and Git text generation.

Reviewed by Cursor Bugbot for commit 3463ac5. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Expand leading ~ in CODEX_HOME paths before passing to Codex CLI subprocesses

Adds a new expandHomePath utility in pathExpansion.ts that resolves a leading ~, ~/, or ~\ to the current user's home directory via os.homedir(). Applies this expansion to CODEX_HOME in all locations where Codex CLI subprocesses are spawned: the app-server session, version check, text generation, provider command execution, and discovery probing.

Macroscope summarized 3463ac5.

altjx and others added 3 commits April 19, 2026 13:51
Spawned processes don't inherit shell tilde expansion, so a Codex
homePath of ~/.codex-work was being passed to the child verbatim as
CODEX_HOME=~/.codex-work. The receiver then treats ~ as a relative
directory name rather than $HOME, so state ends up in the wrong place
(or fails to load existing config).

Add an expandHomePath() helper that turns a leading ~ or ~/… into
the current user's home directory, and apply it everywhere the Codex
homePath setting flows into CODEX_HOME: the text-generation spawn,
the discovery probe, the app-server manager spawn and version check,
and the Codex provider health check. Leaves other-user (~alice)
expansion out — only ~ and ~/… are handled.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The other three expandHomePath helpers in this repo (os-jank.ts,
WorkspaceEntries.ts, WorkspacePaths.ts) accept both `~/` and `~\`
prefixes. Match that behavior in the new pathExpansion helper so a
Windows user who types `~\.codex` into provider settings gets the same
expansion as `~/.codex`.

Also add a small test file covering the shape of the helper (empty,
unchanged, `~`, `~/…`, `~\…`, and `~user` pass-through).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 19, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4b9a8a78-70fe-4ebe-98df-d8c9010f3d68

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Apr 19, 2026
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Apr 19, 2026

Approvability

Verdict: Approved

Straightforward bug fix that expands ~ in paths before passing them to spawned processes. The new utility function is simple, well-tested, and applied consistently across all CODEX_HOME usages. No complex logic or side effects beyond fixing incorrect path handling.

You can customize Macroscope's approvability policy. Learn more.

@juliusmarminge juliusmarminge enabled auto-merge (squash) April 20, 2026 00:03
@juliusmarminge juliusmarminge merged commit 20f346d into pingdotgg:main Apr 20, 2026
12 checks passed
aaditagrawal added a commit to aaditagrawal/t3code that referenced this pull request Apr 20, 2026
Upstream additions:
- fix(web): restore manual sort drag and keep per-group expand state (pingdotgg#2221)
- fix: Change right panel sheet to be below title bar / action bar (pingdotgg#2224)
- Refactor OpenCode lifecycle and structured output handling (pingdotgg#2218)
- effect-codex-app-server (pingdotgg#1942)
- Redesign model picker with favorites and search (pingdotgg#2153)
- fix(server): prevent probeClaudeCapabilities from wasting API requests (pingdotgg#2192)
- fix(server): handle OpenCode text response format in commit message gen (pingdotgg#2202)
- Devcontainer / IDE updates (pingdotgg#2208)
- Expand leading ~ in Codex home paths before exporting CODEX_HOME (pingdotgg#2210)
- fix(release): use v<semver> tag format for nightly releases (pingdotgg#2186)

Fork adaptations:
- Took upstream's redesigned model picker with favorites and search
- Removed deleted codexAppServerManager (replaced by effect-codex-app-server)
- Stubbed fetchCodexUsage (manager-based readout no longer available)
- Extended PROVIDER_ICON_BY_PROVIDER for all 8 fork providers
- Extended modelOptionsByProvider test fixtures for all 8 providers
- Inline ClaudeSlashCommand type (not yet re-exported from SDK)
- Updated SettingsPanels imports for new picker module structure
- Preserved fork's CI customizations (ubuntu-24.04 not Blacksmith)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants