A team wants their Copilot agent to autonomously implement small bug fixes: create a branch, commit the fix, and open a pull request without any human steps. Which two GitHub token permissions are minimally required for the agent to complete this workflow?
Select an answer to reveal the explanation.
Short Explanation and Infographic
Autonomous branch-create-commit-PR is a two-permission job: write to 'contents' lets the agent create a branch and push commits, and write to 'pull-requests' lets it open the PR. Read-only access won't allow any modifications, and admin access is overkill (and dangerous) — the agent never needs to bypass branch protections. Think of it as giving someone a pen and a mailbox key, not the master key to the whole building.
Full explanation below image
Full Explanation
When a Copilot agent needs to autonomously create a branch, commit changes, and open a pull request, it must interact with two GitHub API resource categories:
1. Contents (write): The Git Contents API is used to create and update files in a repository. Creating a branch is also a ref operation under the Git Refs API, which falls within the contents scope. The agent needs write access to create the branch ref and to push commits (create/update blobs and trees).
2. Pull requests (write): Opening a pull request requires calling the Pull Requests API (POST /repos/{owner}/{repo}/pulls). Without write access to this scope, the API call returns a 403 Forbidden error.
These two write permissions represent the minimum viable set for this workflow.
Option A is incorrect because read-only access to both permissions allows the agent to list files and list pull requests, but not to create or modify either. The agent would be able to inspect the repo but could not create a branch, commit code, or open a PR.
Option C is incorrect because admin access is far more than what is needed and introduces significant security risk. Admin access includes capabilities like deleting the repository, modifying branch protection rules, and managing webhooks — none of which are required for this workflow. The principle of least privilege is a core security best practice for agent permissions.
Option D is incorrect because actions write access (used to trigger workflow runs) and checks write access (used to create check runs and test annotations) are completely unrelated to the branch-create-commit-PR workflow. These would be needed for separate CI orchestration scenarios, not for the basic autonomous commit and PR flow.
Option B is correct. contents: write plus pull-requests: write is the minimal, least-privilege permission set for this autonomous workflow.