← All connection guides

How to connect Codex to GitHub

Configure Codex with GitHub’s hosted MCP server and an environment-based token, then read issues and pull requests.

Free guide · Updated

Based on official documentation · Checked

Ask your agent

Copy the prompt and paste it into your assistant.

Quick answer

Add GitHub’s official remote MCP endpoint to Codex and point it at an environment variable containing your GitHub personal access token. This gives Codex GitHub tools; it does not replace git authentication for pushing a local checkout.

1. Prepare account access

Create a GitHub token for the repositories and actions you intend to use, with only the needed permissions. Organization policies may require approval. Make GITHUB_PAT_TOKEN available in the environment of the terminal that launches Codex. Keep its value out of prompts, shared configuration and committed files.

2. Add the remote server

Run this documented command. It stores the variable name in configuration rather than embedding the token:

codex mcp add github --url https://api.githubcopilot.com/mcp/ --bearer-token-env-var GITHUB_PAT_TOKEN

Configuration equivalent

If editing the shared CLI/IDE config directly, merge this section into ~/.codex/config.toml without replacing unrelated settings:

[mcp_servers.github]
url = "https://api.githubcopilot.com/mcp/"
bearer_token_env_var = "GITHUB_PAT_TOKEN"

Practice

3. Confirm GitHub tools

  1. Start Codex from the prepared environment. Inspect /mcp, then ask it to read one named issue and list open pull requests in an explicit owner/repository.

Output: Issue and pull-request details match GitHub, and the run uses GitHub MCP tools.

Troubleshooting

For a 401 response, check token validity and whether the launching process received the environment variable. For a missing private repository, check repository access and organization authorization. A shell opened before you configured the variable may need restarting. A public repository read alone does not verify private access.

Alternative and removal

GitHub also documents a local Docker server with OAuth if you prefer that installation method. Keep its configuration separate from the remote PAT setup. When removing the connection, delete the relevant MCP entry and revoke the token if it has no other purpose.

Sources

Read the primary material