Loading...
    • Build
    • Admin
    • Models & pricing
    • Client SDKs
    • API Reference
    Search...
    ⌘K
    First steps
    Intro to ClaudeQuickstart
    Building with Claude
    Features overviewUsing the Messages APIHandling stop reasons
    Model capabilities
    Extended thinkingAdaptive thinkingEffortFast mode (beta: research preview)Structured outputsCitationsStreaming MessagesBatch processingSearch resultsStreaming refusalsMultilingual supportEmbeddings
    Tools
    OverviewHow tool use worksWeb search toolWeb fetch toolCode execution toolMemory toolBash toolComputer use toolText editor tool
    Tool infrastructure
    Tool searchProgrammatic tool callingFine-grained tool streaming
    Context management
    Context windowsCompactionContext editingPrompt cachingToken counting
    Working with files
    Files APIPDF supportImages and vision
    Skills
    OverviewQuickstartBest practicesSkills for enterpriseSkills in the API
    MCP
    Remote MCP serversMCP connector
    Prompt engineering
    OverviewPrompting best practicesConsole prompting tools
    Test and evaluate
    Define success and build evaluationsUsing the Evaluation Tool in ConsoleReducing latency
    Strengthen guardrails
    Reduce hallucinationsIncrease output consistencyMitigate jailbreaksReduce prompt leak
    Resources
    Glossary
    Release notes
    Claude Platform
    Console
    Log in
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Partners

    • Amazon Bedrock
    • Google Cloud's Vertex AI

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Help and security

    • Availability
    • Status
    • Support
    • Discord

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy
    Delegate work to your agent

    Accessing GitHub

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

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

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

    All Managed Agents API requests require the managed-agents-2026-04-01 beta header. The SDK sets the beta header automatically.

    GitHub MCP and Session Resources

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

    agent_id=$(curl -fsS https://api.anthropic.com/v1/agents \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -H "anthropic-beta: managed-agents-2026-04-01" \
      -H "content-type: application/json" \
      --data @- <<JSON | jq -r '.id'
    {
      "name": "Code Reviewer",
      "model": "claude-sonnet-4-6",
      "system": "You are a code review assistant with access to GitHub.",
      "mcp_servers": [
        {
          "type": "url",
          "name": "github",
          "url": "https://api.githubcopilot.com/mcp/"
        }
      ],
      "tools": [
        {"type": "agent_toolset_20260401"},
        {
          "type": "mcp_toolset",
          "mcp_server_name": "github"
        }
      ]
    }
    JSON
    )

    Then create a session that mounts the GitHub repository:

    session_id=$(curl -fsS https://api.anthropic.com/v1/sessions \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -H "anthropic-beta: managed-agents-2026-04-01" \
      -H "content-type: application/json" \
      --data @- <<JSON | jq -r '.id'
    {
      "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"
        }
      ]
    }
    JSON
    )

    The resources[].authorization_token authenticates the repository clone operation and is not echoed in API responses.

    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

    Use fine-grained personal access tokens with minimum required permissions. Avoid using tokens with broad access to your GitHub account.

    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 via 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
    repo_resource_id=$(curl -fsS "https://api.anthropic.com/v1/sessions/$session_id/resources" \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -H "anthropic-beta: managed-agents-2026-04-01" \
      -H "content-type: application/json" | jq -r '.data[0].id')
    echo "$repo_resource_id"  # "sesrsc_01ABC..."
    
    # Rotate the authorization token
    curl -fsS "https://api.anthropic.com/v1/sessions/$session_id/resources/$repo_resource_id" \
    # ...
      -o /dev/null \
      --data @- <<JSON
    {
      "authorization_token": "ghp_your_new_github_token"
    }
    JSON

    Creating pull requests

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

    curl -fsS "https://api.anthropic.com/v1/sessions/$session_id/events" \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -H "anthropic-beta: managed-agents-2026-04-01" \
      -H "content-type: application/json" \
      -o /dev/null \
      --data @- <<JSON
    {
      "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."
            }
          ]
        }
      ]
    }
    JSON

    Was this page helpful?

    • GitHub MCP and Session Resources
    • Token permissions
    • Multiple repositories
    • Managing repositories on a running session
    • Creating pull requests