answered from live GitHub & Hugging Face data

What are the best practices for using deploy keys with AI coding agents like Codex and Claude Code?

MaintActive · today
Stars157k
Issues17k open
MaintActive · 3d ago
Stars10k
Issues969 open
MaintSlowing · 10mo ago
Stars7.2k
Issues99 open

Do not give a coding agent a write-enabled deploy key. Deploy keys have no expiry, so a leaked key stays valid until someone removes it. Use a GitHub App installation token instead, which expires after one hour.

I checked GitHub's deploy key, GitHub App, and GitHub App decision docs. I did not find dedicated Codex or Claude Code documentation on secret handling, so the agent-specific points below are my inference from the GitHub docs.

Why deploy keys fit agents poorly

GitHub's managing deploy keys page lists these drawbacks:

An agent runs commands on a machine. It can usually read files in ~/.ssh. Treat any deploy key on that machine as readable by the agent (my inference).

Best practices

  1. Use a read-only deploy key only when the agent needs to clone or fetch one repository.
  2. Leave "Allow write access" unchecked. GitHub makes read-only the default.
  3. Create one key pair per repository. The docs say "You can't reuse a deploy key for multiple repositories."
  4. Store the key outside the agent's working directory, and set file permissions so only your user reads it.
  5. Rotate or delete the key when the agent's work ends. Deploy keys do not expire on their own.
  6. For writes, pushes, or pull requests, switch to a GitHub App. The decision guide says GitHub Apps "use short lived tokens" and "use fine-grained permissions."

Option comparison

Option Expiry Scope Fit for agents
Deploy key, read-only None One repository Acceptable for clone or fetch only
Deploy key, write None One repository, admin-level actions Avoid
GitHub App installation token 1 hour, per the token docs Chosen repositories and permissions Preferred
Machine user Key has no expiry Read/write on personal repositories Avoid for agents

The token docs say you can limit a token "to specific repositories" and to specific permissions. The token "cannot be granted permissions that the app was not granted."

Recommendation

Use one GitHub App for your agents, and mint a short-lived installation token per run. Install the app only on the repositories each agent needs. Grant only the permissions it needs. Use deploy keys only for read-only clones where a GitHub App is not practical.

Choose a read-only deploy key if… the agent only reads one repository on one server. Choose a GitHub App if… the agent pushes commits, opens pull requests, or works across repositories.

I could not check the maintenance signals for the anthropics/claude-code-action repository, because the lookup failed. Claude Code itself, anthropics/claude-code, shows as actively maintained, with a last push 0 days ago.

If you run several agents, githug issues each agent its own key. That key mints GitHub tokens that last one hour and work on one repository. Commits show the agent as author.

docs.github.com/en/authentication/connecting-to-github-with-ssh/managing-deploy-keysdocs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-an-installation-access-token-for-a-github-appdocs.kernel.org/process/coding-assistants.htmlgithub.com/anthropics/claude-codegithub.com/anthropics/claude-code-actiongithub.com/anthropics/claude-code-security-reviewgithub.com/anthropics/claude-code-base-actiongithub.com/anthropics/claude-code-playgroundgithub.com/buyuk-dev/openai-codex-cligithub.com/AetherX-Technologies/Codex-ClaudeCode-CLI-to-OpenAI-APIgithub.com/taahro/awesome-openai-codex-cligithub.com/lim6112j/openai_codex_cligithub.com/AnujNishad1/OpenAI-Codex-CLIdocs.github.com/en/apps/creating-github-apps/about-creating-github-apps/deciding-when-to-build-a-github-app
Answered live from GitHub & Hugging Face · anthropic/claude-haiku-5.5 · 11/28/2026

Ask your own open-source question →