Accessing GitHub - Claude Platform Docs
Claude Platform Docs
Managed AgentsManage agent context

Accessing GitHub

Connect your agent to GitHub repositories for cloning, reading, and creating pull requests.

You can mount a GitHub repository to your session sandbox and connect to the GitHub MCP for making pull requests.

GitHub repositories are cached, so future sessions that use the same repository start faster.

GitHub MCP and session resources

First, create an agent that declares the GitHub MCP server. The agent definition holds the server URL but no authentication token:

ant apply code-reviewer.md
code-reviewer.md
---
name: Code Reviewer
model: claude-opus-5
mcp_servers:
  - type: url
    name: github
    url: https://api.githubcopilot.com/mcp/
tools:
  - type: agent_toolset_20260401
  - type: mcp_toolset
    mcp_server_name: github
---

You are a code review assistant with access to GitHub.

Then create a session that mounts the GitHub repository:

session = client.beta.sessions.create(
    agent=agent.id,
    environment_id=environment.id,
    resources=[
        {
            "type": "github_repository",
            "url": "https://github.com/org/repo",
            "mount_path": "/workspace/repo",
            "authorization_token": "ghp_your_github_token",
        },
    ],
)

A github_repository resource accepts the following fields:

FieldDescription
typeRequired. Must be "github_repository".
urlRequired. The repository's HTTPS URL in the form https://github.com/<owner>/<repo>, without a .git suffix. Other forms, including SSH URLs, are rejected with an invalid_request_error.
authorization_tokenRequired. The GitHub token used to clone the repository. It is not echoed in API responses. See Token permissions.
mount_pathOptional. The directory under /workspace to clone the repository into. Defaults to /workspace/<repo-name>.
checkoutOptional. A branch ({"type": "branch", "name": "main"}) or commit ({"type": "commit", "sha": "..."}) to check out. Defaults to the repository's default branch.

Mounting a repository also loads any skills stored in its root .claude/skills directory. Skills are discovered once per session, from the repository state checked out at session start. See Load skills from a GitHub repository.

Token permissions

When providing a GitHub token, use the minimum required permissions:

ActionRequired scopes
Clone private reposrepo
Create PRsrepo
Read issuesrepo (private) or public_repo
Create issuesrepo (private) or public_repo

Multiple repositories

Mount multiple repositories by adding entries to the resources array:

resources = [
    {
        "type": "github_repository",
        "url": "https://github.com/org/frontend",
        "mount_path": "/workspace/frontend",
        "authorization_token": "ghp_your_github_token",
    },
    {
        "type": "github_repository",
        "url": "https://github.com/org/backend",
        "mount_path": "/workspace/backend",
        "authorization_token": "ghp_your_github_token",
    },
]

Managing repositories on a running session

After a session is created, you can list its repository resources and rotate their authorization tokens. Each resource has an id returned at session creation time (or through resources.list) that you use for updates. Repositories are attached for the lifetime of the session; to change which repositories are mounted, create a new session.

# List resources on the session
listed = client.beta.sessions.resources.list(session.id)
repo_resource_id = listed.data[0].id
print(repo_resource_id)  # "sesrsc_01ABC..."

# Rotate the authorization token
client.beta.sessions.resources.update(
    repo_resource_id,
    session_id=session.id,
    authorization_token="ghp_your_new_github_token",
)

Creating pull requests

With the GitHub MCP server, the agent can create branches, commit changes, and push them:

client.beta.sessions.events.send(
    session.id,
    events=[
        {
            "type": "user.message",
            "content": [
                {
                    "type": "text",
                    "text": "Fix the type error in src/utils.ts, commit it to a new branch, and push it.",
                },
            ],
        },
    ],
)

Next steps

Stream events and steer the agent while it opens the pull request

Connect more MCP servers to give the agent additional tools

Mount files in the sandbox alongside your repositories

Was this page helpful?