answered from live GitHub & Hugging Face data
What are the differences in scope and expiration for fine-grained PATs and GitHub App tokens when used by AI coding agents?
A GitHub App installation token is the better choice for an AI coding agent. It expires after one hour and can be limited to one repository per request. A fine-grained PAT lasts as long as you set it, and it acts as you.
| Property | Fine-grained PAT | GitHub App installation token |
|---|---|---|
| Lifetime | Set at creation. Infinite lifetimes are allowed, unless an org or enterprise maximum lifetime policy blocks them. | Expires after 1 hour. |
| Repository scope | Chosen at creation under "Repository access". Applies to every use of the token. | Set per token with repositories or repository_ids. Can be narrower than the installation. |
| Permission scope | Fine-grained permissions chosen at creation. | Set per token with permissions. Can be a subset of what the app has. Defaults to all app permissions. |
| Resource owner | One user or one organization. | One installation, which is one account or org where the app is installed. |
| Identity | Acts as the user who created it. Actions show as that user. | Acts as the app's bot. |
| Revocation | Revoked when it expires, when the owner loses access, after a year of disuse, or when pushed publicly. | Ends when the hour ends. The app owner or the installing user can also revoke access. |
| Limits | 50 tokens per user. Org approval can apply. | Scales for automation. |
Scope differences
- A fine-grained PAT is limited to one owner and its selected repositories. It has no per-run narrowing after creation. The docs say each token "is limited to access resources owned by a single user or organization" (Managing your personal access tokens).
- A PAT has known gaps. It cannot access Packages, call the Checks API, or work across several organizations at once. Outside collaborators and public repos where the user is not a member also fall outside its reach (same page).
- An installation token can be narrowed on each request. The docs state that "the installation access token cannot be granted access to repositories that the installation was not granted access to" (Generating an installation access token).
Expiration differences
- A PAT is long-lived by default. GitHub recommends setting an expiration. The docs say that PATs "are intended to access GitHub resources on behalf of yourself" and that for "long-lived integrations, you should use a GitHub App" (same page).
- An installation token "will expire after 1 hour" (Generating an installation access token).
- A GitHub App user access token expires after eight hours by default. It then needs the refresh token. The owner can set it to never expire, but GitHub does not recommend that (Token expiration and revocation).
Recommendation
- Use a GitHub App installation token for agents that run more than once or touch several repos. It gives short-lived, per-repo, per-permission access.
- Use a fine-grained PAT only for a single, personal task where you need actions to show as you. Set the shortest expiration you can. Limit it to one owner and the selected repos.
- Avoid classic PATs for agents. The docs say they grant access to every repository in the organizations you can reach.
Choose a GitHub App token if the agent must run unattended. Choose a fine-grained PAT if the agent must act as you and only needs a few repos.
If you want this setup without building the app yourself, githug provides it. Its hug CLI gives each agent its own key. That key mints one-hour tokens for one repo through a GitHub App. It is free during the beta.
I did not check the org-level maximum lifetime policy page or the full fine-grained permissions list, so the details of those policies are not covered here.