How to run Claude Code in GitHub Actions with least-privilege permissions

To run Claude Code in GitHub Actions with least privilege, declare a job-level permissions block with only the scopes the run needs, grant Claude a named --allowedTools list, and limit who can trigger the run. The Claude Code GitHub Action documents each control. The sections below follow the order a workflow file is read.
Which permissions does each kind of run need?
Three run shapes cover most workflows. A reply to an @claude mention can push commits, so it needs write scopes. A pull request review only posts comments, and a scheduled report only reads. Match the permissions block to the shape of the run, not to the broadest example you find.
| Run shape | Trigger in the example | Job permissions | Tools granted in the example |
|---|---|---|---|
Reply to @claude |
issue_comment, pull_request_review_comment |
contents write, pull-requests write, issues write, id-token write, actions read | None (interactive mode) |
| Pull request review | pull_request |
contents read, pull-requests read, issues read, id-token write | mcp__github_inline_comment__create_inline_comment |
| Scheduled report | schedule |
contents read, issues read, id-token write | mcp__github__list_commits, mcp__github__list_issues |
The review and report rows are the least-privileged shapes on the page. Both declare read on contents and grant only named tools. id-token: write appears in all three because the action’s default GitHub App authentication needs it. actions: read in the mention example lets Claude read CI results on pull requests, so leave it out of any shape that does not need CI results.
Step 1: Declare the job permissions explicitly
- Start from the review shape and set
permissionson the job. Every example on the page declares it there. - Keep
id-token: write, which default GitHub App authentication needs. - Raise
contentstowriteonly when Claude must push commits to a branch. - Add
actions: readonly when Claude must read CI results. - Pass the key from a secret,
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}. Never commit the key itself.
name: Code Review
on:
pull_request:
types: [opened, synchronize, ready_for_review, reopened]
jobs:
review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
issues: read
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 }}
plugin_marketplaces: "https://github.com/anthropics/claude-plugins-official.git"
plugins: "code-review@claude-plugins-official"
prompt: "/code-review:code-review --comment ${{ github.repository }}/pull/${{ github.event.pull_request.number }}"
claude_args: '--allowedTools "mcp__github_inline_comment__create_inline_comment"'
Two details in this file control scope. The --comment flag in the prompt is what makes Claude post findings to the pull request, and without it the findings stay in the run log. The claude_args line is also required, because the action starts the MCP server that posts inline comments only when --allowedTools names it. The pull_request trigger also runs only for branches in the same repository, since GitHub withholds secrets from fork pull requests on public repositories.
Step 2: Limit who can start a run
The action runs two checks before Claude starts. On issue, pull request, comment and review events, the triggering user needs write access. On every event, a bot actor is rejected unless it appears in allowed_bots. Scheduled runs have no external actor and run only from the default branch, so the workflow file on that branch is the thing to review.
- Keep the write-access check. Do not set
allowed_non_write_userson a workflow with broad permissions. The security page calls it a significant risk and suggests it only for workflows with very limited scopes, such as one that hasissues: writealone. - Leave
allowed_botsunset unless a bot must trigger Claude. The security page says allowed bots are not checked for repository permissions, and'*'lets any app that can post the event invoke the action on a public repository. Use an explicit list. - On a public repository that takes outside input, use
include_comments_by_actorto allowlist the commenters whose text reaches Claude. - Under
pull_request_targetorworkflow_run, the run uses the base repository’s secrets. Do not check out an untrusted ref into the workspace root before the action runs.
Step 3: Grant only the tools the prompt needs
A plain-text prompt starts with no tool grants. You add them with --allowedTools in claude_args, or with a permissions.allow rule in the settings input. Skills work differently: a skill can use the tools listed in its own allowed-tools frontmatter. Scope each Bash rule to a subcommand. The permissions page says Bash(git log *) allows only git log, while Bash(git *) allows every git command.
name: Daily Report
on:
schedule:
- cron: "0 9 * * *"
jobs:
report:
runs-on: ubuntu-latest
permissions:
contents: read
issues: read
id-token: write
steps:
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
prompt: "Generate a summary of yesterday's commits and open issues"
claude_args: |
--allowedTools "mcp__github__list_commits,mcp__github__list_issues"
This job skips actions/checkout because it reads commits and issues through the GitHub API tools, so it never needs a working copy. Each tool name is a separate grant. Add one only when the prompt cannot finish without it.
Step 4: Deny the actions the job must never take
Rules run in a fixed order: deny, then ask, then allow, and the first match decides. An allow rule cannot carve an exception out of a deny rule, which makes deny the right tool for actions such as pushes. The action docs add two gotchas. A deny rule in a settings file does not cover the wrapper scripts Claude uses for git add, git rm, git commit and git push, so pass it in claude_args. And a Bash deny rule is a text match, so git -C . push is not caught by a git push rule.
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
claude_args: '--disallowedTools "Bash(git push:*)"'
Deny rules are not a sandbox. The security page says the action is not one, and that code run through an allowed command, such as npm test, can change files that later steps read. Keep Write and broad rules such as Bash(git:*) out of any workflow that handles outside contributions. The page says Bash(git:*) can still run programs through forms its list does not deny, such as git rebase --exec. For the settings-file deny rules themselves, see how to block destructive commands in Claude Code.
Step 5: Set a permission mode for each run
A workflow has no one to approve a prompt, so the mode decides what happens to a call nobody allowed. The action and the CLI default differently, so set the mode on purpose.
| Mode | What it does in a run | Notes from the docs |
|---|---|---|
| default (Manual) | A call that needs approval is denied unless a PermissionRequest hook or --permission-prompt-tool approves it |
The claude -p default from v2.1.302 when nothing sets a mode |
dontAsk |
Denies every call that would otherwise prompt | Described as useful for locked-down CI runs |
acceptEdits |
Writes files without prompting; other shell commands and network requests still need an allow rule | Security page recommends it, or default, for a strict list |
auto |
A classifier reviews calls that allow rules do not cover | The action’s default; a call can run if the review passes it |
Commit-only work needs one narrow grant. This command lets Claude read the staged diff and commit, and nothing else in the shell:
claude -p "Look at my staged changes and create an appropriate commit" \
--allowedTools "Bash(git diff *),Bash(git log *),Bash(git status *),Bash(git commit *)"
For an unattended job, --permission-prompts none turns any call that would prompt into a denial and lets the run continue. It needs Claude Code v2.1.259 or later. Pair it with --max-turns to cap iterations, and keep the denials. With --output-format stream-json, denials appear as permission_denied system messages, and the final result lists them in permission_denials.
claude -p "Update the dependency pins and run the tests" --permission-mode auto --permission-prompts none
The headless page recommends --bare for scripted calls, but bare mode changes what loads. It still reads settings files and their permission rules, and it skips auto-discovery of hooks, MCP servers in .mcp.json, and CLAUDE.md. It also never reads OAuth credentials, so set ANTHROPIC_API_KEY. Without --bare, a -p run executes the hooks in the project’s .claude/settings.json even in a folder you have never trusted. If a hook is your guardrail, do not use bare mode for that run.
claude --bare -p "Summarize README.md" --allowedTools "Read"
Step 6: Scope the GitHub token and the App
By default the action authenticates as the Claude GitHub App, and GitHub does not let you accept a subset of the app’s permissions. The security page lists the three the action uses today: Contents, Pull requests and Issues, all read and write. The app also requests Actions, Checks, Discussions and Workflows for future features. If your organization needs only the three in use, the action docs say to create a custom GitHub App with those three. That custom app covers only the action. Code Review and auto-fix still need the official app.
| Option | Permissions | What it covers |
|---|---|---|
| Official Claude GitHub App | Full set, including Actions and Workflows read and write | The action, Code Review and web auto-fix |
| Custom GitHub App | Contents, Issues and Pull requests | The action only |
If you pass github_token: ${{ secrets.GITHUB_TOKEN }}, the commits Claude makes will not trigger your CI. Remove that input to authenticate as the App instead. The action’s token is also short-lived and scoped to the one repository the run operates in, and the security page says a run has no cross-repository access.
What the workflow still cannot control
Least privilege limits the damage a run can do. It does not stop text from steering Claude. The security page says issues and comments from outside contributors still reach Claude, and that hidden instructions can sit in HTML comments, invisible characters or hidden attributes. The action strips many of these, but the page advises reviewing the raw content of external input before Claude processes it. Keep claude_args narrow, because text from outside can still try to get Claude to edit a file and then run it.
On pull requests, the action restores Claude’s configuration from the base branch before it starts. That covers .claude/, .mcp.json, CLAUDE.md, AGENTS.md and a few other paths. Everything else, including package.json and lockfiles, stays at the pull request head. Commands that run repository code, such as npm install or make, are denied by default when the author lacks write access, even if claude_args allows them. The page calls that list common commands, not a sandbox. Output is a risk as well. show_full_output is off by default, and the page warns that its logs are public on public repositories.
Checklist before you merge the workflow
- The job’s
permissionslists only the scopes in the table for this run shape. allowed_non_write_usersis unset, andallowed_botsis unset or an explicit list.claude_argsnames each allowed tool, and Bash rules are scoped to a subcommand.- Pushes are denied in
claude_argswhen the job must not push. - A permission mode is set on purpose, and
--max-turnscaps the run. github_tokenis unset unless you need a custom token, andshow_full_outputstays off on public repositories.
Enforcing this with AIControls
The controls in this post live in the workflow file and in Claude Code’s settings, and they hold only for the runs those files define. This post makes no claim that AIControls enforces the workflow. For the AIControls approach to coding agents, see the coding-agents page.
Frequently asked questions
Can Claude run any shell command in a GitHub Actions run?
Only what your settings allow. The action page says a plain-text prompt has no shell or GitHub API access until you grant tools. The security page adds that the action defaults to auto mode, where a safety review decides calls your allow rules do not cover, so a call can still run if that review passes it. For a strict list, pass --permission-mode acceptEdits or default in claude_args.
Does a deny rule in a settings file stop git push in the action?
Not on its own. The security page says a deny rule in a settings file does not cover the wrapper scripts Claude uses for git add, git rm, git commit and git push. Put the rule in claude_args instead, for example --disallowedTools with Bash(git push:*). A Bash rule also matches text, so a push written as git -C . push is not matched. Treat deny rules as one layer, not a sandbox.
Why doesn't CI run on the commits Claude pushes?
GitHub does not trigger workflows on commits made with the default GITHUB_TOKEN. If your workflow passes github_token set to the GITHUB_TOKEN secret, remove that input so the action authenticates as the Claude GitHub App. Then check that your CI triggers include the events Claude's pushes produce, such as push or pull_request.
Should a CI run use --bare?
The headless docs recommend --bare for scripted and SDK calls. Bare mode skips auto-discovery of hooks, MCP servers in .mcp.json, CLAUDE.md and other project files, and it never reads OAuth credentials, so set ANTHROPIC_API_KEY in the environment instead. If your guardrails are hooks, leave bare mode off for that run.