Repository navigation
Description
Describe the feature or problem you’d like to solve
AI coding agents (Copilot, Claude Code, Cursor, etc.) need GitHub access via gh to create branches, push commits, and open PRs. But gh auth login authenticates as the full user — so any process with access to the token can operate across every repo you have access to with full permissions.
This is a real problem when running AI agents. An agent scoped to work on one repo can read, write, or merge across all your repos. But if you don't authenticate at all, the agent becomes pretty useless and you're constantly stepping in to do things manually.
Fine-grained PATs partially solve this — they support per-repo and per-permission scoping — but they need manual creation and rotation outside the gh flow, and they're themselves one of the main things being stolen by malicious packages right now. Token exfiltration from env vars and config files is one of the most common supply chain attack vectors.
MCP servers are another option but they come with their own problems. Most AI agents default to the gh CLI first — it's what they know and it's already there. MCP servers often need PAT tokens anyway, so you're back to the same theft risk. They also add another dependency and integration layer that can break, and not every agent runtime supports them. For most setups, gh is the path of least resistance, so it makes sense to make that path safer.
Proposed solution
Allow gh auth login to accept repo and permission constraints that are enforced locally by the CLI. That way processes using gh (including AI agents) can't exceed the boundary you set, even if the underlying credential has broader access.
Something like:
gh auth login --scope-repo owner/repo-name
# Restrict with specific denials
gh auth login --scope-repo owner/repo-name --deny merge,delete
# Multiple repos
gh auth login --scope-repo owner/repo-a --scope-repo owner/repo-b
The CLI would filter or reject API calls outside the declared boundary before they hit GitHub's API. This doesn't replace branch protection or fine-grained PATs — it's a local boundary for the common case of handing gh access to an agent
Additional context
The main use case is AI coding agents that need push/PR access to a specific repo but shouldn't be able to touch anything else. This is basically the same idea as Docker's --read-only or git safe.directory — a local constraint on top of existing credentials.
Activity
williammartin commentedon Mar 25, 2026
Thanks for the writeup. There's some overlap with #12624 (read-only).
As over there, I think what I'd like to see is a bit more exploration on the boundaries this could or couldn't enforce. For example, if you are running
--yolo, there's nothing that would stop an agent from modifying on disk configuration. We'd also have to be very careful aroundgh api, or even `curl -H "Authorization: bearer $(gh auth token)".Cross linking from #12522 too.
david-kort commentedon Jun 2, 2026
I love using the cli instead of a token-heavy MCP, and my agents are working great with it. They tend to work the most with
gh api *.Only problem still is that as a repo owner, I can't just hand the cli to the agent without worrying about vibe-merging stuff into protected branches, etc. I just want the cli access to be limited to scopes like issue/pr reads and writes, but not merges and so on. Without scopes, the usability stays highly limited in my agent workflows.
olejorgenb commentedon Jun 2, 2026
https://honnibal.dev/blog/locking-down-gh#:~:text=Step%205%3A%20Replace%20gh%20auth%20with%20a%20read%2Donly%20PAT - seems it's possible to use a "fine-grained PAT" for authentication now
AriESQ commentedon Jun 12, 2026
Beware this advice, it does not work in practice.
BagToad commentedon Jun 12, 2026
Fine grained PATs are supported. If you are having problems, please make an issue.
woodruffw commentedon Jul 22, 2026
I think it would be really great to have some form of this: it's increasingly common for agents (or just normal systems) to call or be passed some form of
gh auth token, which is frequently extremely overscoped for a given task.It would be awesome if there was some way to attenuate an existing token, e.g.
gh auth token --readonlyor similar.dmitry-markin commentedon Jul 27, 2026
Ideally GitHub web interface shown after
gh auth loginshould allow fine-grained repo & permission selection with permissions enforced on GitHub side, not client side.