Skip to content

fix: resolve login shell PATH so codex is found when launched via AppImage/GUI on Linux - #1

Draft
benakdev with Copilot wants to merge 2 commits into
mainfrom
copilot/investigate-codex-cli-issue
Draft

benakdev with Copilot wants to merge 2 commits into
mainfrom
copilot/investigate-codex-cli-issue

Conversation

Copilot AI commented Mar 14, 2026 •

Copy link
Copy Markdown

When launched from a GUI (AppImage, Dock, file manager) rather than a terminal, process.env.PATH is a minimal system PATH that excludes paths added by shell init scripts. Node version managers like fnm/nvm inject their bin dirs via .bashrc/.zprofile, so codex — and node itself — are invisible to the process. This breaks even the custom binary path workaround: the codex npm wrapper is a #!/usr/bin/env node script, so env fails to locate node at spawn time.

What Changed

  • apps/server/src/shellEnv.ts (new) — getSpawnEnv() / resolveLoginShellPath() utilities:

    • On Unix, spawns $SHELL -l -c "echo $PATH" once to capture the full login-shell PATH
    • Takes only the last non-empty output line (guards against init scripts writing to stdout)
    • Caches the result for the server lifetime; falls back to process.env.PATH on any failure
    • Windows: no-op, returns process.env.PATH unchanged
  • codexAppServerManager.ts — replaces inline { ...process.env } spreads with getSpawnEnv() in both the spawnSync version check and the spawn app-server launch

  • ProviderHealth.ts and CodexTextGeneration.ts — pass env: getSpawnEnv() to ChildProcess.make for the health probe and text-generation invocations

  • shellEnv.test.ts (new) — unit tests covering success, multiline stdout, failure fallback, throw fallback, and caching behaviour

Why

The standard fix used by VS Code and similar desktop tools: query the login shell for its PATH once at startup. This ensures version-manager-managed binaries (and their node runtime) are discoverable regardless of how the process was launched.

// Before — PATH never includes fnm/nvm dirs when launched from GUI
env: { ...process.env, ...(codexHomePath ? { CODEX_HOME: codexHomePath } : {}) }

// After — PATH comes from the user's login shell
env: getSpawnEnv(codexHomePath ? { CODEX_HOME: codexHomePath } : undefined)

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…a AppImage/GUI on Linux

When the app is launched from a GUI (AppImage, Dock, file manager) rather than
a terminal, process.env.PATH is a minimal system PATH that omits paths added by
shell init scripts like ~/.bashrc or ~/.zprofile, including paths set up by Node
version managers such as fnm and nvm.

This caused two problems:
1. `codex` could not be found at all, showing "not installed or not on PATH"
2. Even with an absolute custom path, the npm wrapper script failed because
   its `#!/usr/bin/env node` shebang couldn't locate `node` either

Fix: add shellEnv.ts that resolves PATH by spawning the user's login shell once
($SHELL -l -c "echo $PATH"), caches the result, and falls back to process.env.PATH
on any failure. Use getSpawnEnv() in all three places that spawn codex processes.

Co-authored-by: benakdev <[email protected]>
Copilot AI changed the title [WIP] Investigate codex CLI not available on PATH fix: resolve login shell PATH so codex is found when launched via AppImage/GUI on Linux Mar 14, 2026
Copilot AI requested a review from benakdev March 14, 2026 16:59
Copilot stopped work on behalf of benakdev due to an error March 14, 2026 17:23
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