fix(compile): use execPath for process.argv[1] in standalone binaries#32990
Merged
bartlomieju merged 4 commits intomainfrom Mar 26, 2026
Merged
fix(compile): use execPath for process.argv[1] in standalone binaries#32990bartlomieju merged 4 commits intomainfrom
bartlomieju merged 4 commits intomainfrom
Conversation
In compiled (standalone) binaries, `process.argv[1]` was set to the internal temp extraction path (e.g. `/tmp/deno-compile-foo/main.ts`) instead of the binary path. This caused npm CLI tools like `@google/gemini-cli` to see the temp path as a positional argument, breaking their argument parsing. For standalone binaries, `process.argv[1]` now uses `Deno.execPath()` (the compiled binary path), matching Node.js SEA behavior where `argv[0]` and `argv[1]` both point to the executable. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
looks good overall. one thing i'd want covered before merging: the new spec only exercises the unix path (
|
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
re-reviewed. the windows |
bartlomieju
added a commit
that referenced
this pull request
Mar 26, 2026
…ry relaunches When Node.js apps (e.g. @google/gemini-cli) relaunch themselves via `spawn(process.execPath, [process.argv[1], ...args])`, the standalone binary would include the exe path as a user argument in `Deno.args` / `process.argv`. This is because `process.argv[1]` in standalone mode is the exe path (set by #32990), and the binary's arg parser only skipped `argv[0]`. Now the standalone binary detects when the first CLI arg matches the current exe path and strips it, preventing the path from leaking into user arguments. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3 tasks
bartlomieju
added a commit
that referenced
this pull request
Mar 26, 2026
…ry relaunches (#33016) ## Summary Fixes an issue where compiled npm CLI tools that relaunch themselves (e.g. `@google/gemini-cli`) would have the binary path leak into `process.argv` as a user argument. When Node.js apps relaunch themselves they typically do: ```js spawn(process.execPath, [process.argv[1], ...userArgs]) ``` In standalone binaries `process.argv[1]` is the exe path (set by #32990), so the child process receives the exe path as its first CLI argument. The standalone arg parser only skipped `argv[0]`, so the duplicate exe path ended up in `Deno.args` / `process.argv`, causing yargs-based CLIs to misinterpret it as a positional argument. For example, running compiled `gemini` would show the binary path pre-filled as the initial prompt, because yargs parsed `/Users/x/.deno/bin/gemini` as a positional arg. ## Fix In `cli/rt/binary.rs`, detect when the first CLI arg (after skipping `argv[0]`) matches the current executable path and strip it. This handles the standard Node.js relaunch pattern without affecting normal usage. --------- Co-authored-by: Claude Opus 4.6 (1M context) <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.
Summary
In compiled (standalone) binaries,
process.argv[1]was set to the internaltemp extraction path (e.g.
/tmp/deno-compile-foo/path/to/main.ts) instead ofthe binary path. This caused npm CLI tools like
@google/gemini-clito see thetemp path as a positional argument, breaking their argument parsing.
For example, running
gemini -p "hello"would fail with:because the temp path leaked into
process.argvand was parsed as a positional argby yargs.
Fix
For standalone binaries (
Deno.build.standalone),process.argv[1]now usesDeno.execPath()(the compiled binary path), matching Node.js SEA behaviorwhere
argv[0]andargv[1]both point to the executable.Related: #28915 (fixes
argv[0], this PR fixesargv[1])Test plan
compile::standalone_process_argvverifiesargv[1] === Deno.execPath()and user args start atargv[2]@google/gemini-cli🤖 Generated with Claude Code