Some people love using Git's force push feature. Some people don't. And even among those who do, some people really really don't want agents like Claude Code running force push.
The following Git hook lets you disable force push on your computer. It can be disabled by setting ALLOW_GIT_FORCE_PUSH=I_AM_A_HUMAN_NOT_AN_LLM_AND_I_THE_HUMAN_WANT_TO_FORCE_PUSH, which hopefully your LLM will avoid doing. (It can also be skipped with a particular git flag, but hopefully your agent will avoid that too.)
This is local to your computer: it is not shared with your collaborators. (A more effective way to prevent force push is to configure your Git server to not allow force pushes, such as via GitHub rule sets.)
There are two ways to set this up:
Put the file below into .git/hooks/pre-push inside your repo. Make sure it's executable (chmod +x .git/hooks/pre-push).
Make sure you are running Git v2.54 or later, for the brand-new config-based hooks feature. This came out in April 2026 so at the time of writing, this probably requires installing Git yourself. If on a Mac, brew install git should do the trick, but do check with git --version afterwards to make sure that Homebrew actually takes precedence over /usr/bin; if it doesn't, you may want to update your shell config files to prepend /opt/homebrew/bin: to the very beginning of $PATH.
Copy the file below into some location that is on your $PATH (eg if you have a ~/.local/bin or something). (Or put it anywhere and change the command below to have its absolute path.) Make sure it's executable (chmod +x ~/.local/bin/pre-push-block-force-push).
Then, add the .gitconfig snippet below to your ~/.gitconfig or ~/.config/git/config. Now it is active on all of your repos!