Skip to content

Windows support for the embedded Claude session (ConPTY) - #7

Draft
simplaerai-sv wants to merge 1 commit into
HelpFreedom:mainfrom
simplaerai-sv:win32-embedded-claude
Draft

Windows support for the embedded Claude session (ConPTY)#7
simplaerai-sv wants to merge 1 commit into
HelpFreedom:mainfrom
simplaerai-sv:win32-embedded-claude

Conversation

@simplaerai-sv

@simplaerai-sv simplaerai-sv commented Aug 16, 2026

Copy link
Copy Markdown

Problem

On Windows the Claude panel dies immediately with
Error: File not found — the session spawn path is POSIX-only:
a /bin/bash watchdog wrapper, /bin/sh command -v, and negative-pid
group signals.

Changes

One file, electron/claude.ts, win32 branches only — the POSIX path is
untouched:

  • which(): resolve via where.exe, preferring .exe/.cmd/.bat. npm
    installs an extensionless sh shim next to claude.cmd and lists it
    first; Windows cannot exec it.
  • spawn: no bash watchdog wrapper. .cmd/.bat shims are routed through
    cmd.exe /c (a shim cannot be CreateProcess'd directly). Closing the
    pty tears down the attached ConPTY console tree, so a hard Electron
    death still takes claude with it — the guarantee the wrapper provides
    on POSIX.
  • killSession(): pty.kill() instead of process.kill(-pid, SIGHUP)
    negative-pid group signals are a POSIX concept and throw on Windows.

Tested

Windows 11 (build 26200), Node 24, claude CLI 2.1.233:

  • the panel opens; first-run onboarding and login work
  • all six kadr_* MCP tools are reachable from the embedded session
  • the session cwd follows the saved project folder, as designed
  • close/reopen regenerates kadr-mcp.json with a fresh bridge port

Honest caveat: that run was against the v0.3.0 base. The branch has
since been rebased onto v0.5.1, so it now sits on top of the session
generation/serialization rework and sessionEnv(). The merge resolution
keeps both — upstream session identity, plus the win32 spawn branch —
and tsc -p tsconfig.node.json is clean, but the rebased build has not
been re-run on Windows yet. Happy to confirm before you merge.

No file overlap with the other open Windows PR (#9, which fixes
npm install and the dev-server bind), nor with #3 (macOS) or #5 (NixOS).

🤖 Generated with Claude Code

@simplaerai-sv
simplaerai-sv marked this pull request as draft August 16, 2026 13:52
@simplaerai-sv
simplaerai-sv force-pushed the win32-embedded-claude branch from f71d37d to 934ea30 Compare August 16, 2026 13:58
The Claude panel was POSIX-only and died on Windows with "File not
found" before the CLI even started. Three win32 branches, POSIX path
untouched:

- which(): resolve via where.exe, preferring .exe/.cmd/.bat — npm puts
  an extensionless sh shim first, which Windows cannot exec
- spawn: no bash watchdog wrapper; .cmd/.bat shims route through
  cmd.exe /c under ConPTY. Closing the pty tears down the attached
  console tree, so a hard Electron death still takes claude with it
- closeSession(): pty.kill() instead of process.kill(-pid, SIGHUP) —
  negative-pid group signals throw on Windows

Tested on Windows 11 (26200), Node 24, claude CLI 2.1.233: panel opens,
all six kadr_* MCP tools reachable from the embedded session.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
lt3-me added a commit to lt3-me/kadr that referenced this pull request Sep 9, 2026
…lpFreedom#7 in view

PR HelpFreedom#7 (simplaerai-sv, «Windows support for the embedded Claude session»)
solves the same failure on the v0.3 base. This compares the two and takes
the one idea from it worth taking.

### Taken: the explicit cmd.exe route

`winLaunch` now starts a `.cmd`/`.bat` launcher — npm's `claude.cmd` shim —
through `%ComSpec%` itself instead of letting CreateProcess supply the
interpreter. Two things come with that. `/d` skips the registry AutoRun
(this machine has clink there; a conda hook is the other usual tenant),
which otherwise runs inside the panel's cmd.exe and can print into it.
And the quoting becomes ours: `/s` plus an outer pair of quotes around the
whole line, which keeps a launcher path with a space in it whole.

That last part is where PR HelpFreedom#7's version breaks. It spawns
`cmd.exe /c "<shim>" args...` bare, and cmd's parser strips the first and
the last quote of its command when the first character is a quote — so
`"C:\Users\Jane Doe\AppData\Roaming\npm\claude.cmd" --mcp-config ...`
becomes `C:\Users\Jane Doe\...` and cmd stops at `C:\Users\Jane`. A user
name with a space is not exotic. Verified with a shim in a directory with
a space: bare `/c` fails as described, the outer-quoted form and the
implicit CreateProcess form both deliver every argument intact, inner
quotes and non-ASCII included.

### Not taken: `where.exe`

PR HelpFreedom#7 resolves the CLI with `where.exe` and prefers an `.exe`/`.cmd`/`.bat`
hit, falling back to the first line — which is npm's extensionless sh
shim, the file ConPTY cannot start. The PATH walk here uses PATHEXT, so
that shim is never a candidate; it searches the SESSION's PATH, which
claude-env.json may extend; and it checks `~/.local/bin`, the native
installer's directory, for an editor launched from a desktop entry whose
PATH has not caught up. It also spawns no helper process.

Session teardown is the same in both: `pty.kill()` on Windows, node-pty's
ConPTY kill enumerating the console's process list.

### Verification, on the real UI this time

Windows 11, claude 2.1.265 from npm, the panel driven by hand:

- open → one `cmd.exe /d /s /c "…claude.CMD …"` and one claude.exe;
- close → nothing left; close-and-reopen in quick succession → exactly
  one tree; quit the editor with the panel open → nothing left;
- `/mcp` inside the panel: kadr connected, 13 tools; the same 13 over a
  stdio client spawning mcp-bridge.cjs like claude does; kadr_state and
  kadr_eval answer; /eval refuses a request without the token and one
  carrying an Origin (403 both);
- close/reopen regenerates kadr-mcp.json with a fresh bridge port;
- the trust dialog that appears with no project open is the CLI's own:
  the panel starts in the home directory then, and the CLI does not
  persist trust for it even when run from a plain terminal.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.

1 participant