Skip to content

fix: Ensure standard PATH is available for external CLIs #284

@jicaiji1-max

Description

@jicaiji1-max

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:

// src/external.ts
const standardPath = '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin';
const env = {
  ...process.env,
  PATH: `${process.env.PATH}:${standardPath}`,
};
const result = spawnSync(cli.binary, args, { stdio: 'inherit', env });

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

I've already implemented this fix locally and it works. Happy to submit a PR if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions