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.)

Activity

  1. transferred this issue fromgithub/copilot-clion Jun 30, 2026
  2. github-actions commented on Jun 30, 2026

    @github-actions
    Contributor

    Investigation Results

    Thanks for the detailed report. After analyzing the code and verifying against the published npm packages, this does not appear to be a bug — the current behavior is correct. Reclassifying as a question.

    What I investigated

    Code path: nodejs/src/client.ts — getBundledCliPath() (line 366)

    What the code actually does

    The issue describes the problematic resolution as using @github/copilot/sdk, but the actual current code uses platform-specific packages via getCliPlatformPackageNames(). On Windows x64 that returns @github/copilot-win32-x64; on macOS arm64 it returns @github/copilot-darwin-arm64. It is not resolving @github/copilot at all.

    Why the dirname math is correct

    I verified against the live npm registry that the platform packages export sdk as ./sdk/index.js (a file inside a subdirectory):

    "./sdk": {
      "types": "./sdk/index.d.ts",
      "import": "./sdk/index.js"
    }
    

    So with sdkPath = .../node_modules/@github/copilot-darwin-arm64/sdk/index.js:

    • dirname(sdkPath) → .../node_modules/@github/copilot-darwin-arm64/sdk
    • dirname(dirname(sdkPath)) → .../node_modules/@github/copilot-darwin-arm64``
    • Result → .../node_modules/@github/copilot-darwin-arm64/index.js ✅

    This is the correct package root. The CJS fallback branch produces the same target path (join(base, ...packageName.split("/"), "index.js")), so both branches agree.

    Why the @github/index.js error would not occur with current code

    That error would only arise if the sdk export pointed to a file at the package root level (e.g. sdk.js not sdk/index.js), requiring only one dirname instead of two. The actual packages use ./sdk/index.js in a subdirectory, so two dirname calls are correct. The thin loader package (@github/copilot) has no exports at all and is never touched by this code path.

    Conclusion

    The code is working as designed. If you are encountering Copilot CLI not found errors in practice, it may be due to a corrupted/partial package installation or a non-standard module resolution environment. The documented COPILOT_CLI_PATH env var workaround bypasses this resolution entirely.

    Generated by Bug Handler for issue #1849 · sonnet46 1.3M · ◷

  3. patniko commented on Sep 8, 2026

    @patniko
    Contributor

    Closing as fixed after verification against the current public SDK sources and bundled behavior.

    Public evidence

    The reported behavior/request is implemented at the current SDK baseline, so this issue is being closed as completed.

    Public SDK baseline: github/copilot-sdk d5c9d06d8c41.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions