Claude Code Pwsh Guard banner
waseemnasir2k26 waseemnasir2k26

Claude Code Pwsh Guard

Development community

Description

Claude Code hook pack that stops the agent firing Bash-only syntax at a Windows PowerShell session. Detects extglob, POSIX env refs, /dev/null, heredocs and more; auto-rewrites the safe ones and blocks the rest with the correct pwsh command so the agent self-corrects. Not affiliated with Anthropic.

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

claude-code-pwsh-guard

A Claude Code hook pack that catches bash-only shell syntax before it reaches a Windows PowerShell session, and either rewrites it to the PowerShell equivalent or blocks it with the correct command in the error message.

Claude                                                    pwsh-guard                          Result
──────────────────────────────────────────────────────────────────────────────────────────────────
Bash("shopt -s extglob;                       ─▶  PreToolUse: deny                   ✗ never runs
      rm -f !(keep.txt|keep2.txt)")               [ERROR] shopt / extglob is a bash builtin
                                                   PowerShell: Get-ChildItem -Exclude ... |
                                                               Remove-Item
                                                  [ERROR] extglob pattern !(...)

Bash("Get-ChildItem -Exclude                  ─▶  (silent)                            ✓ runs
      keep.txt,keep2.txt | Remove-Item")

Bash("export NODE_ENV=production;             ─▶  PreToolUse: allow + updatedInput    ✓ runs, fixed
      echo $PATH > /dev/null")                    $env:NODE_ENV = "production";
                                                  echo $env:PATH > $null

Without the guard, that first command produces `The term 'shopt' is not recognized`, Claude tries a variation of the same bash syntax, and the loop repeats. That loop is [issue #28670](https://github.com/anthropics/claude-code/issues/28670).

![hook events](https://img.shields.io/badge/hooks-PreToolUse%20%2B%20SessionStart-blue) ![rules](https://img.shields.io/badge/rules-19-blue) ![tests](https://img.shields.io/badge/tests-204%20passing-brightgreen) ![license](https://img.shields.io/badge/license-MIT-blue)

Quick start

  1. Clone this repo anywhere: git clone https://github.com//claude-code-pwsh-guard
  2. cd claude-code-pwsh-guard
  3. powershell -ExecutionPolicy Bypass -File .\install.ps1