DEV Community

Attila Albert
Attila Albert

Posted on

Put an AI coding assistant in your pull requests: Claude Code GitHub Actions, set up safely

By Tomás Herrera, NBT

Most people meet an AI coding assistant in their editor or terminal. The same agent can also live in your repository: someone types @claude in an issue or pull request comment, and a GitHub Actions runner checks out the code, does the work and replies in the thread. This guide sets that up with Anthropic's claude-code-action. It covers the two modes it runs in, who can trigger it, and the permission choices worth making before you merge the workflow file.

Everything below comes from the official Claude Code GitHub Actions documentation, read on 6 December 2026. If you're still choosing an AI coding assistant, read a comparison first. This article assumes you've settled on Claude Code.

What you need

  • Admin access to the repository. Both setup paths need it.
  • A credential, one of two kinds. The first is a Claude API key from the Claude Console, stored as ANTHROPIC_API_KEY. The second is a subscription token you create locally with claude setup-token, stored as CLAUDE_CODE_OAUTH_TOKEN.
  • The Claude GitHub App installed on the repository.

Which credential? For one person's repository, the subscription token is convenient. For anything shared across an organization, the docs recommend an API key, because a token is tied to the subscription of the person who ran claude setup-token.

Quick setup: one command

If you already run Claude Code locally and the repository is on github.com, this is the fastest path:

  1. Sign in to the GitHub CLI (gh auth login).
  2. Run claude in the repository and type /install-github-app.
  3. Install the Claude GitHub App when the browser opens, then return and press Enter.
  4. Pick the workflows you want: the @claude mentions workflow, the pull request review workflow, or both.
  5. Choose the credential. Claude Code saves it as a repository secret.
  6. Confirm. Claude Code pushes a branch with the workflow files and opens a pull request for you to create and merge.

Nothing runs until that pull request is merged, so you can read the YAML first. The command works only with github.com remotes. On GitLab or Bitbucket it prints a notice and stops.

Manual setup: the minimal mentions workflow

If you'd rather write the file yourself, install the app, add the secret, and save this as .github/workflows/claude.yml. It's the docs' interactive-mode example:

name: Claude Code
on:
  issue_comment:
    types: [created]
  pull_request_review_comment:
    types: [created]
jobs:
  claude:
    if: contains(github.event.comment.body, '@claude')
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
      issues: write
      id-token: write
      actions: read
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 1
      - uses: anthropics/claude-code-action@v1
        with:
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
Enter fullscreen mode Exit fullscreen mode

What each non-obvious part does:

  • The if: line stops a runner from starting on every comment. Without it you pay for runner minutes on "LGTM".
  • id-token: write is needed for the action's default GitHub App authentication.
  • actions: read lets Claude read CI results on the pull request, so "why is the build red?" gets a real answer.
  • fetch-depth: 1 gives a shallow checkout, which is enough for most requests.

If you use a subscription token, replace the last line with claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}.

Interactive mode vs automation mode

The action decides how to run from your workflow file:

  • No prompt input means interactive mode. Claude waits for the trigger phrase (@claude by default) in a comment, a review, or a newly opened issue's title or body, then answers in the thread.
  • A prompt input means automation mode. Claude runs on whatever event fires the workflow, including a cron schedule. By default the result goes to the workflow run log, not a comment.

Automation mode is where you put repeatable jobs: a review on every pull request, or a morning summary of yesterday's issues. One detail catches people. With a plain-text prompt, Claude has no shell or GitHub API access until you grant the tools it needs, through --allowedTools in claude_args or permission rules. If a scheduled job does nothing useful, check this first.

Who can make it run

Two checks run before Claude starts, in both modes:

  1. Write access. On issue and pull request events, the person who triggered the run must have write access to the repository. A drive-by commenter on a public repo can't spend your credits. To allow specific people without write access, there's an allowed_non_write_users input, which also requires your own github_token.
  2. Human actor. Bots are rejected unless you list them in allowed_bots. This prevents loops where one bot's comment triggers Claude, whose comment triggers the bot again.

Leave both defaults alone unless you have a specific reason.

The permissions you're really granting

The workflow's permissions: block limits the job's token. The GitHub App is a separate grant. The action itself relies on three of the app's permissions: Contents, Issues and Pull requests, each read and write. But the Claude GitHub App is shared by several Claude features, and installing it grants its full permission set: Actions, Workflows, Checks and more. GitHub doesn't let you accept only part of an app's permissions.

If your security team wants only the three permissions the action uses, the documented route is a custom GitHub App with Contents, Issues and Pull requests. It's more work. Make that call before the rollout, not after an audit.

Rolling it out to more than one repository

For an organization:

  • Install the app once at the organization level.
  • Store the credential as an organization-level Actions secret.
  • Either copy the workflow into each repository or define it once as a reusable workflow that each repository calls.

To avoid a long-lived secret entirely, the action supports workload identity federation. It swaps the workflow's GitHub OIDC token for Claude API access through a Claude Console service account. The inputs are anthropic_federation_rule_id and anthropic_organization_id, plus optional service account and workspace IDs. The job still needs id-token: write.

Three requests that work well

Once it's merged, try these in a comment:

@claude why is the test job failing on this PR? Point to the line.
@claude add a unit test for the empty-input case in parseDate, push to this branch
@claude summarise what this PR changes for a reviewer who hasn't seen the issue
Enter fullscreen mode Exit fullscreen mode

Each one has a clear target and a checkable result. "Fix everything" doesn't, and you'll spend more time reviewing than you saved. Treat Claude's commits like a colleague's: review the diff before you merge.

Removing it later

Delete the workflow files, then delete the secret. Deleting a secret doesn't revoke it, so retire the API key in the Console too. Uninstall the GitHub App only if no other Claude feature uses it.

Where a desktop app fits

The Action handles work that starts on GitHub. Most work still starts on your own machine, and that's where we come in. Disclosure: we make Ninja Builder, a desktop app that runs Claude and other coding agents with step-by-step playbooks, a review card for each reply and checks before anything goes online. New to the tool itself? Start with what is Claude Code and come back to the Action once the local workflow feels natural.

Top comments (0)