Skip to content

fix: ensure standard PATH is available for external CLIs#285

Merged
jackwener merged 1 commit intojackwener:mainfrom
jicaiji1-max:fix/external-cli-path
Mar 23, 2026
Merged

fix: ensure standard PATH is available for external CLIs#285
jackwener merged 1 commit intojackwener:mainfrom
jicaiji1-max:fix/external-cli-path

Conversation

@jicaiji1-max
Copy link
Contributor

Problem

When calling external CLIs (like opencode), child processes may not find system commands like sysctl because the PATH environment variable does not include standard system paths.

This causes errors like:

error: Executable not found in $PATH: "sysctl"

Solution

Add standard paths to the environment when spawning external CLI processes.

Test Case

# Register opencode
opencli register opencode --binary /usr/local/bin/opencode --desc "OpenCode AI coding agent"

# Before fix: fails with sysctl not found
opencli opencode --version

# After fix: works correctly
opencli opencode --version
# Output: 1.2.20

Fixes #284

Copy link
Contributor

@Astro-Han Astro-Han left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix for a real problem — sysctl not found makes sense when PATH is stripped. Two things to watch for:

process.env.PATH can be undefined

If PATH is unset, the template string produces "undefined:/usr/local/bin:..." — a literal undefined directory in the search path. A quick guard:

const currentPath = process.env.PATH || '';

isBinaryInstalled() uses a different PATH

The new env is only passed to spawnSync, but isBinaryInstalled() (line 68, uses which) still runs with the original process.env. If a binary exists only in a standard path like /usr/sbin, isBinaryInstalled returns false while spawnSync would find it — leading to unnecessary install prompts.

Some environments (GUI apps, cron, IDE terminals) launch with a minimal
PATH that excludes standard directories like /usr/local/bin and /usr/sbin.
This causes external CLIs to fail when they try to run system commands
(e.g. sysctl).

Fix by ensuring standard system paths exist in process.env.PATH at
startup. This is a one-time fix that benefits ALL child processes —
isBinaryInstalled(), installExternalCli(), daemon spawn, etc. — without
needing per-call env patching.

Fixes jackwener#284
@jackwener jackwener force-pushed the fix/external-cli-path branch from 421a6e4 to 2da2ef3 Compare March 23, 2026 07:55
@jackwener jackwener merged commit 22f5c7a into jackwener:main Mar 23, 2026
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.

fix: Ensure standard PATH is available for external CLIs

3 participants