Claude's em dash habit silently breaks PowerShell scripts

Claude has a habit of inserting em dashes (—) where code needs plain hyphens (-), causing PowerShell scripts to fail with cryptic errors. The two characters look nearly identical in most editors, making the bug hard to spot. Users report this happens repeatedly when using Claude to generate scripts.

When writing prose, Claude often uses the em dash (—) for stylistic punctuation. That is fine in regular text, but in code it is a serious problem. PowerShell and most other scripting languages require a plain hyphen (-) to mark command options and flags. If an em dash sneaks in, the script throws an error about an unrecognized character, and because the characters look so similar on screen, the cause can be frustrating to track down.

The practical fix is to tell Claude explicitly in your prompt to use only plain hyphens in any code it writes. You can also do a find-and-replace in a text editor before running any Claude-generated script, swapping every em dash for a hyphen. The issue is not limited to PowerShell — bash and other shell languages are equally affected.

Key points

  • Claude replaces hyphens (-) with em dashes (—) in generated code, breaking PowerShell scripts at runtime.
  • The two characters are visually nearly identical, making this bug hard to notice.
  • Fix: tell Claude in your prompt to use only plain hyphens (-) in all code.
  • Before running a script, do a find-and-replace to swap em dashes for hyphens.
  • The same problem can occur in bash, Python, and other scripting languages.

Quick term guide

em dash
A long horizontal line character (—) used in writing for emphasis or pauses — different from the short hyphen (-) used in code.
PowerShell
A Windows tool that lets you automate tasks and control your computer by typing commands or running script files.
script
A small program that automates repeated steps.
port
A specific virtual door on your computer used by apps to send and receive information.
options
Financial contracts that give you the right to buy or sell an asset at a set price and time.
prompt
Text instructions you give to an AI tool.
ping
The time (in milliseconds) it takes for a signal to travel from your device to another and back — lower means faster response.
Python
Python is a common programming language used to build apps and scripts.
Read original