Rightshold™ Sign up

Answers · agent safety

How do I make an AI coding agent's commits go through pull requests instead of straight to main?

Last updated

TL;DR: Give the agent its own GitHub identity with write access, not admin, and protect the default branch so that identity can't push to it directly. On GitHub, a ruleset or branch protection rule that requires a pull request before merging, with at least one approval, does that. Add an approval of the most recent reviewable push by someone other than the person who pushed it, so an agent can't add commits after a human approved. Keep required status checks passing, and leave force pushes and deletions blocked (the defaults). The setting people miss: by default branch protection rules don't apply to repository admins, so an agent running with your admin token skips them unless you turn on Do not allow bypassing the above settings. In rulesets, only actors on the bypass list can bypass, so keep agents off it. GitHub's own Copilot cloud agent shows the target pattern: it pushes only to its own copilot/ branch, can't approve or merge its pull requests, and the person who asked for the change can't approve it either.

What should I check, step by step?

1. Create a separate identity for the agent (a machine account or a GitHub App) with write access to the repository, never admin. Pair it with the commit author setup in the related git-identity answer.

  1. Protect the default branch: in a ruleset, turn on Require a pull request before merging with at least 1 required approval (or the same in a classic branch protection rule).
  2. Turn on Require approval of the most recent reviewable push, and Dismiss stale pull request approvals when new commits are pushed, so an approval covers what actually merges.
  3. Require status checks to pass, and for checks that matter, pin the expected source to the GitHub App that runs them. GitHub's docs note that any person or integration with write access can set a commit status, which includes the agent.
  4. Classic branch protection: turn on Do not allow bypassing the above settings so admins (and an agent using an admin's token) are held to the rule. Rulesets: keep the agent's account or app off the bypass list.
  5. Keep Block force pushes and Restrict deletions on. Both are on by default and stop an agent from rewriting or deleting the protected branch.
  6. Add CODEOWNERS with Require review from Code Owners for paths such as .github/workflows, deployment config and auth code, so agent changes there need the owning team.
  7. Test it: as the agent's identity, try git push to main and confirm GitHub rejects it with a protected-branch error, then open a pull request and confirm it can't be merged without the approval.
  8. Check your plan: protected branches work in public repositories on GitHub Free, and in private repositories on GitHub Pro, Team and Enterprise. Bypass lists are only available in repositories owned by an organization.

How GitHub's Copilot cloud agent is fenced

GitHub's risks-and-mitigations page says the agent can push only to a single branch (a new copilot/ branch, or the pull request's branch when mentioned on one), can't run git push itself, is subject to branch protections and required checks, can't mark its pull requests ready for review or approve or merge them, and doesn't trigger GitHub Actions workflows until someone with write access approves the run.

Rulesets vs classic branch protection

Rulesets layer: if several rulesets and branch protection rules target the same branch, all of them apply and the most restrictive version of each rule wins. Only one classic branch protection rule applies to a branch at a time.

How do I ask Rightshold about this (free, no key)?

Add the MCP server https://www.rightshold.com/mcp to Claude, Cursor, ChatGPT, Grok or VS Code, then ask: “Before I approve this agent-written pull request, scan its description and the instructions file it changed for hidden text or instructions aimed at the reviewer or the next agent.”

One-click setup

{
  "tool": "scan_text",
  "arguments": {
    "text": "<the pull request description, or the changed AGENTS.md / CLAUDE.md / instructions file>"
  }
}

Rightshold does not configure GitHub, review pull requests or hold repository permissions. It scans text you give it and records signed run summaries you send. Not legal advice.

What are the sources?

Related

Not legal advice. JSON · Markdown · All answers

Get a free API key in one call

No card and no email needed. 100 free credits; the license and policy checks stay free without a key.

curl -s -X POST https://www.rightshold.com/v1/accounts/signup -H "Content-Type: application/json" -d '{"accept_terms":true}'
export RIGHTSHOLD_API_KEY=rs_...   # the api_key from the reply (shown once)
curl -s https://www.rightshold.com/v1/licenses/check -H "Authorization: Bearer $RIGHTSHOLD_API_KEY" \
  -H "Content-Type: application/json" -d '{"license":"MIT","intended_use":{"commercial_use":true}}'