Skip to content

fix(claude-accounts): quote resolved claude path for Windows shell spawn - #10237

Merged
OrcaWin merged 2 commits into
stablyai:mainfrom
ghoon4:fix-claude-account-spawn-quoting
Jul 24, 2026
Merged

OrcaWin merged 2 commits into
stablyai:mainfrom
ghoon4:fix-claude-account-spawn-quoting

Conversation

@ghoon4

@ghoon4 ghoon4 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #10236

Problem

runClaudeCommand spawns the resolved claude CLI with shell: true on Windows, but spawn concatenates the command into the cmd.exe line without quoting. When the CLI resolves to a path with spaces (any C:\Users\First Last\... profile, npm install), cmd.exe splits at the first space and every Claude account operation (add, status) fails with:

'C:\Users\First' is not recognized as an internal or external command

Fix

Quote the resolved command when it will pass through the Windows shell, mirroring what the codebase already does for the same situation in claude-pty.ts (cmd.exe /c "<quoted path>", "ensure the command path is properly quoted if it contains spaces") and quoteWindowsCmdArg in ai-vault-types.ts. Non-Windows spawn (shell: false) is unchanged; the WSL branch was never affected.

Tests

  • New regression test: on win32, a resolved path containing spaces is passed to spawn quoted, with shell: true.
  • Updated the existing uses taskkill to cancel the Windows Claude login process tree expectation to the quoted command ('"claude"') — the intended behavior change.
  • Converted the module-level resolveClaudeCommand mock to a vi.hoisted + vi.fn so a single test can override the resolved path without doUnmock wiping the hoisted mock for later tests.
  • vitest run src/main/claude-accounts/service.test.ts: 26/26 pass (on a Windows host with a space in the profile path — previously 2 of these tests could only pass on hosts without one).
  • oxlint and tsc --noEmit -p config/tsconfig.node.json clean on the touched files.

Verified end-to-end on Windows 11 (profile C:\Users\Ji Hoon, claude 2.1.218 under %APPDATA%\npm): reproducing the exact resolve + shell: true spawn fails unquoted and succeeds quoted.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 11ce52be-62d3-4bea-8c86-3c87c01893fe

📥 Commits

Reviewing files that changed from the base of the PR and between c7c80d4964075ffb4b5c92b6d712d7835d44be3b and a656763.

📒 Files selected for processing (5)
  • config/scripts/claude-account-windows-spawn-repro.mjs
  • src/main/claude-accounts/service.test.ts
  • src/main/claude-accounts/service.ts
  • src/main/claude-accounts/windows-command-invocation.test.ts
  • src/main/claude-accounts/windows-command-invocation.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/main/claude-accounts/windows-command-invocation.test.ts
  • src/main/claude-accounts/windows-command-invocation.ts
  • src/main/claude-accounts/service.ts
  • src/main/claude-accounts/service.test.ts
  • config/scripts/claude-account-windows-spawn-repro.mjs

📝 Walkthrough

Walkthrough

Windows Claude command execution now builds explicit cmd.exe invocations with escaped paths and arguments. Process termination uses Windows taskkill.exe with timeout handling and non-Windows process-group fallbacks. Tests cover Windows path quoting, WSL execution, login cancellation, and invalid command tokens. A Windows-only repro harness validates argument preservation, error handling, and process-tree cleanup.

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is on-topic but misses several required template sections, including Screenshots, AI Review Report, Security Audit, and Notes. Add the missing template sections and include the required testing checklist, AI review report, security audit, screenshots note, and notes.
Out of Scope Changes check ⚠️ Warning Most changes support the Windows quoting fix, but the large repro harness and termination-flow rewrite go beyond #10236's scope. Remove or justify the extra repro and termination changes so the PR stays focused on quoting the resolved Claude path on Windows.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main Windows quoting fix in this PR.
Linked Issues check ✅ Passed The quoted Windows spawn fix and regression coverage satisfy #10236's requirements without changing the non-Windows or WSL behavior.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

ghoon4 and others added 2 commits July 23, 2026 17:11
runClaudeCommand spawns the resolved claude command with shell:true on
Windows, but spawn concatenates the command into the cmd.exe line without
quoting. When the CLI resolves to a path containing spaces (e.g.
C:\Users\First Last\AppData\Roaming\npm\claude.cmd), cmd.exe splits at the
first space and account add fails with:

  'C:\Users\First' is not recognized as an internal or external command

Quote the command the same way claude-pty.ts and quoteWindowsCmdArg
already do for other Windows spawns.

Co-Authored-By: Claude Fable 5 <[email protected]>

@OrcaWin OrcaWin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the precise report and Windows reproduction. The diagnosis is correct, and quoting the resolved command does fix the common profile-path-with-spaces case.

Requesting changes because the current shell:true boundary still lets cmd.exe interpret valid path and argument characters. On a physical Windows host with Node 24 and a real .cmd shim:

  • The reported spaced and Unicode path passed with this PR.
  • A valid path containing %ORCA_PATH_TRAP% was environment-expanded and no longer addressed the intended command.
  • Empty and spaced arguments were lost or split.
  • &, |, <, >, ^, and % arguments were interpreted by cmd.exe; the > case physically redirected output and created a file.
  • Node emitted DEP0190 because arguments passed with shell:true are concatenated without escaping.
  • Error propagation and taskkill tree cancellation passed for the ordinary spaced-path case.

Please move ownership of the complete Windows command line into Orca: invoke ComSpec explicitly with /d /v:off /s /c, use shell:false plus windowsVerbatimArguments:true, quote every command/argument token, and protect percent expansion outside quoted spans. Keep the WSL branch ahead of native Claude resolution so WSL remains independent, and wait for taskkill completion before cleaning up the managed auth directory.

The regression test should supplement spawn mocks with a real Windows .cmd fixture under a temporary path containing spaces, Unicode, &, ^, parentheses, %, and !. It should capture exact argv/env, cover empty/spaced and cmd-metacharacter arguments, stderr/exit status, and verify taskkill removes the shell/child/grandchild tree.

This is a good issue diagnosis and a useful contribution; the requested change is specifically about making the Node-to-cmd.exe authority boundary safe enough to merge.

@OrcaWin
OrcaWin dismissed their stale review July 24, 2026 00:25

Addressed by maintainer follow-up commit c7c80d496; awaiting GitHub CI.

@OrcaWin
OrcaWin force-pushed the fix-claude-account-spawn-quoting branch from c7c80d4 to a656763 Compare July 24, 2026 00:27
@OrcaWin
OrcaWin merged commit 87c59dd into stablyai:main Jul 24, 2026
1 check passed
nwparker added a commit that referenced this pull request Jul 24, 2026
This reverts commit 8f40ddf (#10179).

Rebased on current main. The revert applied cleanly across the vast majority
of the 1,626-file PR; the remaining work was preserving PRs that had been built
on top of #10179 after it merged. All are preserved:

- #9990  perf(terminal): cold-restore replay
- #10213 fix(codex): TUI settings promotion
- #10135 fix(mobile): images in native chat
- #9387  fix(status-bar): Resource Manager badge + concurrent listSessions
- #9853  fix(app): bound wake/quit paths (phone-session-ended freeze)
- #10237 fix(claude-accounts): quote claude path for Windows (kept shell:false)

Because those PRs were written against helper modules/APIs that #10179
introduced, the minimal, typecheck-verified closure they depend on is kept so
the tree builds and every later-PR test passes:

- bounded file/JSON readers used by #10213/#9990 (agent-state-file-reader,
  node-bounded-file-reader, json-text-structure-limit, terminal-history limits)
- claimed-agent-pty-owner cap API + pty:listSessions admission (#9990/#9387)
- the mobile-E2EE outbound-memory-budget subsystem #9853 builds on
  (e2ee-channel, mobile-e2ee-*, ws-outbound-backpressure-queue,
  remote-runtime-request-frames/-memory-limits, map-with-concurrency, e2ee-crypto)

Everything else #10179 added (~555 files) is deleted; every file it modified
elsewhere is restored to its pre-#10179 state.

Verified: root typecheck (node+cli+web), mobile typecheck, full root test suite,
full mobile test suite, oxlint, localization catalog + coverage, reliability
gates, max-lines ratchet, and the CLI emit build all pass. Two checks fail only
locally and fail identically on clean origin/main (this clone's git-tag
namespace for verify:skill-bundle-manifest; an inherited GIT_CONFIG_* env for
one relay test) — both pass on a clean CI environment.

Co-authored-by: Orca <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…awn (stablyai#10237)

* fix(claude-accounts): quote resolved claude path for Windows shell spawn

runClaudeCommand spawns the resolved claude command with shell:true on
Windows, but spawn concatenates the command into the cmd.exe line without
quoting. When the CLI resolves to a path containing spaces (e.g.
C:\Users\First Last\AppData\Roaming\npm\claude.cmd), cmd.exe splits at the
first space and account add fails with:

  'C:\Users\First' is not recognized as an internal or external command

Quote the command the same way claude-pty.ts and quoteWindowsCmdArg
already do for other Windows spawns.

Co-Authored-By: Claude Fable 5 <[email protected]>

* fix(claude-accounts): own Windows cmd invocation

---------

Co-authored-by: Claude Fable 5 <[email protected]>
Co-authored-by: OrcaWin <[email protected]>
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.

[Bug]: Claude account add fails on Windows when the user profile path contains a space (unquoted shell spawn)

2 participants