Repository navigation
getBundledCliPath() resolves @github/index.js (one dir too high) on Node with import.meta.resolve #1849
Description
Activity
- addedquestionFurther information is requestedFurther information is requested
on Jun 30, 2026 github-actions commented
on Jun 30, 2026 on Jun 30, 2026 – with GitHub ActionsContributorMore actionsInvestigation 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 viagetCliPlatformPackageNames(). On Windows x64 that returns@github/copilot-win32-x64; on macOS arm64 it returns@github/copilot-darwin-arm64. It is not resolving@github/copilotat all.Why the dirname math is correct
I verified against the live npm registry that the platform packages export
sdkas./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/sdkdirname(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.jserror would not occur with current codeThat error would only arise if the
sdkexport pointed to a file at the package root level (e.g.sdk.jsnotsdk/index.js), requiring only onedirnameinstead of two. The actual packages use./sdk/index.jsin a subdirectory, so twodirnamecalls 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 founderrors in practice, it may be due to a corrupted/partial package installation or a non-standard module resolution environment. The documentedCOPILOT_CLI_PATHenv var workaround bypasses this resolution entirely.Generated by Bug Handler for issue #1849 · sonnet46 1.3M · ◷
Closing as fixed after verification against the current public SDK sources and bundled behavior.
Public evidence
- #2395 — Launch managed SDK servers through the Rust runtime wrapper (merged 2026-09-01)
- #2463 — Use Copilot CLI releases for Node runtime (merged 2026-09-03)
- commit
538b2dce3075— Launch managed SDK servers through the Rust runtime wrapper (Launch managed SDK servers through the Rust runtime wrapper #2395) - commit
ec1c6f4b6368— Use Copilot CLI releases for Node runtime (Use Copilot CLI releases for Node runtime #2463) nodejs/src/runtimeArtifacts.ts—ensureRuntimeBundle; getRuntimePackageNamenodejs/test/runtimeArtifacts.test.ts—resolves the installed platform runtime without network accessnodejs/test/runtimeArtifacts.test.ts—uses the SDK platform package namespace
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.
Summary
CopilotClient'sgetBundledCliPath()resolves the CLI entry to a path one directory too high when the@github/copilotpackage is installed and the running Node hasimport.meta.resolve. It returns.../node_modules/@github/index.jsinstead of.../node_modules/@github/copilot/index.js, so startup throws:even though
@github/copilotis correctly installed.Root cause
In the
import.meta.resolvebranch, the path is derived as:dirname(dirname(sdkPath))strips two segments. For a resolvedsdkentry living under@github/copilot/..., twodirnamecalls land on@github/(the scope dir), so the joined result is@github/index.js— the wrong package level. The non-import.meta.resolvefallback branch (require.resolve.pathsloop) correctly targets@github/copilot/index.js, which is why the bug only reproduces on newer Node whereimport.meta.resolveis 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 toPATH), it works — which masks the bug.Workaround
Set
COPILOT_CLI_PATHto a launch-verified entry (e.g..../@github/copilot/index.jsornpm-loader.js); the client honors it beforegetBundledCliPath().Suggested fix
Use a single
dirname(or resolve the package root viarequire.resolve('@github/copilot/package.json')) so both branches agree on@github/copilot/index.js.Environment
Windows, Node v24/v25,
@github/copilotCLI 1.0.61–1.0.66, embeddedCopilotClientSDK.(AI-assisted report, filed via an automated agent.)