Improve the system prompt for git commits.

Resolved 💬 3 comments Opened May 7, 2025 by motlin Closed Jan 3, 2026

When precommit hooks fail, Claude code often tries to commit one more time, without adding the changed files, so the second try also fails.

Sometimes Claude code is careful to stage individual changes file by file, but sometime it will commit everything at once.

I think this all stems from a confusing system prompt. It says to try committing twice when precommit hooks fail but doesn't mention running git add in between. For staging changes, it mentions avoiding git add . but suggests running git commit -am which has the same effect as running git add . and could be confusing the LLM.

5. If the commit fails due to pre-commit hook changes, retry the commit ONCE to include these automated changes. If it fails again, it usually means a pre-commit hook is preventing the commit. If the commit succeeds but you notice that files were modified by the pre-commit hook, you MUST amend your commit to include them.
- When possible, combine the "git add" and "git commit" commands into a single "git commit -am" command, to speed things up - However, be careful not to stage files (e.g. with \git add .\) for commits that aren't part of the change, they may have untracked files they want to keep around, but not commit.

To get around these problems, I add this to ~/.claude/CLAUDE.md:

- If pre-commit hooks fail, then there are now local changes. Git add those changes and try again.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗