This guide describes a team workflow for a coding agent on GitHub, where the agent writes code, tests and documentation while people set the direction, review each change and merge it. It is written for tech leads and platform engineers who want an agent in the team without giving it the last word. It covers the run, the branch and pull request protocol, a ruleset for the main branch, approval cards and architecture decision records (ADRs). The GitHub settings follow the GitHub Docs and REST API version 2026-03-10, the commands use GitHub CLI 2.106.0, and the ADR template follows MADR 4.0.0. All of them were checked on 1 December 2026.
Split the roles
Write the split down before the first run, in the instructions file that your agent reads at the start of each session.
- The agent writes code, tests and documentation.
- The agent proposes outward actions, and a person approves each one.
- People set the direction by writing and ordering the backlog.
- People review each pull request and merge it.
- The team decides architecture questions by vote, and the agent records the result.
One rule needs no exceptions: the agent never merges. The rest of this guide shows how to enforce that rule in GitHub itself, and not only in the prompt.
One backlog item per coding run
A coding run starts from one backlog item, which needs clear acceptance criteria, and ends with one pull request. The agent reads the item, makes the change, runs the tests and opens the pull request.
This limit has practical effects:
- The diff stays small enough to review in one sitting.
- Each pull request traces back to one item.
- A revert removes one change, not three.
If the agent finds that an item is too large, it does not grow the pull request. Instead it proposes new backlog items, which a person approves before they exist.
Branch and pull request protocol
Every agent session follows the same fixed protocol, which makes agent work easy to find and easy to review.
- Start from the latest default branch.
- Create one branch per run, named
agent/<issue-number>-<short-slug>, for exampleagent/412-cart-empty-state. - Push only to that branch and never to the default branch.
- Open one pull request from that branch.
- Link the backlog item with a closing keyword, for example
Closes #412. - Request a review from the team.
GitHub closes the linked issue when the pull request merges into the default branch, and the supported keywords include close, closes, fixes and resolves.
Store the template at .github/pull_request_template.md so that GitHub fills the pull request body with it.
## Backlog item
Closes #
## What changed
-
## Tests
- [ ] New or changed behaviour has tests
- [ ] All required checks pass
## Documentation
- [ ] Docs updated, or not needed because:
## Architecture decisions
- ADRs that apply:
- [ ] This change needs a new ADR
## Out of scope
-
The “Out of scope” section matters for agent work, because it shows the reviewer what the agent saw and chose not to change. For a section that records AI involvement, see what engineering teams that use coding agents should document.
Protect the main branch with a ruleset
A ruleset enforces the review rules in GitHub itself. This one targets the default branch and requires a pull request with one approval and passing status checks.
{
"name": "main: reviewed pull requests only",
"target": "branch",
"enforcement": "active",
"bypass_actors": [],
"conditions": {
"ref_name": {
"include": ["~DEFAULT_BRANCH"],
"exclude": []
}
},
"rules": [
{ "type": "deletion" },
{ "type": "non_fast_forward" },
{
"type": "pull_request",
"parameters": {
"required_approving_review_count": 1,
"dismiss_stale_reviews_on_push": true,
"require_last_push_approval": true,
"require_code_owner_review": false,
"required_review_thread_resolution": true,
"allowed_merge_methods": ["squash"]
}
},
{
"type": "required_status_checks",
"parameters": {
"strict_required_status_checks_policy": true,
"required_status_checks": [
{ "context": "test" },
{ "context": "lint" }
]
}
}
]
}
Create it with the REST API:
gh api --method POST repos/OWNER/REPO/rulesets \
-H "X-GitHub-Api-Version: 2026-03-10" \
--input main-ruleset.json
You can also import the JSON file on the Rulesets page in the repository settings.
What each rule does:
deletionblocks deleting the branch.non_fast_forwardblocks force pushes.required_approving_review_count: 1requires one approval before merge.dismiss_stale_reviews_on_pushremoves approvals when new commits arrive.require_last_push_approvalrequires that someone other than the last pusher approves the most recent push.allowed_merge_methodsallows only squash merges, so each item lands as one commit.strict_required_status_checks_policyrequires the branch to be up to date before merge.
The test and lint contexts are examples, so use the names of your own check jobs. You can add an integration_id to each check, and GitHub then accepts that status only from that app. For what your checks should block, see AI code review in GitHub Actions.
Stop the agent from bypassing the rules
A ruleset only helps if the agent cannot step around it. Only actors on the bypass list can bypass a ruleset, and that list can hold repository roles, teams, GitHub Apps and Dependabot.
- Give the agent its own identity, for example a GitHub App, instead of letting it use a person’s account.
- Give that identity write access and not admin, because an admin can edit the ruleset.
- Keep the agent’s app off every bypass list, and also check the teams and roles that the identity belongs to.
- If you also use classic branch protection, turn on “Do not allow bypassing the above settings”, because without it admins bypass the rule.
- In Settings, Actions, General, turn off “Allow GitHub Actions to create and approve pull requests”. This setting controls whether
GITHUB_TOKENcan create and approve pull requests.
Then test the result with the agent’s own token:
GH_TOKEN="$AGENT_TOKEN" gh api repos/OWNER/REPO/rulesets/RULESET_ID \
-H "X-GitHub-Api-Version: 2026-03-10" \
--jq .current_user_can_bypass
The answer should be never, not one of the other values always, pull_requests_only or exempt.
The approval rule stops a merge without review, but it does not stop the agent from clicking merge after a person approves. To limit merges to people, use the classic branch protection setting “Restrict who can push to matching branches” and list only the human team there. This works because GitHub applies branch protection to merges of pull requests too. The setting needs an organization repository on GitHub Team or GitHub Enterprise Cloud, or a public repository in a GitHub Free organization. Also leave the merge tool out of the agent’s tool set.
GitHub Copilot cloud agent follows the same principle: it cannot approve or merge its own pull requests, and the person who asked for the pull request cannot approve it either.
Approval cards for outward actions
Code goes through a pull request, but other actions need a check too. An outward action is anything that other people see, such as a chat message, a new issue, a comment or a pull request.
The agent does not run these actions itself. Instead it writes a card that a person approves or rejects, and a separate executor runs only the approved cards. The executor holds the write credentials, not the agent.
{
"id": "card-0193",
"action": "github.create_pull_request",
"target": "OWNER/REPO",
"summary": "Open a pull request for backlog item #412",
"payload": {
"base": "main",
"head": "agent/412-cart-empty-state",
"title": "Cart: show an empty state",
"body": "Closes #412"
},
"reason": "All acceptance criteria for #412 pass locally.",
"requested_by": "agent",
"on_behalf_of": "user-id-of-the-person-who-started-the-run",
"status": "pending"
}
Rules that keep cards useful:
- Show the full payload, not only the summary.
- Bind the approval to that exact payload, so that a changed payload needs a new card.
- Let cards expire after a set time.
- Log who approved or rejected each card, and when.
- Send a rejection reason back to the agent.
Architecture decisions by team vote
An ADR records one decision, and the original format from 2011 has five parts: a title, the context, the decision, a status and the consequences. ADRs get sequential numbers that are not reused, and a replaced ADR stays in the repository with the status “superseded”.
ADRs also help the agent. It reads the accepted ADRs before each run so that it follows past decisions, but it does not take the decisions itself.
A workflow that keeps people in charge:
- A person or the agent proposes an ADR in a pull request, with status “proposed”.
- The team discusses and votes.
- The agent records the options, the vote and the outcome in the file.
- A person reviews and merges the ADR pull request.
Store ADRs in the same repository as the code, for example as docs/adr/0007-server-side-cart-state.md. This template is based on MADR 4.0.0 and adds a section for the vote:
---
status: proposed
date: 2026-12-01
decision-makers: core team
---
# Keep cart state on the server
## Context and problem statement
## Considered options
1.
2.
## Vote
| Option | Votes |
| -------- | ----- |
| Option 1 | |
| Option 2 | |
Voting closed on:
## Decision outcome
Chosen option:
### Consequences
- Good, because
- Bad, because
In practice
In 2026, an international cosmetics retailer started a second project to rebuild its digital landscape AI first. An AI agent writes most of the code while a small core team steers it, and we are part of that core team, where we lead the frontend architecture.
One repository holds the code, tests, documentation and ADRs. The agent writes the code, tests and documentation, while people set the direction, review each change and merge it. The agent never merges.
In a coding run, the agent takes one backlog item and opens a pull request for review. It shows each action, such as a message, an issue or a pull request, on a card that a person approves first.
The core team decides ADRs by vote, and the agent records the result. We asked for the branch and pull request protocol that every agent session follows, and for one required approval before a merge to the main branch.
Checklist
- Write the role split into the agent’s instructions.
- Limit each coding run to one backlog item and one pull request.
- Name agent branches
agent/<issue-number>-<short-slug>. - Add
.github/pull_request_template.mdwith a backlog link. - Create a ruleset for the default branch with one approval and required checks.
- Keep the agent’s identity off all bypass lists.
- Check
current_user_can_bypasswith the agent’s token. - Restrict merges to the human team.
- Route every outward action through an approval card.
- Record ADRs in the repository after a team vote.
If you want this workflow in your repositories, see coding agent rollout. For the review rules and checks for agent pull requests, see AI code review in CI, or get in touch.
Sources
- GitHub Docs: About rulesets
- GitHub Docs: Available rules for rulesets
- GitHub Docs: Creating rulesets for a repository
- GitHub Docs: REST API endpoints for rules
- GitHub Docs: About protected branches
- GitHub Docs: Managing GitHub Actions settings for a repository
- GitHub Docs: Creating a pull request template
- GitHub Docs: Linking a pull request to an issue
- GitHub Docs: Risks and mitigations for Copilot cloud agent
- GitHub: ruleset-recipes
- Cognitect blog: Documenting architecture decisions (2011)
- MADR: Markdown Architectural Decision Records