• AI
  • GitHub
  • code review

Tie pull request approvals to the commit that gets merged

When an AI agent can push fixes to a pull request, checks and approvals must apply to the final commit. A beginner-friendly guide with Claude Ship as the example and the GitHub branch protection settings that enforce it.

Imagine you ask a colleague to proofread a contract. They read it and sign off. Then, before the contract is sent, someone quietly edits one clause. The signature is still on the page, but it no longer covers what the contract says.

The same thing can happen to code. Once an AI agent is allowed to push fixes to a pull request, it can change the code after a person has already approved it. This article explains why approvals and test results must belong to the exact version of the code that gets merged, and how to make GitHub enforce that.

A few terms first

If you already use GitHub every day, skim this section.

  • Commit: a saved snapshot of changes in Git. Each commit has a unique ID called a SHA (a long string such as 3f9a2c1...).
  • Branch: a separate line of work in a repository. You make changes on your own branch, then bring them into the main branch.
  • Pull request (PR): a request to merge the changes from your branch into another branch, usually main. Teammates read and discuss the changes there.
  • Merge: the step that actually brings the PR’s changes into the target branch.
  • Head commit: the newest commit on the PR’s branch. It is the version that will be merged.
  • CI (continuous integration): a service that automatically builds and tests every push.
  • Status check: a single result that CI (or another tool) reports on a commit, such as “tests passed” (green) or “build failed” (red).
  • Review approval: a reviewer pressing “Approve” on a PR to say the change looks good.
  • Branch protection rule: a GitHub setting on a branch such as main that blocks merging until conditions are met, for example “at least one approval” or “tests must pass”.

The problem: evidence that points at the wrong commit

Here is the scenario in concrete steps.

  1. You open a PR. CI runs on commit A, and all checks pass.
  2. A reviewer reads commit A and approves.
  3. An agent then pushes commit B to fix a failing edge case.
  4. The PR page may still show an approval and green marks from before.

Neither of those says anything about commit B. Yet B is the head commit, so B is what gets merged.

Why does this matter? A green check and an approval are evidence. Evidence is only useful if it describes the thing you are about to ship. If the evidence is about A, you are merging B on trust.

Before agents, this gap existed too, but people usually noticed when they pushed a late change themselves. With an agent pushing fixes on its own, late commits become a normal part of the workflow. So the rule needs to be enforced by the repository, not remembered by people.

The central rule of this article is: approval evidence, meaning status checks and review approvals, must be tied to the exact commit that is merged.

Claude Ship as an example

Anthropic announced Claude Ship for GitHub pull requests on November 23, 2026. It is a good example of an agent that both writes fixes and takes part in approvals. It combines Code Review, which was already generally available, with two components that were in beta at the time of the announcement. Anthropic’s announcement

  • PR Steward handles what holds up a PR. It can push a patch for a review comment, address failing CI, or resolve a merge conflict. It leaves a comment explaining what it changed and how to undo it. The announcement says Steward “is designed not to approve or merge pull requests”.
  • Claude Approvals reads a policy file that the team keeps on the repository’s default branch. It decides whether a change can be approved or needs a human reviewer. Teams can configure branch protection to require its green light.

The announcement also lists practical limits:

  • It is available on Claude Team and Enterprise plans, for repositories on GitHub.
  • It is not available to organizations with Zero Data Retention, the HIPAA configuration, or customer-managed encryption keys.
  • Usage is billed on tokens. Claude Approvals has no base charge, but a policy that uses Claude’s review triggers a billed Code Review, even in observe mode.
  • Anthropic recommends running the approval policy in observe-only mode first. In that mode it records its decisions without blocking anything, so you can compare them with your own before relying on them.

The announcement says Claude Ship “works with existing branch protection and required checks”. What can merge depends on the developer’s permissions and the repository’s branch rules. It does not say how a new push affects an earlier approval. That is exactly the part your repository’s own rules have to cover.

Why green checks alone are not enough

Even on the right commit, a green check does not mean “safe”.

A typo fix and a change to an authorization check can both pass CI. For the second one, the important questions are which user roles the tests tried, and whether they tested access that should be denied. CI only tells you that the tests that exist have passed.

That is why a sensible trial policy treats changes differently. It could allow automatic approval for documentation changes. It could require an accountable human reviewer for authorization code or database migrations.

The commit problem sits on top of that. Suppose commit A only changed documentation and was approved automatically. Then the agent pushes commit B, which touches authorization code. The earlier decision no longer fits. Both the checks and the approval need to be evaluated again on B.

Branch protection settings that enforce it

GitHub has four settings that tie evidence to the latest commit. Managing a branch protection rule

Setting What it does Why it matters when an agent pushes
Dismiss stale pull request approvals when new commits are pushed Removes an approval when commits that change the PR’s diff are pushed. The PR needs a new approval before it can merge. An approval of A cannot be reused for B.
Require approval of the most recent reviewable push The most recent reviewable push must be approved by someone other than the person who pushed it. Whoever pushed last cannot approve their own push. GitHub presents this as an alternative to dismissing every stale review.
Require status checks to pass before merging Blocks merging until the checks you select pass. Required checks must pass on the latest commit SHA. Checks from earlier commits do not count.
Require branches to be up to date before merging The PR branch must include the latest changes from the target branch before merging. Checks then reflect your PR combined with the current main, not an older one.

A “stale” approval simply means an approval given to an older version of the PR.

On required checks, GitHub’s troubleshooting guide is explicit: “Required checks must pass on the latest commit SHA” and “Checks from earlier commits don’t satisfy the requirement.” One detail: GitHub also creates a temporary test merge commit (your PR combined with the target branch). If that commit has a status, it is the one that must pass; otherwise the head commit must. Troubleshooting required status checks Stale-review dismissal and the “up to date” option are described in About protected branches.

Pick between the first two settings on purpose. Dismissing stale approvals is stricter: every code-changing push needs a fresh approval. Requiring approval of the most recent push is lighter, but still stops the last pusher from approving their own push.

Step by step: create the rule

These steps run in the GitHub web interface, on the repository you want to protect. They follow GitHub’s documentation for a classic branch protection rule.

  1. Open the repository’s main page and click Settings. If you do not see the tab, open the More menu, then click Settings.
  2. In the sidebar, under “Code, planning, and automation”, click Branches.
  3. Under “Branch protection rules”, click Add classic branch protection rule.
  4. In Branch name pattern, type the branch to protect, for example main.
  5. Select Require a pull request before merging. This means nobody can push straight to main; changes must arrive through a PR.
  6. Under it, select Require approvals and choose how many approvals are needed.
  7. Still under it, select Dismiss stale pull request approvals when new commits are pushed, or Require approval of the most recent reviewable push, depending on how strict you want to be.
  8. Select Require status checks to pass before merging. In the search field, find and select the checks your CI reports, such as your test job.
  9. Optionally select Require branches to be up to date before merging.
  10. Click Create. When you edit an existing rule later, the button is Save changes.

Expected result: on the next PR to main, the merge button stays blocked until the selected checks pass on the latest commit and the required approval exists.

How to verify the setup

Do not trust the settings until you have watched them work. Use a test repository, or a test branch, so nothing important is at risk.

  1. Open a PR and let it pass. Push commit A. Wait until the required checks are green. Have someone approve.
  2. Push a change. Push commit B that changes code, by hand or by letting the agent fix something.
  3. Look at the PR page. Expected: the earlier approval is shown as dismissed, or the PR asks for approval of the latest push. The required checks show as pending or running for B, not green from A. The merge button is blocked.
  4. Wait and re-approve. When the checks pass on B and someone approves again, the merge button should unlock.
  5. Compare policy decisions. If an approval policy runs in observe-only mode, compare its recorded decision for B with what a human reviewer would have decided.

If step 3 still shows a usable approval and green checks, the rule is not applied to that branch. Check the branch name pattern first.

Common mistakes

  • Protecting the wrong branch. A typo in the branch name pattern means the rule silently applies to nothing.
  • Requiring checks that never run. If a required check is not triggered for a PR, the PR stays blocked waiting for it. Make sure CI runs on every push to PR branches.
  • Turning on only “Require approvals”. Without dismissing stale approvals or requiring approval of the latest push, an old approval can still count after new commits.
  • Trusting the agent’s summary comment instead of the diff. A comment that says “fixed the edge case” is helpful, but the reviewer should still read what commit B changed.
  • Letting an approval policy block merges on day one. Run it in observe-only mode first and compare its decisions with yours.

Measuring the trial

After the rules are in place, measure three things:

  • the time from opening a PR to meeting the merge requirements;
  • how often the author has to come back for a fix;
  • how often automated patches are reverted.

If agent fixes arrive faster but PRs still wait just as long for human approval, the bottleneck has moved, not disappeared.

Commits made by an agent in an isolated environment, as described in running coding agents in sandboxes and Git worktrees, are still new commits. They go through the same rules.

Conclusion

A green check or an approval is evidence about one commit. When agents can push to pull requests, configure branch protection so that:

  • new commits dismiss old approvals, or the latest push needs approval from someone else;
  • required checks must pass on the latest SHA.

Then run any approval policy in observe-only mode first, and decide which kinds of change always need a person. Claude Ship is one tool that fits into those rules. The rules themselves belong to your repository.

Written by Duy Pham Independent developer. I build the apps on this site and write about how they work.

More about me