Running AI Coding Agents in GitHub Actions: Official Actions, Permissions and Cost Control
The Nx supply-chain compromise in August 2025 didn't start with an AI agent. It started with a GitHub Actions workflow. Per Nx's postmortem, a PR-title check used pull_request_target, which "runs with the permissions of the target branch (not the fork)", and echoed the title unsanitised into a shell. An attacker opened a PR with a crafted title, got a read/write GitHub token out of the run, and used it to reach the workflow that held the npm publishing token.
Now put a coding agent in that workflow. Its whole job is to read untrusted text (issue bodies, PR descriptions, review comments) and act on it with tools. Everything that makes Actions security hard gets harder. None of that means you shouldn't run agents in CI; @claude fix this on an issue and automatic first-pass reviews are useful. It means the workflow YAML around the agent deserves more care than the prompt.
The official options, as of November 2026
| Option | Latest | What it is |
|---|---|---|
anthropics/claude-code-action | v1.0.269 (6 Nov 2026), MIT | Claude Code on your runner; @claude mentions or a fixed prompt |
openai/codex-action | v1.13 (5 Oct 2026), Apache-2.0 | Runs codex exec with a prompt; returns final-message |
google-github-actions/run-gemini-cli | v0.1.22 (24 Apr 2026), Apache-2.0 | Gemini CLI with example triage, review and assistant workflows |
| Copilot cloud agent | Hosted by GitHub | Assign an issue to Copilot; it runs on an Actions runner and opens a PR |
| GitHub Agentic Workflows | Technical preview | Markdown workflows compiled to hardened Actions YAML |
A few notes on each. The Claude action authenticates with an API key, a Claude subscription OAuth token, workload identity federation (no stored secret) or Bedrock, Vertex AI and Foundry via OIDC. The Codex action's distinctive input is safety-strategy, which defaults to drop-sudo. The Gemini action is still pre-1.0, and it's worth knowing that Google moved individual users from Gemini CLI to Antigravity CLI in June 2026; API-key and enterprise access to Gemini CLI continues. Copilot's agent isn't an action you add at all, but you customise its environment with a .github/workflows/copilot-setup-steps.yml whose job must be named copilot-setup-steps (and whose timeout-minutes tops out at 59).
GitHub Agentic Workflows deserves a look even in preview: you write the workflow in Markdown, gh aw compile turns it into pinned YAML, the agent runs read-only, and only the writes you declared as "safe outputs" are applied, by a separate job with its own permissions. Supported engines include Copilot, Claude Code and Codex. It bakes in the split-job pattern I recommend below.
How a safe run flows
Every safe setup I've seen has the same shape: a gate on who can trigger, a job token with the minimum permissions, an agent restricted to the tools it needs, and a human between the agent's output and the default branch.
A minimal review workflow with Claude
This is close to the basic PR review example in the action's docs, with a timeout and concurrency added:
name: Claude review
on:
pull_request:
types: [opened, synchronize]
concurrency:
group: claude-review-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
review:
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
pull-requests: write
id-token: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
prompt: |
REPO: ${{ github.repository }}
PR NUMBER: ${{ github.event.pull_request.number }}
Review this PR for bugs and security issues.
Use `gh pr comment` for top-level feedback.
claude_args: |
--max-turns 10
--allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)"
The --allowedTools line is doing real work. In automation mode, Anthropic's GitHub Actions docs say Claude has no shell or GitHub API access until you grant the tools the prompt needs. Grant gh pr comment, not Bash(*). The id-token: write permission is there for the action's GitHub App authentication.
Note what happens with forks: GitHub doesn't pass secrets to pull_request runs from forked repositories, and the GITHUB_TOKEN is read-only there. So on a public repo, this review only runs for branches in the same repository. That's a feature. The tempting fix, switching to pull_request_target, is exactly the Nx mistake.
The split-job pattern
OpenAI's example is worth copying for its structure even if you use a different agent. The agent runs in a job with contents: read only; its answer leaves through a job output; a second job with pull-requests: write posts the comment, without ever running the model:
jobs:
codex:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
final_message: ${{ steps.run_codex.outputs.final-message }}
steps:
- uses: actions/checkout@v5
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
persist-credentials: false
- id: run_codex
uses: openai/codex-action@v1
with:
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
permission-profile: ":workspace"
prompt: "Review only the changes in this PR. Be concise."
post_feedback:
needs: codex
if: needs.codex.outputs.final_message != ''
runs-on: ubuntu-latest
permissions:
pull-requests: write
# ...actions/github-script posts needs.codex.outputs.final_message
If the model gets talked into misbehaving, it's holding a read-only token and running under persist-credentials: false. It can't push code or edit the repository; the realistic worst case is a bad comment. (The API key still passes through Codex's proxy, and the action's docs note that in some modes Codex could read it from process memory, so treat that key as exposed to the job.) The :workspace profile also has no network access, so the example installs dependencies in earlier steps.
Permissions and triggers: the rules that matter
- Declare
permissions:on every job. Per GitHub's workflow syntax, once you specify any permission, every unspecified one is set tonone.permissions: {}removes them all. - Never check out untrusted code under
pull_request_targetorworkflow_run. GitHub's secure use guide says these privileged workflows "must not explicitly check out untrusted code." The Claude action's security doc shows the safe variant: base ref at the workspace root, PR head in a subdirectory passed with--add-dir. - Pass untrusted text through
env:, not${{ }}insiderun:. GitHub calls an intermediate environment variable "the preferred approach to handling untrusted input." Codex's example does exactly that for branch names. - Pin third-party actions to a commit SHA, as GitHub's guide recommends.
- Keep the actor gates on. The Claude action only runs for users with write access and rejects bots unless listed in
allowed_bots. Its docs warn that allowed bots aren't permission-checked, and callallowed_non_write_users"a significant security risk". Codex has the equivalentallow-usersandallow-botsinputs. Copilot's agent only takes tasks from users with write access, doesn't run your workflows on its PRs until someone with write access approves, and won't let the person who asked approve the resulting PR.
One more Claude-specific detail I like: on pull requests, the action restores .claude/, .mcp.json, CLAUDE.md and a few other config paths from the base branch before starting, so a PR can't rewrite the agent's instructions or hooks for its own review. Everything else (package.json, Makefile) still comes from the PR head, so hooks shouldn't run npm run scripts.
Keeping the bill sane
You pay twice: runner minutes and model tokens. Anthropic's docs list the levers, and they apply to every agent:
- Cap iterations:
--max-turnsinclaude_args, or a tighter prompt for Codex and Gemini. - Set
timeout-minuteson the job so a stuck run dies. - Use
concurrencywithcancel-in-progress: trueso five quick pushes don't buy five reviews. - Filter early with
if:so runners don't even start on comments that don't mention the agent. - Keep instruction files short, since they're read on every run.
The LLM pricing calculator helps put a number on a review that reads 30k tokens of diff. If you authenticate the Claude action with a subscription OAuth token, runs count against that subscription instead of API billing.
Gotchas I'd check before merging the workflow
- Commits pushed with the default
GITHUB_TOKENdon't trigger other workflows, so CI won't run on the agent's commits unless it authenticates as an app. - Scheduled workflows run only from the default branch, and on public repos GitHub disables them after 60 days without activity.
- Codex's
drop-sudochanges can persist on reused self-hosted runners; run the action as the last step, on disposable runners. actions/checkoutpersists the job's token for later git commands by default (since v6 in a file under$RUNNER_TEMPrather than.git/config). An agent with shell access can find it, so setpersist-credentials: falseon agent jobs that don't push.
For the non-AI side of the same workflows (caching, reusable workflows, OIDC), see GitHub Actions CI/CD patterns that scale and our advanced GitHub Actions guide. If you're still picking an agent, Claude Code, OpenAI Codex and GitHub Copilot have pages here, and our AI code review tools guide covers the hosted review bots that need no workflow at all.
Written by AIDToolStack Editorial
Researched from official documentation, specifications and vendor pages, listed under Sources below. Last checked November 2026.
Sources
- nx.dev/blog/s1ngularity-postmortem
- github.com/anthropics/claude-code-action
- github.com/anthropics/claude-code-action/blob/main/docs/security.md
- github.com/anthropics/claude-code-action/blob/main/docs/usage.md
- github.com/anthropics/claude-code-action/blob/main/docs/solutions.md
- code.claude.com/docs/en/github-actions
- github.com/openai/codex-action
- github.com/openai/codex-action/blob/main/CHANGELOG.md
- github.com/google-github-actions/run-gemini-cli
- developers.googleblog.com/an-important-update-transitioning-gemini-cli-to-antigravity-cli/
- docs.github.com/en/copilot/concepts/agents/coding-agent/risks-and-mitigations
- docs.github.com/en/copilot/how-tos/use-copilot-agents/coding-agent/customize-the-agent-environment
- github.github.com/gh-aw/
- docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows
- docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax
- docs.github.com/en/actions/reference/security/secure-use
- github.com/actions/checkout
Related Posts
Explore on AIDToolStack
Discover tools and servers featured in our directory.
AI Tools
MCP Servers
Sponsor Our Newsletter
Reach thousands of developers who are actively evaluating AI tools, MCP servers, and dev infrastructure. Our weekly newsletter goes to engaged technical decision-makers.
All sponsored content is clearly labeled per our editorial policy.