Claude Platform Docs
Managed Agents에이전트 컨텍스트 관리

GitHub 액세스하기

에이전트를 GitHub 리포지토리에 연결하여 복제, 읽기 및 풀 리퀘스트 생성을 수행합니다.

GitHub 리포지토리를 세션 샌드박스에 마운트하고, 풀 리퀘스트를 생성하기 위해 GitHub MCP에 연결할 수 있습니다.

GitHub 리포지토리는 캐시되므로, 동일한 리포지토리를 사용하는 이후 세션은 더 빠르게 시작됩니다.

GitHub MCP 및 세션 리소스

먼저 GitHub MCP 서버를 선언하는 에이전트를 생성합니다. 에이전트 정의에는 서버 URL이 포함되지만 인증 토큰은 포함되지 않습니다:

ant apply code-reviewer.md
code-reviewer.md
---
name: Code Reviewer
model: claude-opus-5-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.

그런 다음 GitHub 리포지토리를 마운트하는 세션을 생성합니다:

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",
        },
    ],
)

github_repository 리소스는 다음 필드를 허용합니다:

필드설명
type필수. "github_repository"여야 합니다.
url필수. .git 접미사 없이 https://github.com/<owner>/<repo> 형식으로 된 리포지토리의 HTTPS URL입니다. SSH URL을 포함한 다른 형식은 invalid_request_error로 거부됩니다.
authorization_token필수. 리포지토리를 복제하는 데 사용되는 GitHub 토큰입니다. API 응답에는 반환되지 않습니다. 토큰 권한을 참조하세요.
mount_path선택 사항. 리포지토리를 복제할 /workspace 하위 디렉터리입니다. 기본값은 /workspace/<repo-name>입니다.
checkout선택 사항. 체크아웃할 브랜치({"type": "branch", "name": "main"}) 또는 커밋({"type": "commit", "sha": "..."})입니다. 기본값은 리포지토리의 기본 브랜치입니다.

리포지토리를 마운트하면 루트 .claude/skills 디렉터리에 저장된 스킬도 함께 로드됩니다. 스킬은 세션 시작 시 체크아웃된 리포지토리 상태를 기준으로 세션당 한 번 검색됩니다. GitHub 리포지토리에서 스킬 로드하기를 참조하세요.

토큰 권한

GitHub 토큰을 제공할 때는 필요한 최소 권한을 사용하세요:

작업필요한 범위
비공개 리포지토리 복제repo
PR 생성repo
이슈 읽기repo(비공개) 또는 public_repo
이슈 생성repo(비공개) 또는 public_repo

여러 리포지토리

resources 배열에 항목을 추가하여 여러 리포지토리를 마운트합니다:

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",
    },
]

실행 중인 세션에서 리포지토리 관리하기

세션이 생성된 후에는 해당 세션의 리포지토리 리소스를 나열하고 인증 토큰을 교체할 수 있습니다. 각 리소스에는 세션 생성 시(또는 resources.list를 통해) 반환되는 id가 있으며, 업데이트 시 이를 사용합니다. 리포지토리는 세션의 수명 동안 연결된 상태로 유지됩니다. 마운트되는 리포지토리를 변경하려면 새 세션을 생성하세요.

# 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",
)

풀 리퀘스트 생성하기

GitHub MCP 서버를 사용하면 에이전트가 브랜치를 생성하고, 변경 사항을 커밋하고, 이를 푸시할 수 있습니다:

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.",
                },
            ],
        },
    ],
)

다음 단계

에이전트가 풀 리퀘스트를 여는 동안 이벤트를 스트리밍하고 에이전트를 조정합니다

더 많은 MCP 서버를 연결하여 에이전트에 추가 도구를 제공합니다

리포지토리와 함께 샌드박스에 파일을 마운트합니다

Was this page helpful?