Skip to content

Refresh PATH and let npm shims run in bb's shells on Windows - #4731

Merged
SawyerHood merged 3 commits into
mainfrom
bb/windows-shell-environment-thr_jensq3v9th
Oct 2, 2026
Merged

SawyerHood merged 3 commits into
mainfrom
bb/windows-shell-environment-thr_jensq3v9th

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Three problems with the environment bb gives shells on Windows. Part of #1206.

  • The daemon kept the PATH it started with. resolveUserShellCommand returns no shell on Windows, so the periodic shell-environment refresh did nothing, and a provider CLI installed after bb started was not found until bb restarted.
  • Windows client editions block every PowerShell script by default, and npm installs its commands as .ps1 shims. In bb terminals and agent shells npm, pnpm, and codex failed with "running scripts is disabled on this system".
  • The always-on agent introduction told every agent to invoke "$BB_CLI" directly. That is Bourne syntax, and on Windows BB_CLI names a script that needs Node.

What changed

Three commits:

  • PATH refresh (apps/host-daemon/src/runtime-shell-env.ts): on Windows the refresh reads the machine and user environment from the registry with reg.exe, expands %VAR% references against those refreshed values (so %JAVA_HOME%\bin works when the installer added JAVA_HOME too), removes duplicates without regard to case, and appends inherited entries the registry does not list. If the machine environment cannot be read it keeps the previous result.
  • Script policy: bb sets PSExecutionPolicyPreference=RemoteSigned in the environment it hands to terminals, agents, and hooks on Windows, but only when nobody chose a policy: resolvePowerShellExecutionPolicyDefault returns nothing if the variable is already set, if the user or machine registry scope has an ExecutionPolicy, or if a PowerShell 7 powershell.config.json (user, or beside a pwsh on PATH) sets one. A process-scope value outranks those scopes, so setting it unconditionally would have weakened a deliberate AllSigned or Restricted. Group Policy still wins. RemoteSigned is the default on Windows Server and still requires a signature on downloaded scripts. The whole behavior is one option passed in start-host-daemon.ts.
  • Agent text: the introduction and the bb-cli skill say the examples use POSIX syntax and how to read an environment variable, chain commands, and continue a line in PowerShell.

No wire or CLI changes.

How you verified

  • Windows 11 Enterprise VM (build 26300), on a branch combining this with the other open Windows changes:
    • A terminal started with --command "Get-ExecutionPolicy -Scope Process" printed RemoteSigned, and --command "npm --version" exited 0 and printed the version (it failed before).
    • With a new directory appended to the user Path in the registry while bb was running, a terminal could not find a command in it; after bb machine provider-cli status triggered the refresh, a new terminal ran the command. bb was not restarted. The same worked with a new user variable and a Path entry of %THAT_VARIABLE%\bin.
    • After Set-ExecutionPolicy -Scope CurrentUser AllSigned, a new terminal reported process scope Undefined and effective policy AllSigned; after setting it back to Undefined, process scope was RemoteSigned again.
  • Linux: runtime-shell-env.test.ts covers the registry read (expansion against refreshed variables, de-duplication, unreadable user or machine environment) and the policy default (offered only with no registry or config-file policy, never when the variable is set, the registry cannot be read, or off Windows); the bb-guide plugin tests pass. On this branch before the last rebase, turbo run lint typecheck test --filter='...[origin/main]': 20 of 20 tasks passed. After the rebase onto current main, lint and typecheck pass for the same filter.

Not verified: a machine where Group Policy enforces a stricter execution policy.

🤖 Generated with Claude Code

AGENT GENERATED

@SawyerHood
SawyerHood marked this pull request as ready for review October 2, 2026 16:50
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 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-02T16:54:37.220430Z 8f71be8 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.

@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: 8f71be879f

ℹ️ 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".

POWERSHELL_EXECUTION_POLICY_VARIABLE,
) === undefined
) {
shellEnv[POWERSHELL_EXECUTION_POLICY_VARIABLE] = "RemoteSigned";

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 Preserve explicitly configured execution policies

When a user has deliberately configured AllSigned or Restricted at CurrentUser or LocalMachine scope, unconditionally setting the process scope to RemoteSigned overrides that policy because PowerShell gives Process higher precedence. The environment-variable check only detects an already inherited process-scope setting, so ordinary Set-ExecutionPolicy -Scope CurrentUser ... configurations are silently weakened in every bb terminal and agent shell; inject this default only when no explicit non-Group-Policy scope has been configured.

Useful? React with 👍 / 👎.

Comment on lines +350 to +353
.replace(
WINDOWS_ENVIRONMENT_REFERENCE_PATTERN,
(reference, name: string) =>
windowsEnvironmentValue(env, name) ?? reference,

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 Expand PATH using refreshed registry variables

When an installer adds both a new environment variable and a PATH entry referencing it, such as JAVA_HOME plus %JAVA_HOME%\bin, this expansion consults only the daemon's inherited environment. Since that long-running process cannot contain the newly installed variable, the refreshed PATH retains the literal reference and children still cannot find the installed executable, defeating the refresh for a common installer pattern. Read the relevant machine/user registry variables and expand against that refreshed environment before publishing PATH.

Useful? React with 👍 / 👎.

SawyerHood and others added 3 commits October 2, 2026 17:25
On Windows the daemon kept the PATH it started with, so a provider CLI
installed afterwards was not found until bb restarted. The shell
environment refresh now reads the machine and user Path values from the
registry, expands their variable references, and keeps any inherited
entries the registry does not list.

Co-Authored-By: Claude Code <[email protected]>
The always-on introduction told every agent to invoke "$BB_CLI"
directly, which is Bourne syntax and not runnable on Windows, where
BB_CLI names a script that needs Node. The introduction and the bb-cli
skill now say the examples use POSIX syntax and how to read an
environment variable, chain commands, and continue a line in PowerShell.

Co-Authored-By: Claude Code <[email protected]>
Windows client editions block every PowerShell script by default, and npm
installs its commands as .ps1 shims, so npm, pnpm, and codex failed with
'running scripts is disabled' in bb terminals and agent shells. The shell
environment bb hands to terminals, agents, and hooks now sets
PSExecutionPolicyPreference to RemoteSigned for those processes only,
unless the user already set it. Group Policy still wins.

Co-Authored-By: Claude Code <[email protected]>
@SawyerHood
SawyerHood force-pushed the bb/windows-shell-environment-thr_jensq3v9th branch from 8f71be8 to 82960c6 Compare October 2, 2026 17:29
@SawyerHood
SawyerHood merged commit f5c4875 into main Oct 2, 2026
27 checks passed
@SawyerHood
SawyerHood deleted the bb/windows-shell-environment-thr_jensq3v9th branch October 2, 2026 18:08
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