rtk-ai / rtk-ai/rtk

rtk cannot spawn .cmd/.sh wrapper commands on Windows (pnpm, npm, tsc)

Open
#950 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:cli bug effort-medium platform:windows priority:high
Dominant language
Rust
Stars
81k
Forks
5.1k
Avg merge
4d 21h
Merged PRs (30d)
35

Description

Summary

When rtk wraps commands like pnpm, npm, npx, or tsc on Windows, they fail with:

Error: Failed to run pnpm

This is because rtk (Rust binary) spawns these as subprocesses, but on Windows they are not native executables — they are shell script wrappers or .cmd batch files that require a shell to interpret.

Root Cause

Windows Node.js toolchain installs wrapper scripts instead of real binaries:

Command Location Actual file type
pnpm Program Files/nodejs/ POSIX shell script + .CMD batch
npm, npx Program Files/nodejs/ bash script + .cmd batch
tsc AppData/Roaming/npm/ sh script + .cmd batch
corepack Program Files/nodejs/ .cmd batch

When Git Bash runs pnpm install directly, the shell interprets the wrapper script. But when rtk intercepts and tries to spawn pnpm as a subprocess (presumably via std::process::Command), it fails because:

  1. POSIX shell scripts need a shell interpreter
  2. .cmd files need cmd.exe /c to execute

Current Workaround

In our PreToolUse hook (see #502), we added a passthrough list for known wrapper commands:

CMD_WRAPPER_RE="^(pnpm|pnpx|npm|npx|tsc|tsserver|corepack)([[:space:]]|$)"
if printf '%s' "$COMMAND" | sed 's/&&/\n/g; s/||/\n/g; s/;/\n/g' | sed 's/^[[:space:]]*//' | grep -qE "$CMD_WRAPPER_RE"; then
  exit 0  # skip rtk for these commands
fi

This sacrifices rtk's token savings for these commands in exchange for execution reliability.

Suggested Fix

When spawning a command on Windows, rtk could:

  1. Check if the resolved path is a .cmd file → use cmd.exe /c <cmd>
  2. Check if it's a shell script → use sh -c <cmd> or the Git Bash bash.exe
  3. Or simply always spawn via cmd.exe /c on Windows (similar to how Node.js child_process handles it with shell: true)

Related

  • #502 — Windows hook support request (same environment)

Environment

  • OS: Windows 11 Pro (10.0.26200)
  • RTK: v0.27.2
  • Node.js: installed via official installer (Program Files/nodejs/)
  • pnpm: installed via corepack
  • Shell: Git Bash (MINGW64)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Windows subprocess spawning path that uses std::process::Command, then reproduce the failure with pnpm, npm, npx, tsc, or corepack on Windows. Compare handling of .cmd files and shell scripts, and verify that the affected wrapper commands execute successfully without the passthrough workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, shell
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.