Photo of DeepakNess DeepakNess

Prevent AI Agents from auto-merging PRs

Came across this post from Elvis containing a helpful tip to prevent your AI agent from accidentally auto-merging PRs when using the --YOLO or --dangerously-skip-permissions mode. It blocks AI agents like Claude, Codex, or OpenCode from merging Pull Requests accidentally.

Prevent AI agents from auto-merging PRs

In simple language, this setup checks when your AI agent runs a command containing pr merge and:

  • if it does match: blocks the action and prints and error message
  • if it does not match: allows running it without errors

This reduces the risks when vibe-coding in YOLO mode, and here's how I have set this up:

# make the hidden folder
mkdir -p ~/.local/bin

# create and open new file
nano ~/.local/bin/gh

And then paste the following in the file:

#!/bin/bash
# Wrapper to block AI agents from merging PRs

if [[ "$*" == *"pr merge"* ]]; then
  echo "🚫 Blocked: merging requires human approval"
  exit 1
fi

exec /opt/homebrew/bin/gh "$@"

Now, make the script runnable:

chmod +x ~/.local/bin/gh

Then I added the following in my .zshrc file:

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc

Reloaded settings using the following command:

source ~/.zshrc

And it was ready.

It will now block commands containing pr merge in them, in case my AI agent starts to go rogue.

Webmentions

What’s this?