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?
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:
- "Deploy keys are usually not protected by a passphrase, making the key easily accessible if the server is compromised."
- "Deploy keys are credentials that don't have an expiry date."
- Deploy keys "aren't linked directly to organization membership."
- A key with write access "can perform the same actions as an organization member with admin access."
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
- Use a read-only deploy key only when the agent needs to clone or fetch one repository.
- Leave "Allow write access" unchecked. GitHub makes read-only the default.
- Create one key pair per repository. The docs say "You can't reuse a deploy key for multiple repositories."
- Store the key outside the agent's working directory, and set file permissions so only your user reads it.
- Rotate or delete the key when the agent's work ends. Deploy keys do not expire on their own.
- 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.