-
Notifications
You must be signed in to change notification settings - Fork 16.4k
feat(windows): default to PowerShell for shell tools and ! commands #1297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
claude-code-best
merged 1 commit into
claude-code-best:main
from
DavidShawa:feat/windows-default-powershell
Jul 17, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /** | ||
| * Windows default shell: PowerShell tool on by default; ! routing prefers it. | ||
| */ | ||
| import { afterEach, beforeEach, describe, expect, mock, test } from 'bun:test' | ||
|
|
||
| const settingsState: { defaultShell?: 'bash' | 'powershell' } = {} | ||
|
|
||
| mock.module('src/utils/settings/settings.js', () => ({ | ||
| getInitialSettings: () => ({ ...settingsState }), | ||
| })) | ||
|
|
||
| // Force windows platform for these unit tests regardless of host OS. | ||
| mock.module('src/utils/platform.js', () => ({ | ||
| getPlatform: () => 'windows' as const, | ||
| SUPPORTED_PLATFORMS: ['macos', 'wsl'], | ||
| })) | ||
|
Comment on lines
+1
to
+16
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win Follow test naming and mocking conventions. The test file violates two project coding guidelines:
🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
| import { isPowerShellToolEnabled } from '../shellToolUtils.js' | ||
| import { resolveDefaultShell } from '../resolveDefaultShell.js' | ||
|
|
||
| const ENV_KEY = 'CLAUDE_CODE_USE_POWERSHELL_TOOL' | ||
| let savedEnv: string | undefined | ||
|
|
||
| beforeEach(() => { | ||
| savedEnv = process.env[ENV_KEY] | ||
| delete process.env[ENV_KEY] | ||
| delete settingsState.defaultShell | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| if (savedEnv === undefined) delete process.env[ENV_KEY] | ||
| else process.env[ENV_KEY] = savedEnv | ||
| delete settingsState.defaultShell | ||
| }) | ||
|
|
||
| describe('isPowerShellToolEnabled (windows)', () => { | ||
| test('enabled by default when env unset', () => { | ||
| expect(isPowerShellToolEnabled()).toBe(true) | ||
| }) | ||
|
|
||
| test('disabled when env is falsy', () => { | ||
| process.env[ENV_KEY] = '0' | ||
| expect(isPowerShellToolEnabled()).toBe(false) | ||
| process.env[ENV_KEY] = 'false' | ||
| expect(isPowerShellToolEnabled()).toBe(false) | ||
| }) | ||
|
|
||
| test('enabled when env is truthy', () => { | ||
| process.env[ENV_KEY] = '1' | ||
| expect(isPowerShellToolEnabled()).toBe(true) | ||
| }) | ||
| }) | ||
|
|
||
| describe('resolveDefaultShell (windows)', () => { | ||
| test('defaults to powershell when tool enabled and no settings', () => { | ||
| expect(resolveDefaultShell()).toBe('powershell') | ||
| }) | ||
|
|
||
| test('honors settings.defaultShell=bash', () => { | ||
| settingsState.defaultShell = 'bash' | ||
| expect(resolveDefaultShell()).toBe('bash') | ||
| }) | ||
|
|
||
| test('honors settings.defaultShell=powershell', () => { | ||
| settingsState.defaultShell = 'powershell' | ||
| expect(resolveDefaultShell()).toBe('powershell') | ||
| }) | ||
|
|
||
| test('falls back to bash when PowerShell tool is disabled', () => { | ||
| process.env[ENV_KEY] = '0' | ||
| expect(resolveDefaultShell()).toBe('bash') | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,25 @@ | ||
| import { getInitialSettings } from '../settings/settings.js' | ||
| import { getPlatform } from '../platform.js' | ||
| import { isPowerShellToolEnabled } from './shellToolUtils.js' | ||
|
|
||
| /** | ||
| * Resolve the default shell for input-box `!` commands. | ||
| * Resolve the default shell for input-box `!` commands and agent preference. | ||
| * | ||
| * Resolution order (docs/design/ps-shell-selection.md §4.2): | ||
| * settings.defaultShell → 'bash' | ||
| * Resolution order: | ||
| * 1. settings.defaultShell (explicit user/project setting) | ||
| * 2. Windows + PowerShell tool enabled → 'powershell' | ||
| * 3. otherwise → 'bash' | ||
| * | ||
| * Platform default is 'bash' everywhere — we do NOT auto-flip Windows to | ||
| * PowerShell (would break existing Windows users with bash hooks). | ||
| * Opt out of the Windows PowerShell default via settings.defaultShell=bash | ||
| * or CLAUDE_CODE_USE_POWERSHELL_TOOL=0 (disables the PowerShell tool entirely). | ||
| */ | ||
| export function resolveDefaultShell(): 'bash' | 'powershell' { | ||
| return getInitialSettings().defaultShell ?? 'bash' | ||
| const configured = getInitialSettings().defaultShell | ||
| if (configured === 'bash' || configured === 'powershell') { | ||
| return configured | ||
| } | ||
| if (getPlatform() === 'windows' && isPowerShellToolEnabled()) { | ||
| return 'powershell' | ||
| } | ||
| return 'bash' | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,22 @@ | ||
| import { BASH_TOOL_NAME } from '@claude-code-best/builtin-tools/tools/BashTool/toolName.js' | ||
| import { POWERSHELL_TOOL_NAME } from '@claude-code-best/builtin-tools/tools/PowerShellTool/toolName.js' | ||
| import { isEnvDefinedFalsy, isEnvTruthy } from '../envUtils.js' | ||
| import { isEnvDefinedFalsy } from '../envUtils.js' | ||
| import { getPlatform } from '../platform.js' | ||
|
|
||
| export const SHELL_TOOL_NAMES: string[] = [BASH_TOOL_NAME, POWERSHELL_TOOL_NAME] | ||
|
|
||
| /** | ||
| * Runtime gate for PowerShellTool. Windows-only (the permission engine uses | ||
| * Win32-specific path normalizations). Ant defaults on (opt-out via env=0); | ||
| * external defaults off (opt-in via env=1). | ||
| * Win32-specific path normalizations). | ||
| * | ||
| * Default: ON on Windows for all builds (opt-out via | ||
| * CLAUDE_CODE_USE_POWERSHELL_TOOL=0 / false / off). Non-Windows always off. | ||
| * | ||
| * Used by tools.ts (tool-list visibility), processBashCommand (! routing), | ||
| * and promptShellExecution (skill frontmatter routing) so the gate is | ||
| * consistent across all paths that invoke PowerShellTool.call(). | ||
| */ | ||
| export function isPowerShellToolEnabled(): boolean { | ||
| if (getPlatform() !== 'windows') return false | ||
| return process.env.USER_TYPE === 'ant' | ||
| ? !isEnvDefinedFalsy(process.env.CLAUDE_CODE_USE_POWERSHELL_TOOL) | ||
| : isEnvTruthy(process.env.CLAUDE_CODE_USE_POWERSHELL_TOOL) | ||
| return !isEnvDefinedFalsy(process.env.CLAUDE_CODE_USE_POWERSHELL_TOOL) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Dynamically include shell tools and avoid hardcoding "Bash".
In the
hasPowerShell === falsebranch, "Bash" is unconditionally hardcoded intocoreToolsList, andshellToolGuidanceassumes Bash is enabled. If the Bash tool happens to be disabled (hasBashis false), this will confuse the model by providing guidance for a non-existent tool.Consider refactoring to dynamically build the list of enabled shell tools and selectively append the guidance.
♻️ Proposed refactor
📝 Committable suggestion
🤖 Prompt for AI Agents