answered from live GitHub & Hugging Face data
What are the differences in scope and expiry between fine-grained PATs and GitHub App installation tokens for AI agents?
For AI agents, use a GitHub App installation token. It expires after one hour and can be limited to chosen repositories and permissions. A fine-grained personal access token (PAT) is tied to one person and can last much longer.
| Property | Fine-grained PAT | GitHub App installation token |
|---|---|---|
| Who it acts as | The user who created it. Tokens "are tied to the user who generated them" (docs). | The app. "API requests made by an app installation are attributed to the app" (docs). |
| Expiry | Chosen at creation. "Infinite lifetimes are allowed but may be blocked by a maximum lifetime policy" (docs). | "The installation access token will expire after 1 hour" (docs). |
| Repository scope | Set to one resource owner. Repositories are chosen from "Only select repositories" or all. | Optional repositories or repository_ids in the token request. Up to 500 repositories. It "cannot be granted access to repositories that the installation was not granted access to." |
| Permission scope | Fine-grained permissions chosen at creation. | Optional permissions in the request. If omitted, the token gets "all of the permissions that were granted to the app." It "cannot be granted permissions that the app was not granted." |
| Limit on count | 50 tokens per user. | No stated per-user token limit in the pages I read. |
| Inactivity | Removed after one year unused, per the PAT docs. | Not stated for installation tokens. The token itself expires after one hour. |
Scope gaps that matter for agents
Fine-grained PATs cannot do everything. The docs list these gaps:
- Contributing to public repositories where the user is not a member.
- Contributing to repositories where the user is an outside collaborator.
- Accessing multiple organizations at once.
- Accessing Packages.
- Calling the Checks API.
- Accessing user-owned Projects.
Classic PATs cover some of these gaps. They also grant access to "all repositories within the organizations that you have access to" (docs). That is the wider scope to avoid for agents.
Organization controls
- Fine-grained PATs can require administrator approval. The default is "Require administrator approval" (docs).
- The default maximum lifetime for fine-grained PATs in an organization is 366 days.
- Tokens that break an organization's lifetime policy are blocked. They are not revoked.
Other token types to know
- A GitHub App user access token "will expire after eight hours by default" and must be refreshed (docs). Use it only when the agent must act as a specific user.
- Any token pushed to a public repository is revoked automatically (docs).
Recommendation
Use a GitHub App for agents. The PAT docs say long-lived integrations should use a GitHub App. A short token limited to one repository is safer than a long-lived PAT tied to a person.
- Choose a fine-grained PAT if one person runs a single script against their own repositories. Set the shortest practical expiry.
- Choose a GitHub App installation token if an agent works on an organization's repositories. Also choose it if you run more than one agent.
If you run more than one agent, give each agent its own identity. One shared app shows all agents as the same bot. githug is one option for this. Each agent gets its own key. That key mints one-hour tokens that work on one repository, through a GitHub App with least-privilege permissions. The tool is in beta and free for now.