All posts

Agent security

How to Secure Claude Code in GitHub Actions and CI/CD Pipelines

Secure Claude Code workflows by separating event eligibility from task authority, mapping job credentials and runners, and preserving independent verification before releasing generated changes.

Conceptual Harden diagram. Trigger, token and action nodes illustrate a Claude Code workflow in CI.

Executive summary

Securing Claude Code in GitHub Actions requires reviewing the entire workflow, from its trigger to the credential that performs the final operation. Separate untrusted repository text from maintainer authorization, minimize job permissions, isolate runner access, and verify the resulting pull request or artifact through independent release controls.

Review the event before the prompt

A workflow can begin with a scheduled event, a maintainer action, a pull request or a comment. The event determines much more than the initial task description. It can influence which repository context is available, what credentials are exposed, and whether the run is capable of making persistent changes.

The Claude Code GitHub Actions documentation describes a workflow integration that can respond to mentions and run prompts on GitHub events. Begin with the exact workflow file and the installed action revision. Identify every event that matches its trigger configuration, including events that start an automatic task without a person composing a fresh prompt. For each event, identify the actor who can cause it and the source of the text the agent receives.

A maintainer labeling an issue written by an external contributor may legitimately authorize work on that issue. It does not authorize all instructions in the issue description. The contributor may have included troubleshooting notes that suggest uploading a file or contacting another service. The label means that the issue is eligible for the workflow, not that the contributor has inherited the workflow's credentials.

Keep this trigger review with the CI credential-path review so release identities stay visible beyond the agent job.

Separate task data from operational authority

In a conventional workflow, untrusted input might be a branch name, an issue title or a string interpolated into a script. An agent can also interpret an issue body, comments and repository documentation as natural-language requests. Review both the conventional script injection paths and the semantic instructions the agent can encounter.

The action's security documentation distinguishes who can trigger a run from text supplied by other people. It also identifies access checks and event-specific behavior. Review those details against the actual workflow rather than applying one general statement about every event type. A trusted trigger can still bring untrusted content into the prompt.

Write the intended operation outside the imported content. For example, a workflow responding to a documentation issue might authorize reading the issue, examining a documentation directory and proposing a change in a review branch. It need not authorize changing deployment settings or reading unrelated credentials. The engineer responsible for the workflow should decide which operations are in scope before exposing the agent to the issue.

Make a job-by-job credential map

Review the GitHub identity, model authentication and any additional connector or deployment credentials as distinct grants. A job may need model access to generate a proposed patch and repository access to read files. Neither requirement implies that it needs access to the artifact registry or production cloud account.

GitHub's automatic token authentication guidance explains how the workflow's GITHUB_TOKEN can be scoped using the permissions key at workflow or job level. It also notes that an action may access the token through the context even when the token is not explicitly passed as an input. Merely omitting a token argument does not establish that the job cannot use it.

Use a proposed matrix like this before deploying an agent workflow. Adjust the permissions and implementation to the actual operations and the action's documented requirements.

  • Analyze issue. Required effect: Read selected repository content. Grant to verify: Repository read access. Effect that stays outside the job: Repository changes.
  • Prepare patch. Required effect: Produce a change for review. Grant to verify: Narrow write access where needed. Effect that stays outside the job: Merge to protected branch.
  • Verify change. Required effect: Run independent checks. Grant to verify: Test environment access. Effect that stays outside the job: Production deployment.
  • Release. Required effect: Publish approved artifact. Grant to verify: Separate release identity. Effect that stays outside the job: Arbitrary changes to workflow policy.

Do not grant broad permissions to simplify an error in one job. Investigate the operation that failed and decide whether it belongs in that job at all. Where a different identity is required, document its resource scope and who can revoke it.

Review the runner as a credential-bearing machine

A workflow's declared permissions are only part of its authority. A runner can also contain cached credentials, filesystem mounts, service endpoints and installed helpers. Review what is available while the agent runs, including files or environment variables exposed by prior steps. On a reused machine, assess what could remain from previous jobs.

GitHub's secure use reference discusses untrusted input, action dependency pinning, least privilege and risks associated with self-hosted runners. Use that guidance to review whether the runner model is appropriate for the people who can influence a workflow. Keep untrusted pull request processing away from privileged environments. Avoid exposing sensitive deployment credentials to a job merely because another step in the same pipeline needs them.

Record the revision of actions the workflow invokes, as well as any scripts from the repository. A change to a workflow dependency should be reviewed as a change to the execution environment. Someone approving a patch must not silently authorize unrelated changes to the pipeline that will evaluate or publish it.

Rehearse an untrusted issue with a synthetic target

Create a disposable repository, with a documentation folder, an ordinary test branch and a synthetic file clearly marked as out of scope. Use a dedicated test identity and avoid connecting production environments. Configure the workflow using the permissions you intend to validate.

In the first exercise, have an authorized maintainer request a change to a documentation page. Confirm that a reviewable result can be produced. In the second exercise, use an issue description that includes an irrelevant instruction to include the synthetic file in an artifact. The authorized maintainer still requests only the documentation change. Capture the proposed operation and inspect the actual artifacts and repository events to establish whether the unrelated effect occurred.

An agent's refusal is useful but not enough to validate permissions. Separately verify that the credential available to the job cannot perform the prohibited operation against a disposable target. If it can, narrow the grant or move the privileged operation into a separate workflow. Do not test with real secrets, public uploads or production changes.

Preserve an independent release decision

An agent that edits code should not automatically receive the authority to certify or deploy that code. Review the pull request, run the relevant tests from an independently controlled workflow, and preserve the connection between the reviewed revision and the released artifact. An agent's report that tests passed is a statement to verify, not the test result itself.

A similar separation matters on developer workstations. If a developer asks a supported coding agent to fix a failing workflow, a pending call that modifies the release configuration may carry much more authority than the original task needs. Harden can evaluate supported pending tool calls in their task context before execution and allow, redact or block. This does not establish support for the hosted GitHub Actions runner. Teams assessing both local development and CI boundaries can Book a Call to review where each enforcement layer belongs.

FAQs

Is a workflow triggered by a trusted maintainer automatically safe?

No. The triggering actor and the authors of text read by the agent may differ. The workflow should constrain the operations it authorizes even when an eligible maintainer initiates it.

Can I hide the GitHub token by not passing it to the action?

That is not a sufficient boundary. GitHub documents that actions may access the workflow token through its context. Verify the effective permissions instead of relying on the absence of a named input.

Should the agent job deploy its own changes?

Separate patch generation from release authority. Give the release identity to a separately reviewed process and verify that the artifact corresponds to the approved revision before publishing it.

What should we inspect after a negative test?

Inspect the target repository, artifacts and any test service that could receive the operation. A chat message saying nothing was uploaded does not establish what the runner or connector actually did.

When should the workflow security review be repeated?

Repeat the affected checks when events, action revisions, runner configuration, token permissions or the release path change. A previously passing workflow test is evidence for the specific version and conditions recorded at that time.