[Bug] File patch fails with "unexpectedly modified" error when changes are unstaged
Resolved 💬 4 comments Opened Nov 13, 2025 by martinsejas Closed Jan 13, 2026
Bug Description
For some reason I get consistently error's when trying to patch, the error that the 'file has been unexpectedly modified' keeps appearing time and time again. Even if I tell claude to reset the diff by rereading the file it doesn't work. I think it's because I haven't staged and commited and changes in git for a very long while, but I don't want to just yet.
Environment Info
- Platform: win32
- Terminal: vscode
- Version: 2.0.37
- Feedback ID: b7a2d95d-1c00-419e-a6cf-dc432ab1ad5e
Errors
[{"error":"Error: Failed to create shell snapshot: Command failed: C:\\Program Files\\Git\\bin\\bash.exe -c -l SNAPSHOT_FILE='C:\\Users\\Martin\\.claude\\shell-snapshots\\snapshot-bash-1763058161042-7twsft.sh'\n source \"C:\\Users\\Martin\\.bashrc\" < /dev/null\n\n # First, create/clear the snapshot file\n echo \"# Snapshot file\" >| \"$SNAPSHOT_FILE\"\n\n # When this file is sourced, we first unalias to avoid conflicts\n # This is necessary because aliases get \"frozen\" inside function definitions at definition time,\n # which can cause unexpected behavior when functions use commands that conflict with aliases\n echo \"# Unset all aliases to avoid conflicts with functions\" >> \"$SNAPSHOT_FILE\"\n echo \"unalias -a 2>/dev/null || true\" >> \"$SNAPSHOT_FILE\"\n\n \n echo \"# Functions\" >> \"$SNAPSHOT_FILE\"\n\n # Force autoload all functions first\n declare -f > /dev/null 2>&1\n\n # Now get user function names - filter system ones and give the rest to eval in b64 encoding\n declare -F | cut -d' ' -f3 | grep -vE '^(_|__)' | while read func; do\n # Encode the function to base64, preserving all special characters\n encoded_func=$(declare -f \"$func\" | base64 )\n # Write the function definition to the snapshot\n echo \"eval \\\"\\$(echo '$encoded_func' | base64 -d)\\\" > /dev/null 2>&1\" >> \"$SNAPSHOT_FILE\"\n done\n \n echo \"# Shell Options\" >> \"$SNAPSHOT_FILE\"\n shopt -p | head -n 1000 >> \"$SNAPSHOT_FILE\"\n set -o | grep \"on\" | awk '{print \"set -o \" $1}' | head -n 1000 >> \"$SNAPSHOT_FILE\"\n echo \"shopt -s expand_aliases\" >> \"$SNAPSHOT_FILE\"\n \n echo \"# Aliases\" >> \"$SNAPSHOT_FILE\"\n # Filter out winpty aliases on Windows to avoid \"stdin is not a tty\" errors\n # Git Bash automatically creates aliases like \"alias node='winpty node.exe'\" for\n # programs that need Win32 Console in mintty, but winpty fails when there's no TTY\n if [[ \"$OSTYPE\" == \"msys\" ]] || [[ \"$OSTYPE\" == \"cygwin\" ]]; then\n alias | grep -v \"='winpty \" | sed 's/^alias //g' | sed 's/^/alias -- /' | head -n 1000 >> \"$SNAPSHOT_FILE\"\n else\n alias | sed 's/^alias //g' | sed 's/^/alias -- /' | head -n 1000 >> \"$SNAPSHOT_FILE\"\n fi\n \n\n \n # Check for rg availability\n echo \"# Check for rg availability\" >> \"$SNAPSHOT_FILE\"\n echo \"if ! command -v rg >/dev/null 2>&1; then\" >> \"$SNAPSHOT_FILE\"\n echo ' alias rg='\"''\\''C:\\Users\\Martin\\.nvm\\versions\\node\\v22.12.0\\bin\\node_modules\\@anthropic-ai\\claude-code\\vendor\\ripgrep\\x64-win32\\rg.exe'\\'''\" >> \"$SNAPSHOT_FILE\"\n echo \"fi\" >> \"$SNAPSHOT_FILE\"\n \n\n # Add PATH to the file\n echo \"export PATH=\\$PATH\" >> \"$SNAPSHOT_FILE\"\n \n\n # Exit silently on success, only report errors\n if [ ! -f \"$SNAPSHOT_FILE\" ]; then\n echo \"Error: Snapshot file was not created at $SNAPSHOT_FILE\" >&2\n exit 1\n fi\n \n\n at file:///C:/Users/Martin/.nvm/versions/node/v22.12.0/bin/node_modules/@anthropic-ai/claude-code/cli.js:1363:133\n at ChildProcess.exithandler (node:child_process:421:5)\n at ChildProcess.emit (node:events:524:28)\n at ChildProcess.emit (node:domain:489:12)\n at maybeClose (node:internal/child_process:1101:16)\n at ChildProcess._handle.onexit (node:internal/child_process:304:5)","timestamp":"2025-11-13T18:22:51.974Z"},{"error":"Error: File has been unexpectedly modified. Read it again before attempting to write it.\n at Object.call (file:///C:/Users/Martin/.nvm/versions/node/v22.12.0/bin/node_modules
Note: Error logs were truncated.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗