Fix CLI entrypoint detection on Windows (all scripts exit silently) - #12
Open
GOODMAN-PRO wants to merge 1 commit into
Open
Fix CLI entrypoint detection on Windows (all scripts exit silently)#12GOODMAN-PRO wants to merge 1 commit into
GOODMAN-PRO wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
All 15 CLI scripts under
.claude/scripts/use this run-as-main guard:On Windows this never matches:
process.argv[1]is a backslashed path with a drive letter (C:\...\script.mjs), so the template producesfile://C:\...\script.mjs, whileimport.meta.urlis a proper file URL (file:///C:/.../script.mjs). Every script therefore exits silently with code 0 without runningmain()— 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:Verified on Windows 11 / Node 24: before the change
node .claude/scripts/project/indexed-path.mjsexits 0 with no output; after, it runsmain()and prints usage as expected. Behavior on macOS/Linux is unchanged.🤖 Generated with Claude Code