Skip to content
AI & Tools

Running AI Coding Agents in GitHub Actions: Official Actions, Permissions and Cost Control

AIDToolStack EditorialNovember 7, 20267 min read
GitHub ActionsAI AgentsCI/CDSecurityClaude Code
Share:Twitter

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

OptionLatestWhat it is
anthropics/claude-code-actionv1.0.269 (6 Nov 2026), MITClaude Code on your runner; @claude mentions or a fixed prompt
openai/codex-actionv1.13 (5 Oct 2026), Apache-2.0Runs codex exec with a prompt; returns final-message
google-github-actions/run-gemini-cliv0.1.22 (24 Apr 2026), Apache-2.0Gemini CLI with example triage, review and assistant workflows
Copilot cloud agentHosted by GitHubAssign an issue to Copilot; it runs on an Actions runner and opens a PR
GitHub Agentic WorkflowsTechnical previewMarkdown 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

Flow of an agent run in GitHub Actions: event, actor check, job with scoped token, agent with tool allowlist, output, human review
Flow of an agent run in GitHub Actions: event, actor check, job with scoped token, agent with tool allowlist, output, human review

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.

Split-job pattern: the agent job has read-only permissions and passes text to a separate job that holds write permission
Split-job pattern: the agent job has read-only permissions and passes text to a separate job that holds write permission

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 to none. permissions: {} removes them all.
  • Never check out untrusted code under pull_request_target or workflow_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 ${{ }} inside run:. 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 call allowed_non_write_users "a significant security risk". Codex has the equivalent allow-users and allow-bots inputs. 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:

  1. Cap iterations: --max-turns in claude_args, or a tighter prompt for Codex and Gemini.
  2. Set timeout-minutes on the job so a stuck run dies.
  3. Use concurrency with cancel-in-progress: true so five quick pushes don't buy five reviews.
  4. Filter early with if: so runners don't even start on comments that don't mention the agent.
  5. 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_TOKEN don'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-sudo changes can persist on reused self-hosted runners; run the action as the last step, on disposable runners.
  • actions/checkout persists the job's token for later git commands by default (since v6 in a file under $RUNNER_TEMP rather than .git/config). An agent with shell access can find it, so set persist-credentials: false on 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.

AE

Written by AIDToolStack Editorial

Researched from official documentation, specifications and vendor pages, listed under Sources below. Last checked November 2026.

Sources

  1. nx.dev/blog/s1ngularity-postmortem
  2. github.com/anthropics/claude-code-action
  3. github.com/anthropics/claude-code-action/blob/main/docs/security.md
  4. github.com/anthropics/claude-code-action/blob/main/docs/usage.md
  5. github.com/anthropics/claude-code-action/blob/main/docs/solutions.md
  6. code.claude.com/docs/en/github-actions
  7. github.com/openai/codex-action
  8. github.com/openai/codex-action/blob/main/CHANGELOG.md
  9. github.com/google-github-actions/run-gemini-cli
  10. developers.googleblog.com/an-important-update-transitioning-gemini-cli-to-antigravity-cli/
  11. docs.github.com/en/copilot/concepts/agents/coding-agent/risks-and-mitigations
  12. docs.github.com/en/copilot/how-tos/use-copilot-agents/coding-agent/customize-the-agent-environment
  13. github.github.com/gh-aw/
  14. docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows
  15. docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax
  16. docs.github.com/en/actions/reference/security/secure-use
  17. github.com/actions/checkout

Related Posts

Explore on AIDToolStack

Discover tools and servers featured in our directory.

MCP Servers

Trigger.dev Jobs MCP ServerManage Trigger.dev background jobs from your AI coding assistant. Monitor job runs, trigger tasks manually, inspect execution logs, manage schedules, and debug failed runs. The server provides operational visibility into your background job infrastructure — see which tasks are running, queued, or failed, and take action. Your AI can help diagnose job failures from execution logs, retry failed tasks, and optimize concurrency configurations for better throughput.Tailscale Network MCP ServerManage your Tailscale mesh VPN network from your AI coding assistant. View connected devices, manage ACLs, configure exit nodes, check device status, and manage DNS settings. The server provides visibility into your Tailscale network — see which machines are online, troubleshoot connectivity issues, manage network access policies, and configure routes. Useful for developers managing distributed infrastructure where Tailscale provides secure networking between services.Portainer Docker MCP ServerManage Docker environments through Portainer's API from your AI coding assistant. Control containers, images, networks, and volumes across multiple Docker hosts and Kubernetes clusters. The server provides tools for container lifecycle management, image pulling and building, stack deployment, and resource monitoring. Portainer's multi-environment management makes this server particularly valuable for teams managing containers across development, staging, and production environments.

Reviews

Sign in to leave a review.

No reviews yet. Be the first!

Comments

Sign in to leave a comment.

No comments yet. Be the first!

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.

Growing subscriber baseHigh open rates

All sponsored content is clearly labeled per our editorial policy.