Skip to content

fix: Resolve windows npx spawn errors#476

Merged
Shironex merged 1 commit intoAutoMaker-Org:v0.11.0rcfrom
DenyCZ:fix/windows-npx
Jan 14, 2026
Merged

fix: Resolve windows npx spawn errors#476
Shironex merged 1 commit intoAutoMaker-Org:v0.11.0rcfrom
DenyCZ:fix/windows-npx

Conversation

@DenyCZ
Copy link
Copy Markdown
Contributor

@DenyCZ DenyCZ commented Jan 13, 2026

Summary

Fixed a spawn of opencode via NPX on Windows devices. Was giving an error
ERROR [Server] Uncaught Exception: { message: 'spawn npx ENOENT', stack: 'Error: spawn npx ENOENT\n' + ' at ChildProcess._handle.onexit (node:internal/child_process:286:19)\n' + ' at onErrorNT (node:internal/child_process:484:16)\n' + ' at process.processTicksAndRejections (node:internal/process/task_queues:89:21)' }

After changes in this PR getting providers, models from CLI and also spawning the opencode process itself is working.

Also added a support for windows machines for pre-commit hook.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Windows compatibility for npm/npx command execution by using appropriate executable formats on Windows systems.
    • Fixed PATH configuration to properly detect Node.js and npm installations on Windows environments.
    • Enhanced subprocess handling to ensure proper execution of commands on Windows platforms.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 13, 2026

📝 Walkthrough

Walkthrough

The changes improve Windows compatibility by implementing OS-aware PATH configuration in the Git pre-commit hook, updating the OpenCode provider to use npx.cmd on Windows with shell execution enabled, and modifying subprocess handling to treat npx and npm as requiring shell invocation on Windows.

Changes

Cohort / File(s) Summary
Windows PATH Configuration
.husky/pre-commit
Replaced unconditional PATH export with OS-aware conditional logic. When WINDIR is set (Windows detection), appends Windows-specific Node.js paths (/c/Program Files/nodejs, /c/Program Files (x86)/nodejs) instead of POSIX paths.
Windows NPX Execution
apps/server/src/providers/opencode-provider.ts
Updated OpenCode CLI invocations to use npx.cmd instead of npx on Windows. Added shell option enablement for .cmd script execution to ensure proper Windows command handling.
Subprocess Shell Handling
libs/platform/src/subprocess.ts
Extended shell requirement detection to treat npx and npm commands as requiring shell on Windows, in addition to .cmd files. Applied to both spawnJSONLProcess and spawnProcess functions.

Suggested labels

Testers-Requested

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Hoppy Windows paths we trace,
Commands leap with proper grace,
Shell and cmd files now align,
Cross-platform magic, oh so fine!
On any OS, Node will run,
Our rabbit work is finally done! 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: fixing Windows npx spawn errors across multiple files (.husky/pre-commit, opencode-provider.ts, and subprocess.ts).
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

🧹 Recent nitpick comments
libs/platform/src/subprocess.ts (1)

204-206: Consider extracting the duplicated needsShell logic.

This condition is identical to the one in spawnJSONLProcess (lines 48-50). Extracting it to a helper function would improve maintainability.

♻️ Optional refactor to extract helper
+/**
+ * Determine if a command needs shell execution on Windows
+ */
+function needsWindowsShell(command: string): boolean {
+  return (
+    process.platform === 'win32' &&
+    (command.toLowerCase().endsWith('.cmd') || command === 'npx' || command === 'npm')
+  );
+}
+
 export async function* spawnJSONLProcess(options: SubprocessOptions): AsyncGenerator<unknown> {
   // ...
-  const needsShell =
-    process.platform === 'win32' &&
-    (command.toLowerCase().endsWith('.cmd') || command === 'npx' || command === 'npm');
+  const needsShell = needsWindowsShell(command);
   // ...
 }

 export async function spawnProcess(options: SubprocessOptions): Promise<SubprocessResult> {
   // ...
-  const needsShell =
-    process.platform === 'win32' &&
-    (command.toLowerCase().endsWith('.cmd') || command === 'npx' || command === 'npm');
+  const needsShell = needsWindowsShell(command);
   // ...
 }
apps/server/src/providers/opencode-provider.ts (2)

754-756: Consider using case-insensitive check for consistency.

The subprocess.ts uses toLowerCase().endsWith('.cmd'), but this check is case-sensitive. While unlikely to cause issues since the command is explicitly set to lowercase npx.cmd, aligning the checks would be more defensive.

♻️ Optional: case-insensitive check
-        shell: process.platform === 'win32' && command.endsWith('.cmd'),
+        shell: process.platform === 'win32' && command.toLowerCase().endsWith('.cmd'),

989-991: Same optional refinement as above for case-insensitivity.

♻️ Optional: case-insensitive check
-        shell: process.platform === 'win32' && command.endsWith('.cmd'),
+        shell: process.platform === 'win32' && command.toLowerCase().endsWith('.cmd'),
📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 32f6c6d and bb70d04.

📒 Files selected for processing (3)
  • .husky/pre-commit
  • apps/server/src/providers/opencode-provider.ts
  • libs/platform/src/subprocess.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Always import from shared packages (@automaker/*), never from old relative paths

Files:

  • libs/platform/src/subprocess.ts
  • apps/server/src/providers/opencode-provider.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use resolveModelString() from @automaker/model-resolver to convert model aliases (haiku, sonnet, opus) to full model names

Files:

  • libs/platform/src/subprocess.ts
  • apps/server/src/providers/opencode-provider.ts
apps/server/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use createEventEmitter() from lib/events.ts for all server operations to emit events that stream to frontend via WebSocket

Files:

  • apps/server/src/providers/opencode-provider.ts
🔇 Additional comments (4)
libs/platform/src/subprocess.ts (1)

48-50: LGTM! Correctly enables shell for bare npx/npm commands on Windows.

This addresses the spawn npx ENOENT error by ensuring Node.js commands are resolved through the shell on Windows, even when not invoked with the explicit .cmd extension.

apps/server/src/providers/opencode-provider.ts (2)

733-735: LGTM! Correct Windows handling for NPX execution.

Using npx.cmd explicitly on Windows ensures proper command resolution and aligns with the shell option added in the exec call.


968-970: LGTM! Consistent Windows handling for auth provider fetch.

Same correct pattern as fetchModelsFromCli.

.husky/pre-commit (1)

34-39: LGTM! Good Windows-aware PATH configuration.

The WINDIR check correctly detects Git Bash on Windows, and the Unix-style paths (/c/Program Files/...) are compatible with the Git Bash environment.

One consideration: $APPDATA and $LOCALAPPDATA should be available in Git Bash, but if they're unset for some reason, the resulting paths would be malformed (e.g., /npm). This is a minor edge case and acceptable given the script already has fallback error handling at lines 47-50.


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 and usage tips.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @DenyCZ, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the compatibility and reliability of the opencode CLI tool on Windows operating systems. It addresses a persistent spawn npx ENOENT error by implementing platform-specific adjustments for npx command execution and ensuring that Node.js tools are correctly located within the system's PATH. These changes enable seamless operation for Windows users, allowing them to effectively utilize opencode for various tasks, including model retrieval and authentication, and also ensures pre-commit hooks function as expected.

Highlights

  • Windows Compatibility Fix: Resolved spawn npx ENOENT errors on Windows by correctly invoking npx.cmd and enabling shell execution for spawn processes, ensuring opencode commands run successfully.
  • Pre-commit Hook Enhancement: Enhanced the .husky/pre-commit hook to include common Windows Node.js installation paths in the PATH environment variable, improving compatibility for development workflows.
  • Subprocess Execution Logic Update: Updated the subprocess utility to automatically use shell execution for npx and npm commands on Windows, preventing execution failures in various contexts.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request resolves an issue with spawning npx on Windows by correctly using npx.cmd and enabling the shell option for child processes. The changes are applied consistently for both spawn and execFile calls. Additionally, the pre-commit hook is updated to support Windows environments by adding relevant paths. The fixes look solid. I've added a couple of suggestions to improve code maintainability by reducing duplication.

Comment thread .husky/pre-commit
Comment on lines +35 to +36
export PATH="$PATH:/c/Program Files/nodejs:/c/Program Files (x86)/nodejs"
export PATH="$PATH:$APPDATA/npm:$LOCALAPPDATA/Programs/nodejs"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For better readability and to avoid multiple export commands for the same variable within the same block, you can combine these two PATH modifications into a single line.

  export PATH="$PATH:/c/Program Files/nodejs:/c/Program Files (x86)/nodejs:$APPDATA/npm:$LOCALAPPDATA/Programs/nodejs"

@Shironex
Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 13, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Shironex Shironex merged commit ee13bf9 into AutoMaker-Org:v0.11.0rc Jan 14, 2026
7 checks passed
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.

2 participants