{"slug": "why-claude-code-fails-on-windows-when-you-use-multi-line-prompts", "title": "Why Claude Code fails on Windows when you use multi-line prompts", "summary": "Anthropic's Claude Code CLI fails on Windows when given multi-line prompts because the npm-installed claude.CMD batch shim truncates everything after the first newline, causing the agent to receive incomplete instructions. Developer tests showed the direct claude.exe binary works correctly, while the shim silently drops the prompt's second line, leading to failed tasks without any error logs. The fix is to call claude.exe directly or flatten prompts to single-line strings.", "body_md": "# Why Claude Code fails on Windows when you use multi-line prompts\n\n## The ghost in the machine\n\nWe were testing routine web work: filling forms, downloading files, and verifying data. I was using two different setups. One hit the computer use API directly, and the other used [Claude Code](/en/tags/claude%20code/) in headless mode (`claude -p`\n\n) paired with Playwright.\n\nTo keep things objective, we used machine verification. We didn't trust the agent's \"I'm done\" message; we checked the actual JSONL payloads and file sizes. When the headless setup started failing almost every single trial, my first instinct was that the model was just choking on the specific prompt format. I was wrong. The model wasn't the problem—the Windows environment was.\n\n## The culprit is the .CMD shim\n\nIf you're on Windows and installed [Claude](/en/tags/claude/) Code via npm, you've got a file called `claude.CMD`\n\nsitting on your PATH. When you use Python's `subprocess`\n\nor `shutil.which(\"claude\")`\n\n, Windows resolves to that `.CMD`\n\nfile instead of the actual executable.\n\nThat file is just a batch wrapper:\n\n```\n\"%dp0%\\node_modules\\@anthropic-ai\\claude-code\\bin\\claude.exe\" %*\n```\n\nHere is the catch: when you pass a multi-line prompt through that `%*`\n\nargument forwarder in `cmd.exe`\n\n, everything after the first newline is silently deleted. The agent doesn't get an error; it just receives a truncated prompt. In my tests, the agent would see \"Follow the instruction below exactly,\" and then nothing. Of course, it failed because the actual instructions were on line two.\n\nI put together this snippet to prove it. If you run this, you'll see the shim fails while the direct `.exe`\n\nworks:\n\n``` python\nimport os, subprocess\n\nEXE = os.path.join(os.environ[\"APPDATA\"], \"npm\", \"node_modules\",\n \"@anthropic-ai\", \"claude-code\", \"bin\", \"claude.exe\")\nCMD = os.path.join(os.environ[\"APPDATA\"], \"npm\", \"claude.CMD\")\nPROMPT = \"Follow the instruction below exactly.\\nOutput the string MARKER_TAIL_9137 and nothing else.\"\n\nfor label, argv0 in ((\"claude.CMD (shim)\", CMD), (\"claude.exe (direct)\", EXE)):\n r = subprocess.run([argv0, \"-p\", PROMPT], capture_output=True, text=True,\n encoding=\"utf-8\", errors=\"replace\", timeout=180)\n out = (r.stdout or \"\") + (r.stderr or \"\")\n print(label, \"tail_received =\", \"MARKER_TAIL_9137\" in out)\n```\n\n## How to fix your AI workflow\n\nThis is a nightmare to debug because there are no crash logs or non-zero exit codes. Everything looks \"fine,\" but your agent is basically operating with amnesia. If you're building a real-world deployment on Windows, you have two options to avoid this:\n\n**Call the binary directly:** Don't trust`shutil.which`\n\n. Explicitly point your code to`claude.exe`\n\n.**Flatten your prompts:** Replace all newlines with spaces before passing the string to the CLI. This is the safer bet for cross-platform stability.\n\nFor anyone doing deep dive prompt engineering, just remember that the \"plumbing\" between your Python script and the LLM can be just as volatile as the model itself.\n\n[Next Claude Code managed to polish our internal agent using a $10k →](/en/threads/6472/)\n\n## All Replies （3）\n\n[@ChrisPunk](/en/users/ChrisPunk/)Probably just another case of lazy dev work. Why would it even work on Linux but not Windows?", "url": "https://wpnews.pro/news/why-claude-code-fails-on-windows-when-you-use-multi-line-prompts", "canonical_source": "https://promptcube3.com/en/threads/6590/", "published_at": "2026-08-16 17:00:40+00:00", "updated_at": "2026-08-16 17:11:20.889455+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools", "artificial-intelligence"], "entities": ["Anthropic", "Claude Code", "Windows", "npm", "Playwright", "Python"], "alternates": {"html": "https://wpnews.pro/news/why-claude-code-fails-on-windows-when-you-use-multi-line-prompts", "markdown": "https://wpnews.pro/news/why-claude-code-fails-on-windows-when-you-use-multi-line-prompts.md", "text": "https://wpnews.pro/news/why-claude-code-fails-on-windows-when-you-use-multi-line-prompts.txt", "jsonld": "https://wpnews.pro/news/why-claude-code-fails-on-windows-when-you-use-multi-line-prompts.jsonld"}}