Skip to content

Windows: PowerShellツール有効時にPowerShellをデフォルトシェルとして使用

原文(日本語に翻訳)

Windows: PowerShellツールが有効な場合、ClaudeはBashにデフォルト設定する代わりに、プライマリシェルとしてPowerShellを使用するようになりました。

原文(英語)

Windows: when the PowerShell tool is enabled, Claude now treats PowerShell as the primary shell instead of defaulting to Bash

概要

Windows環境でPowerShellツールが有効になっている場合、Claude CodeがコマンドをBash(WSL経由など)ではなくPowerShellで実行するようになりました。これにより、WindowsネイティブなPowerShellコマンドやスクリプトをより自然に使用でき、Windows固有のコマンド(Get-ChildItemSelect-Objectなど)が期待通りに動作します。

基本的な使い方

powershell
# PowerShellツールを有効化(settings.jsonで設定)
# { "powershell": { "enabled": true } }

# PowerShellが有効な場合、Claude CodeはWindowsコマンドを
# PowerShellで実行するようになる

claude
# → ClaudeはPowerShellネイティブコマンドを優先的に使用

実践例

PowerShellネイティブコマンドの活用

powershell
# Claude Codeにタスクを依頼するとPowerShellコマンドが生成される

# ファイル一覧取得
Get-ChildItem -Path . -Filter "*.ts" -Recurse

# プロセス管理
Get-Process | Where-Object { $_.CPU -gt 10 } | Select-Object Name, CPU

# レジストリ操作
Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion"

Windowsサービス管理

powershell
# Claude Codeに依頼すると自動的にPowerShellコマンドを生成
# 「Windowsサービスの一覧を取得して」と依頼すると:
Get-Service | Where-Object Status -eq "Running"

# 「SQLServerサービスを再起動して」と依頼すると:
Restart-Service -Name "MSSQLSERVER" -Force

.NET開発でのPowerShell統合

powershell
# .NETプロジェクトのビルドをPowerShellで実行
dotnet build --configuration Release

# テスト実行
dotnet test --filter "Category=Unit"

# NuGetパッケージ管理
dotnet add package Newtonsoft.Json

注意点

  • この変更はWindows環境でPowerShellツールが有効な場合のみ適用されます
  • WSL2(Windows Subsystem for Linux)環境では、従来通りBashが使用されます
  • Bashに特有のコマンド(grepawkなど)はPowerShellの同等コマンドに置き換えられます
  • PowerShellとBashでは構文が異なるため、既存のスクリプトが変更される場合があります
  • PowerShellツールを無効にすれば従来のBash動作に戻せます

関連情報