Connect GitHub to let an Agent inspect repositories, work with issues and pull requests, review source code, and examine GitHub Actions runs.
Agent Barn stores the token as an encrypted Agent Secret, and configures an aai-cli GitHub profile when the Agent starts.
Connection model
- GitHub PAT
- Encrypted Agent Secret
- aai-cli profile
- Repository operations
The credential authenticates the Agent. The GitHub Skill supplies the aai-cli workflows the Agent runs against it.
Before you begin
You need:
- A GitHub account permitted to access the intended repositories
- Permission to create a personal access token
- Access to configure the Agent
agent.updateandagent.secret.managepermissions- Lifecycle permission when connecting a running Agent
- The GitHub owner or organization name
- The bare names of the intended repositories
- An access plan defining whether the Agent can read or write
Decide whether to use a Fine-grained personal access token, a Classic personal access token, or an existing Organization Shared Credential.
Choose a token type
Fine-grained personal access tokens are the preferred choice when the organization permits them.
Fine-grained PAT
Advantages: repository selection, granular permissions, and expiration controls.
Tradeoffs: may require organization approval and careful permission selection.
Classic PAT
Advantages: broad compatibility and familiar scopes.
Tradeoffs: scopes are broader and offer less repository-level control.
Use a Classic token only when a required workflow cannot use a Fine-grained token, or organizational policy requires it.
Plan the required permissions
Grant permissions based on the Agent’s intended workflow.
| Agent capability | Suggested Fine-grained permission |
|---|---|
| Read repository metadata | Metadata: Read |
| Read source files and commits | Contents: Read |
| Read pull requests | Pull requests: Read |
| Comment on or review pull requests | Pull requests: Read and write |
| Read issues | Issues: Read |
| Create or comment on issues | Issues: Read and write |
| Inspect workflow runs and logs | Actions: Read |
| Modify repository contents | Contents: Read and write |
Do not grant write permissions merely because they are available.
Classic token scopes
For a Classic PAT, Agent Barn’s validator recognizes repo for private and public repository access, public_repo for public-repository-only access, read:user, and read:org — the last is recommended for organization repositories.
The broader user and admin:org scopes also satisfy the identity and organization checks, but should not be granted merely for validation.
Public repositories
Agent Barn still expects a token for a configured GitHub integration. Public repository visibility does not bypass the encrypted credential and profile setup used by aai-cli.
Create the personal access token
Create a Fine-grained token
- Open your account’s developer settings.
- Go to personal access tokens.
- Choose Fine-grained tokens.
- Create a new token.
- Enter a descriptive name, such as
Agent Barn — Support Reviewer. - Set an expiration date.
- Select the intended resource owner.
- Select only the required repositories.
- Grant the minimum repository permissions.
- Create the token.
- Copy it immediately.
For a read-only code-review Agent, begin with:
Metadata: Read
Contents: Read
Pull requests: ReadAdd Pull requests: Read and write only if the Agent must post comments, submit reviews, approve, or request changes.
An organization may require administrator approval before the token can access its repositories.
Create a Classic token
- Open GitHub developer settings.
- Go to Tokens (classic).
- Create a new token.
- Enter a descriptive note.
- Set an expiration date.
- Select the minimum required scopes.
- Create and copy the token.
Public repositories
public_repo
read:user
read:orgPrivate repositories
repo
read:user
read:orgReview the broad access implied by repo before using the token.
Configure organization access
For repositories owned by a GitHub organization, confirm that:
- The token’s resource owner is correct
- The repository is included in the token’s repository selection
- The organization approved the token when approval is required
- The account can access the repository
- Organization authentication policies are satisfied
- The granted permissions match the intended operation
A correctly formatted token can still receive 404 for a private repository when the account or token lacks access.
Understand the Agent Barn fields
| Field | Purpose |
|---|---|
| Personal access token | Authenticates the GitHub account |
| Owner / Org | Default GitHub user or organization |
| Repositories | Optional repository names used to build profiles |
Enter bare repository names
agent-barn
aai-cli
websiteDo not enter owners or URLs
aai-labs/agent-barn
https://github.com/aai-labs/agent-barnThe same Owner / Org value is stored as the GitHub profile’s owner and org.
Repository list versus token access
The optional repository list configures aai-cli profiles. It is not an enforcement boundary.
GitHub token
Authorizes every request. It can reach any repository GitHub allows it to reach, whatever Agent Barn lists.
This is the real security boundary.
Agent Barn repository list
Creates convenient profile defaults, so commands need fewer explicit flags.
This is a convenience, not an authorization control.
Even when a repository list is configured, an aai-cli command can explicitly pass another --owner and --repo. GitHub then authorizes the request using the token. To prevent access to another repository, restrict the token in GitHub.
Connect GitHub in Agent Barn
- Stop the Agent, or begin the web interface’s restart-aware edit flow.
- Open the Agent.
- Go to Configuration.
- Select Keys & integrations.
- Select Edit.
- Add GitHub under Integration credentials.
- Choose Enter credentials.
- Paste the personal access token.
- Enter the GitHub owner or organization.
- Add the intended repository names.
- Apply the configuration.
- Restart the Agent if it was running.
- Validate the credential.
- Test repository access.
The token value becomes hidden after it is saved.
Use a Shared GitHub Credential
GitHub is supported by Organization Shared Credentials. To attach one:
- Open the Agent’s integration configuration.
- Select GitHub.
- Choose Use shared credential.
- Select the named GitHub credential.
- Apply the configuration.
- Restart the Agent.
- Validate and test access.
Assign the GitHub Skill
The credential supplies authentication. The GitHub Skill supplies detailed instructions for using GitHub through aai-cli.
If the active Template requires the GitHub Skill:
- Open the Agent’s Skills configuration.
- Confirm that GitHub is assigned.
- Confirm the expected Skill version.
- Save the Agent configuration.
- Start the Agent.
Agent Barn may mount eligible Built-in provider Skills from configured credentials at startup. Explicit Template Skill requirements still require an explicit Skill assignment.
Validate the credential
- Open Keys & integrations.
- Find GitHub.
- Select Validate.
- Confirm the authenticated GitHub username.
- Review any missing permissions.
- Resolve warnings before production use.
Validation begins with:
GET https://api.github.com/userFor a Classic PAT, Agent Barn inspects the reported OAuth scopes. For a Fine-grained PAT with configured repositories, Agent Barn probes each repository and its pull request endpoint.
{
"validation_status": "valid",
"validation_identity": "octocat",
"validation_error": null,
"missing_scopes": []
}A token can authenticate successfully while returning warnings:
{
"validation_status": "warning",
"validation_identity": "octocat",
"validation_error": null,
"missing_scopes": [
"example-org/private-repo: Repository contents read access"
]
}Fine-grained validation without repositories
If the GitHub credential has no configured repository names, Agent Barn validates the token’s identity but does not probe repository access.
Token authentication: validated
Repository access: not testedVerify access
Verify repository listing
List the GitHub repositories available for the configured organization.aai-cli github repos list --limit 10 --profile github-workrepos list does not require a --repo value. Confirm that only expected repositories are returned. If unexpected repositories appear, restrict the token in GitHub.
Verify source access
Read README.md from the main branch of the agent-barn repository.aai-cli github source get main README.md \
--owner aai-labs \
--repo agent-barn \
--profile github-workEvery repository-specific command should explicitly include:
--profile github-work
--owner OWNER
--repo REPOSITORYVerify pull request access
aai-cli github prs list \
--owner aai-labs \
--repo agent-barn \
--state open \
--limit 10 \
--profile github-workTest comments or reviews only against a designated test pull request, and only when the token intentionally has write permission.
Verify issue access
aai-cli github issues list \
--owner aai-labs \
--repo agent-barn \
--limit 10 \
--profile github-workDo not begin by creating or editing issues unless the Agent’s role requires it.
Multiple repository profiles
When multiple repositories are configured, Agent Barn creates profiles such as:
github-work
github-work-2
github-work-3All profiles use the same token and owner, but have different default repositories. The Agent’s runtime context records the mapping:
github-work → aai-labs/agent-barn
github-work-2 → aai-labs/aai-cli
github-work-3 → aai-labs/websiteCommands can normally continue using github-work while explicitly passing --owner and --repo. Do not guess a numbered profile’s repository mapping — review the Agent’s generated integration context.
No configured repository
An empty repository list creates one profile without a default repo.
[profiles.github-work]
provider = "github"
auth_type = "bearer_token"
owner = "aai-labs"
org = "aai-labs"Repository-specific commands must then provide --repo REPOSITORY. Omitting it produces a configuration error.
Leaving the list empty does not mean “no repository access.” The token can still reach repositories allowed by GitHub.
Runtime behavior
When the Agent starts, Agent Barn:
- Decrypts the GitHub credential.
- Stores the token in the runtime secret store.
- Creates one or more
aai-cliprofiles. - Mounts eligible GitHub Skill instructions.
- Adds the configured owner and repository mappings to the tool context.
- Tells the Agent that credentials are already available.
Encrypted GitHub Agent Secret
│
▼
Agent start
│
├── Secret: github.token
├── Profile: github-work
└── GitHub Skill instructions
│
▼
GitHub APIRotate the token
- Create the replacement token in GitHub.
- Give it the intended repository access and permissions.
- Stop the Agent, or begin a restart-aware edit.
- Open Keys & integrations.
- Enter a complete replacement GitHub credential.
- Re-enter the Owner / Org and repository list.
- Apply and restart.
- Validate the replacement.
- Test repository and pull request access.
- Revoke the old token in GitHub.
Stored credential values cannot be retrieved or partially edited. Submit the complete replacement payload.
Change repository access
- Update the token’s repository selection in GitHub.
- Update its permissions if required.
- Update the Agent Barn repository profile list for clarity.
- Restart the Agent.
- Validate each configured repository.
- Run controlled source and pull request tests.
Changing the Agent Barn repository list alone does not change GitHub authorization.
Remove GitHub access
- Stop the Agent, or begin a restart-aware configuration edit.
- Identify any assigned Skill requiring
github. - Remove or replace that Skill when permitted.
- Open Keys & integrations.
- Select Remove for GitHub.
- Apply the configuration.
- Restart the Agent.
- Confirm that GitHub is no longer available.
- Revoke the token in GitHub.
Agent Barn rejects removal if a remaining assigned Skill requires the GitHub provider.
API reference
Add or replace a GitHub credential
The Agent must be stopped.
PATCH /api/v1/organizations/{organization_id}/agents/{agent_id}
Content-Type: application/json{
"secrets": [
{
"provider": "github",
"content": {
"token": "github_pat_REDACTED",
"owner": "aai-labs",
"org": "aai-labs",
"repos": [
"agent-barn",
"aai-cli"
]
}
}
]
}The owner and org fields normally contain the same GitHub login. Every token value in these examples is redacted — supply your own.
Configure no default repositories
{
"secrets": [
{
"provider": "github",
"content": {
"token": "github_pat_REDACTED",
"owner": "aai-labs",
"org": "aai-labs",
"repos": []
}
}
]
}The Agent must pass a repository name explicitly for repository-specific commands.
Attach a Shared GitHub Credential
{
"shared_credentials": [
{
"shared_credential_id": "3fd08cf5-59c5-494b-9449-a0413109a0ca"
}
]
}Validate GitHub
POST /api/v1/organizations/{organization_id}/agents/{agent_id}/integrations/github/validateValidation requires agent.secret.manage.
Remove GitHub
{
"removed_secret_providers": [
"github"
]
}Troubleshooting
Validation says the token is invalid or expired
Rotate and resubmit
Create or rotate the token in GitHub, submit the complete replacement credential, and validate again.
Validation succeeds but shows missing permissions
Authentication is not authorization
Authentication succeeded, but the token may not support the intended workflow. Review:
- Repository selection
- Contents permission
- Pull request permission
- Issue permission
- Actions permission
- Organization approval
A private repository returns 404
GitHub hides inaccessible repositories
GitHub often returns 404 when the authenticated token cannot access a private repository.
Check the owner, repository name, token repository selection, account membership, and organization approval.
A public repository cannot be read
Check names, token, and flags
Confirm that:
- The owner and repository are spelled correctly
- The token can authenticate
- A Fine-grained token has the needed public repository access
- A Classic token includes an appropriate public repository scope
- The command passes
--ownerand--repo
Validation did not test repository access
No repositories were configured
Fine-grained validation skips repository probes when the Agent Barn repository list is empty.
Add the intended repository names and validate again.
The Agent accesses repositories not listed in Agent Barn
The list is not a boundary
The repository list configures profiles, not authorization. Restrict the token’s repository selection and permissions in GitHub.
The Agent says --repo is missing
No default repository in the profile
No default repository is configured for the selected profile.
Pass --repo REPOSITORY explicitly, or add repository names to the GitHub credential.
Pull request listing works, but comments fail
Read is not write
The token probably has Pull requests: Read but not Read and write.
Grant write access only if the Agent should post comments or reviews.
Source access works, but GitHub Actions logs fail
Actions is a separate permission
Actions access uses a separate repository permission. Grant Actions: Read if the Agent needs workflow runs, jobs, or logs.
The token is awaiting organization approval
An administrator must approve it
An organization administrator must approve the Fine-grained token before it can access the selected organization resources.
A Shared Credential conflicts with a manual token
One source per provider
An Agent can use only one GitHub credential source.
Remove the manual credential before attaching the Shared Credential, or replace the Shared attachment with a manual credential.
GitHub was connected but the Agent cannot use it
Restart, Skill, profile, or token scope
Check that:
- The Agent restarted after the credential was saved
- The GitHub Skill is assigned when required
- The expected Skill version is pinned
- The
github-workprofile was generated - The requested repository is allowed by the token
- Startup logs contain no Skill mount errors
Recommended practices
- Prefer Fine-grained personal access tokens
- Use a dedicated GitHub identity for production Agents
- Select only the required repositories
- Grant Metadata and Contents read before adding write access
- Grant Pull request write only for reviewing or commenting Agents
- Keep Issue and Actions permissions aligned with the documented workflow
- Set token expiration dates
- Treat the token as the true repository authorization boundary
- Keep the Agent Barn repository list accurate for profile clarity
- Validate every configured repository
- Test read operations before write operations
- Rotate tokens on a documented schedule
- Revoke replaced and unused tokens
- Review organization token approvals regularly
- Never place tokens in Templates, Skills, prompts, or conversations
Next steps
Continue to Connect Jira to configure an Atlassian API token and scope an Agent to the intended Jira site and projects.