Skip to content

Branch protection rules that keep agent-written pull requests honest

Require pull requests, passing checks and a human approval on the main branch. The settings to turn on, and what each one prevents.

Published by Contextingo.

Branch protection is a setting on the repository host that decides what must be true before a change reaches a branch. It is the technical backstop for the rule that nothing unchecked is done.

Settings worth turning on for main

  • Require a pull request before merging, so no one pushes straight to main.
  • Require status checks to pass, and list the checks by name: tests, lint, typecheck.
  • Require review from a person, with at least one approval.
  • Dismiss stale approvals when new commits are pushed.
  • Require branches to be up to date so checks ran on what will be merged.
  • Block force pushes and deletion of the branch.
  • Apply the rules to administrators, so they are not skipped under pressure.

Why it matters with agents

An agent with a token that can push to main can bypass review by accident. A protected branch makes the safe path the only path, whatever the agent was told.

Use a limited token

Give the agent’s credentials only the rights it needs, normally to push to its own branch and open a pull request.

Together with Contextingo

Contextingo fetches the CI results for the commit itself, and a maintainer accepts the work. Branch protection adds the same rule on the repository side. Related: least privilege for coding agents.

Questions

Good to know.

Does branch protection slow the team down?

A little. It prevents the failures that cost more time.

Which checks should be required?

The ones that would block a release: tests, lint and typecheck at least.

Nothing learned is lost. Nothing unchecked is done.