Claude Amending Wrong Commit Fix (2026)

The Error

warning: Claude Code ran 'git commit --amend' after a pre-commit hook failure
  The --amend modified the PREVIOUS commit (abc1234) instead of creating a new one
  Previous commit message: "Add user authentication"
  Now contains: unrelated linting fixes mixed with auth changes

This appears when Claude Code uses --amend thinking it is completing a failed commit, but instead modifies the previous unrelated commit.

The Fix

git reflog
git reset --soft HEAD@{1}
git commit -m "Original commit message restored"
git add .
git commit -m "New changes in separate commit"
  1. Use git reflog to find the commit SHA before the erroneous amend.
  2. Reset to that commit while keeping all changes staged.
  3. Re-create the original commit and then create a separate commit for the new changes.

Why This Happens

When a pre-commit hook fails, the git commit command exits with a non-zero code and no commit is created. Claude Code may then retry with --amend, thinking it needs to complete the failed commit. But --amend modifies the last successful commit — which is an entirely different, previously completed commit. This silently corrupts that commit by adding unrelated changes to it.

If That Doesn’t Work

If the amend was pushed to remote:

git reflog
git reset --hard HEAD@{1}
git push --force-with-lease

If multiple amends were chained:

git reflog
# Find the last clean state
git reset --soft <clean-sha>
git stash
git commit -m "Restored original commit"
git stash pop
git commit -m "New changes"

Create a revert commit if force push is not possible:

git revert HEAD
git commit -m "Revert erroneous amend"

Prevention

# CLAUDE.md rule
NEVER use 'git commit --amend'. Always create new commits. After a pre-commit hook failure, fix the issue and run 'git commit' (not --amend). The failed commit never existed — there is nothing to amend.

This fix also applies if you see variations of this error:

  • Connection or process errors with similar root causes in the same subsystem
  • Timeout variants where the operation starts but does not complete
  • Permission variants where access is denied to the same resource
  • Configuration variants where the same setting is missing or malformed

If your specific error message differs slightly from the one shown above, the fix is likely the same. The key indicator is the operation that failed (shown in the stack trace) rather than the exact wording of the message.

Frequently Asked Questions

Does this error affect all operating systems?

This error can occur on macOS, Linux, and Windows (WSL). The exact error message may differ slightly between platforms, but the root cause and fix are the same. macOS users may see additional Gatekeeper or notarization prompts. Linux users should check that the relevant system packages are installed. Windows users should ensure they are running inside WSL2, not native Windows.

Will this error come back after updating Claude Code?

Updates can occasionally reintroduce this error if the update changes default configurations or dependency requirements. After updating Claude Code, verify your project still builds and runs correctly. If the error returns, reapply the fix and check the changelog for breaking changes.

Can this error cause data loss?

No, this error occurs before or during an operation and does not corrupt existing files. Claude Code’s edit operations are atomic — they either complete fully or not at all. However, if the error occurs during a multi-step operation, you may have partial changes that need to be reviewed with git diff before continuing.

How do I report this error to Anthropic if the fix does not work?

Open an issue at github.com/anthropics/claude-code with: (1) the full error message including stack trace, (2) your Node.js version (node --version), (3) your Claude Code version (claude --version), (4) your operating system and version, and (5) the command or operation that triggered the error.

Try it: Paste your error into our Error Diagnostic for an instant fix.