Skip to content

getBundledCliPath() resolves @github/index.js (one dir too high) on Node with import.meta.resolve #1849

Description

@MichaelEns

Summary

CopilotClient's getBundledCliPath() resolves the CLI entry to a path one directory too high when the @github/copilot package is installed and the running Node has import.meta.resolve. It returns .../node_modules/@github/index.js instead of .../node_modules/@github/copilot/index.js, so startup throws:

Copilot CLI not found at C:\...\node_modules\@github\index.js. Ensure @github/copilot is installed.

even though @github/copilot is correctly installed.

Root cause

In the import.meta.resolve branch, the path is derived as:

const sdkPath = fileURLToPath(import.meta.resolve("@github/copilot/sdk"));
return join(dirname(dirname(sdkPath)), "index.js");

dirname(dirname(sdkPath)) strips two segments. For a resolved sdk entry living under @github/copilot/..., two dirname calls land on @github/ (the scope dir), so the joined result is @github/index.js — the wrong package level. The non-import.meta.resolve fallback branch (require.resolve.paths loop) correctly targets @github/copilot/index.js, which is why the bug only reproduces on newer Node where import.meta.resolve is present.

Impact

Any host on a recent Node (observed on Node v24.x / v25.x) where the package is present fails to launch the bundled CLI. On older Node (no import.meta.resolve) or where the package is absent (falls back to PATH), it works — which masks the bug.

Workaround

Set COPILOT_CLI_PATH to a launch-verified entry (e.g. .../@github/copilot/index.js or npm-loader.js); the client honors it before getBundledCliPath().

Suggested fix

Use a single dirname (or resolve the package root via require.resolve('@github/copilot/package.json')) so both branches agree on @github/copilot/index.js.

Environment

Windows, Node v24/v25, @github/copilot CLI 1.0.61–1.0.66, embedded CopilotClient SDK.

(AI-assisted report, filed via an automated agent.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions