Skip to content

Fix CLI entrypoint detection on Windows (all scripts exit silently) - #12

Open
GOODMAN-PRO wants to merge 1 commit into
neilsonnn:mainfrom
GOODMAN-PRO:fix/windows-cli-entrypoint
Open

Fix CLI entrypoint detection on Windows (all scripts exit silently)#12
GOODMAN-PRO wants to merge 1 commit into
neilsonnn:mainfrom
GOODMAN-PRO:fix/windows-cli-entrypoint

Conversation

@GOODMAN-PRO

Copy link
Copy Markdown

All 15 CLI scripts under .claude/scripts/ use this run-as-main guard:

if (import.meta.url === `file://${process.argv[1]}`) { main(); }

On Windows this never matches: process.argv[1] is a backslashed path with a drive letter (C:\...\script.mjs), so the template produces file://C:\...\script.mjs, while import.meta.url is a proper file URL (file:///C:/.../script.mjs). Every script therefore exits silently with code 0 without running main() — no error, no output, which makes the whole CLI pipeline appear broken on Windows.

Fix: build the comparison with pathToFileURL(), which normalizes separators and drive letters on every platform:

if (import.meta.url === (await import("node:url")).pathToFileURL(process.argv[1]).href) {

Verified on Windows 11 / Node 24: before the change node .claude/scripts/project/indexed-path.mjs exits 0 with no output; after, it runs main() and prints usage as expected. Behavior on macOS/Linux is unchanged.

🤖 Generated with Claude Code

The run-as-main guard compared import.meta.url against
`file://${process.argv[1]}`, which never matches on Windows:
process.argv[1] uses backslashes and a drive letter
(C:\...\script.mjs) while import.meta.url is a proper file URL
(file:///C:/.../script.mjs). Every CLI script therefore exited
silently with code 0 without running main().

Use url.pathToFileURL() to build the comparison URL instead, which
normalizes separators and drive letters on all platforms. Applied to
all 15 scripts under .claude/scripts/.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant