Skip to content

Open terminals on native Windows - #4660

Merged
SawyerHood merged 2 commits into
mainfrom
bb/windows-terminals-thr_jensq3v9th
Oct 2, 2026
Merged

SawyerHood merged 2 commits into
mainfrom
bb/windows-terminals-thr_jensq3v9th

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

TerminalManager.openTerminal returned unsupported_platform: Native Windows terminals are not supported for every open on Windows, so the Terminals panel and bb terminal create did nothing there. Behind that refusal the shell lookup only knew $SHELL, /bin/zsh, /bin/bash, and /bin/sh, commands were always passed as -lc, and closing a terminal called pty.kill(signal), which node-pty rejects on Windows ("Signals not supported on windows"). Separately, bb terminal send --enter appended a line feed; PowerShell's line editor treats that as "continue on the next line", so the command was never submitted. Part of #1206.

What changed

  • New apps/host-daemon/src/terminals/terminal-shell.ts: the Windows shell is PowerShell 7 (pwsh.exe) when it is on PATH, otherwise Windows PowerShell under %SystemRoot%, otherwise %ComSpec%. Start arguments follow the shell: -NoLogo -Command <text> for PowerShell, /d /s /c <text> for cmd, -lc <text> for POSIX shells (including Git bash). The terminal title drops .exe.
  • terminal-manager.ts: the Windows refusal and the now-unused platform option are removed. On Windows the pty is closed with pty.kill() and no signal; macOS and Linux still signal the process group.
  • bb terminal send --enter sends a carriage return, which is what a terminal emulator sends for the Enter key. Cooked-mode POSIX shells receive it as a newline through the tty's CR-to-NL translation, and raw-mode line editors bind it to accept-line. The flag's help text now reads "Press Enter after the text".
  • A PowerShell terminal started with a command exits with that command's exit code. -Command by itself reports 1 for every failure, so the daemon appends a check that exits with $LASTEXITCODE when the last native command failed and with 1 when a cmdlet failed.
  • bb terminal create -- <args> sends the argument list unchanged in a new argv start mode, and the daemon quotes it for the shell it selected: single quotes after the call operator for PowerShell, double quotes for cmd, single quotes for POSIX shells. Before, the CLI quoted for a POSIX shell whatever the target machine ran.
  • bb guide terminals and the bb-cli skill (plugins/bb-guide/skills/bb-cli/references/thread-operation.md) say which shell a terminal runs on each platform and that the argument-list form is quoted for it.

Wire change: the terminal start field accepts { mode: "argv", argv } in packages/host-daemon-contract and packages/server-contract, and HOST_DAEMON_PROTOCOL_VERSION goes from 224 to 225.

How you verified

  • Windows 11 Enterprise VM (build 26300), on a branch with this change on top of Start bb and run the bb CLI on native Windows #4657 (needed to build on Windows): bb terminal create --machine bb-win11 --cwd C:\src\plainrepo --command "git status; echo done-marker" exited 0 and printed the git status and done-marker; an interactive terminal opened with title powershell and the prompt PS C:\src\plainrepo>; bb terminal send <id> --text hostname --enter printed bb-win11 and returned to the prompt; bb terminal close <id> took the session's PowerShell process count from 1 to 0.
  • Before the --enter change the same send left PowerShell at its >> continuation prompt with hostname unsubmitted.
  • Exit codes and argument lists, same VM, on a branch combining all the open Windows changes: --command "cmd /c exit 7" ended with exit code 7 and --command 'node -e "process.exit(3)"' with 3 (both were 1 before); a failing cmdlet (Get-Item <missing> -ErrorAction Stop) ended with 1 and Write-Output ok with 0. bb terminal create -- node -e <script> "C:\bb-setup\argv out.json" "two words" "it's" "semi;colon" '$env:USERNAME' "a&b" "C:\Program Files\x" wrote exactly those six arguments to the file, and -- node -e "process.exit(9)" ended with 9.
  • Linux: turbo run lint typecheck test for @bb/host-daemon, @bb/cli, @bb/host-daemon-contract, @bb/server-contract, @bb/templates, and the bb-guide plugin passes, including the existing real-pty terminal test. terminal-shell.test.ts covers shell classification, start arguments and quoting per shell, the exit-code suffix, titles, and the Windows shell order; the CLI tests pin the carriage return and the argv start mode. check-npm-version-guard.mjs passes without a plugin SDK bump.

Not verified: --enter against a full-screen terminal program on macOS or Linux; cmd as the fallback shell on a machine without PowerShell, including its argument quoting, which only the unit tests cover; PowerShell 7 (the VM has only Windows PowerShell 5.1).

🤖 Generated with Claude Code

AGENT GENERATED

The terminal manager refused every open on Windows and only knew POSIX shells.

- Pick the Windows shell: PowerShell 7 on PATH, then Windows PowerShell, then
  ComSpec. Pass a command in the shell's own syntax (`-Command`, `/c`, `-lc`).
- Close a Windows pseudoconsole without a signal, which node-pty rejects there.
- Make `bb terminal send --enter` send a carriage return, the byte a terminal
  sends for Enter; PowerShell treats a line feed as a continuation.

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d576f1f4cc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
switch (kind) {
case "powershell":
return ["-NoLogo", "-Command", args.start.command];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve native exit codes from PowerShell commands

When start.command ends with a native executable returning a code such as 7, launching it with -Command does not forward $LASTEXITCODE; PowerShell documents that the resulting status is normalized to 0 or 1 unless the command explicitly uses exit. The terminal therefore records and reports the wrong exit code on Windows, unlike the POSIX -lc path. Wrap the command so the shell explicitly exits with the native command's code while still preserving PowerShell cmdlet failures.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T01:43:47.827074Z d576f1f Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@SawyerHood
SawyerHood marked this pull request as draft October 1, 2026 23:37
@SawyerHood
SawyerHood marked this pull request as ready for review October 2, 2026 01:41

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d576f1f4cc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +50 to +51
case "cmd":
return ["/d", "/s", "/c", args.start.command];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid POSIX-quoting positional commands for Windows targets

When a Windows terminal is created through the positional CLI form, resolveTerminalStart still serializes every argument with POSIX single-quote escaping before this branch passes the text to PowerShell or cmd. For example, an argument containing a space becomes 'hello world'; cmd does not treat single quotes as quoting, so the child receives split arguments containing literal quote characters, and embedded single quotes produce invalid PowerShell syntax. Either preserve the command as native-shell text or quote it according to the selected target shell so the newly enabled Windows feature works through the full CLI surface.

AGENTS.md reference: AGENTS.md:L26-L26

Useful? React with 👍 / 👎.

Comment on lines +33 to +36
A terminal runs the machine's own shell: $SHELL (then zsh, bash, sh) on macOS
and Linux; on Windows, PowerShell 7 when `pwsh` is on PATH, otherwise Windows
PowerShell, otherwise cmd. Write --command in that shell's syntax. `send --enter`
presses Enter (a carriage return), which every one of those shells accepts.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Document the Windows terminal contract in the bb-cli skill

This adds user-visible shell selection and changes terminal send --enter, but only the in-CLI guide was updated; the required plugins/bb-guide/skills/bb-cli surface still omits the native-shell contract. Agents relying on that installed skill can therefore generate POSIX-only command syntax for Windows terminals. Update its terminal reference alongside this guide change.

AGENTS.md reference: AGENTS.md:L27-L27

Useful? React with 👍 / 👎.

- A PowerShell terminal command now exits with the command's own exit code;
  -Command alone collapses every failure to 1.
- bb terminal create -- <args> sends the argument list as is. The daemon quotes
  it for the shell it selected (PowerShell, cmd, or a POSIX shell) instead of
  the CLI quoting for a POSIX shell. Adds an argv terminal start mode and bumps
  the host daemon protocol to 225.
- Document the per-platform shell and the argument-list form in the bb-cli
  skill.

Co-Authored-By: Claude Code <[email protected]>
@SawyerHood
SawyerHood merged commit 864b4cb into main Oct 2, 2026
21 checks passed
@SawyerHood
SawyerHood deleted the bb/windows-terminals-thr_jensq3v9th branch October 2, 2026 03:21
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