Run Claude Code in GitHub Actions with claude-code-action, or in Azure Pipelines with the Claude Code command line in headless mode. We recommend letting the build, tests, and analysers pass first. Then give Claude a narrow, read-only job with a turn limit and a cost cap.
- Foundry bills through Azure, but runs slower for us when hosted on Azure.
- Start with review, and grant write access deliberately.
- Run the AI step once per pull request.
If you want this set up with budgets and gates from the start, our GitHub Actions CI/CD service covers it.
Which way of running Claude in CI fits your team?
There are three ways to put Claude in a .NET continuous integration (CI) pipeline, and the right one depends on where your code lives and how much control you want. The table compares them.
| Option | Where it fits | What you maintain |
|---|---|---|
| Claude Code GitHub Action | Repositories on GitHub, where you want to set the prompt, model, triggers, and limits | A workflow file and a secret |
| Claude Code Review | GitHub repositories on a Claude Team or Enterprise plan, where you want automatic review without a workflow | Settings in your Claude organisation |
| Claude Code command line in headless mode | Azure Pipelines, or any other CI system that runs a script | A pipeline step, the install, and a secret |
Claude Code Review runs on Anthropic’s infrastructure, so it needs no runner and no workflow. This guide covers the other two, because they are what you set up yourself. Our guide to pricing AI in the pipeline compares what each one bills.
Should you run Claude through Microsoft Foundry or the Claude API?
Microsoft Foundry puts Claude spend on your Azure bill and inside Azure governance, while the Claude API gives you every feature. On Foundry deployments hosted on Azure, we consistently see Claude Code take noticeably longer than the same work through the Claude API. Decide on the route before you build the pipeline, because the setup differs.
Foundry offers two hosting options for each Claude deployment. ‘Hosted on Azure’ runs on Azure infrastructure, and Anthropic recommends it for most workloads. ‘Hosted on Anthropic’ runs on Anthropic’s infrastructure, and offers models and features that the Azure option lacks.
| Claude API | Foundry, hosted on Azure | Foundry, hosted on Anthropic | |
|---|---|---|---|
| Billing | Anthropic invoice | Azure Marketplace, at the same per-token rates | Azure Marketplace, at the same per-token rates |
| Where prompts are processed | Anthropic infrastructure | Azure infrastructure | Anthropic infrastructure |
| Models | All generally available models | Opus 5.5, Sonnet 5.5, Haiku 5.5, and some earlier models | A wider list, including Claude Fable 5.2 |
| Features | All | The Foundry gaps, plus no code execution, newer web search and fetch, Agent Skills, programmatic tool calling, or Files API | Most, but no Managed Agents, Message Batches, or server-side fallbacks (the Foundry gaps) |
| Rate limits | Usage tiers in the Claude Console, with rate limit headers | Managed in Azure, with no Anthropic rate limit headers | Managed in Azure, with no Anthropic rate limit headers |
| Speed, in our experience | Our baseline | Noticeably slower | Not yet compared |
On deployments hosted on Azure, Anthropic stores retained content on Azure infrastructure. Operational data without prompts or completions, such as usage figures and safety classifier scores, is stored on Anthropic’s systems outside Azure.
What the speed difference means in CI
We have not measured the gap formally, and neither Microsoft’s nor Anthropic’s documentation compares latency between the two. Independent single-request benchmarks from Artificial Analysis do not show Azure as consistently slower. The gap we see in long agent runs may therefore depend on how a deployment is set up, such as its region and quota, as much as on the platform. Treat it as something to test on your own jobs, not as a fixed figure.
In a pipeline, slower runs cost twice. A slower review holds a runner for longer, which uses more Actions minutes on GitHub-hosted runners. It also lengthens the wait before an engineer sees the findings, which is the delay the AI step was meant to remove.
How to choose
- Choose the Claude API when run time matters, or when you need Managed Agents, batches, or server-side fallbacks.
- Choose Foundry hosted on Azure when billing through Azure or processing prompts on Azure infrastructure is a requirement, and plan for slower runs.
- Consider Foundry hosted on Anthropic when you want Azure billing with the wider model and feature list, and test its speed for yourself.
To compare routes, run the same review job on a sample of real pull requests through each one. Compare the job durations and the total_cost_usd that each headless run reports. Claude Code detects deployments hosted on Azure and adjusts its feature set automatically, so the same workflow runs on either.
Where does Claude fit in a .NET pipeline?
Claude belongs after the deterministic checks and before human review. The build, the unit tests, and the Roslyn analysers (code rules that run inside the compiler) are cheap, fast, and certain, so they should run first. A model reviewing code that does not compile spends tokens on problems the compiler would have found.

We take the same view inside a Claude Code session, where hooks run dotnet build and dotnet test after edits. Our harness engineering guide explains why deterministic checks come before inferential ones. In CI, the job dependencies do the same work.
How do you set up Claude Code in GitHub Actions?
The setup has two parts: the Claude GitHub App with a secret, and a workflow file. Anthropic’s GitHub Actions documentation covers both.
Install the app and add a secret
The quickest route is to run /install-github-app in a Claude Code session in the repository. It installs the Claude GitHub App, saves the secret, and opens a pull request (PR) with the workflow files.
To do it by hand, install the Claude GitHub App and add an ANTHROPIC_API_KEY repository secret with a key from the Claude Console. For several repositories, install the app once at organisation level and store the key as an organisation secret. Anthropic recommends an API key rather than a subscription token for shared secrets.
A review job that waits for the build
This workflow builds and tests the .NET solution, then runs Claude’s code review only if that succeeds. It runs when a PR opens, is reopened, or is marked ready for review, not on every push.
name: Build and Claude review
on:
pull_request:
types: [opened, reopened, ready_for_review]
concurrency:
group: claude-review-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v7
- uses: actions/setup-dotnet@v6
with:
dotnet-version: '10.0.x'
- run: dotnet build --configuration Release
- run: dotnet test --configuration Release --no-build
review:
needs: build
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
pull-requests: read
issues: read
id-token: write
steps:
- uses: actions/checkout@v7
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: |
--model claude-sonnet-5-5
--max-turns 15
--allowedTools "mcp__github_inline_comment__create_inline_comment"The review step runs Anthropic’s code-review plugin, which posts inline comments on the PR and skips drafts and trivial changes. The --max-turns limit and the job timeout cap what one run can spend. Write your review criteria in CLAUDE.md at the repository root, because Claude reads it on every run.
Respond to @claude mentions
A second workflow lets engineers ask Claude for help in a PR or issue comment, such as ‘@claude add tests for this handler’. Anthropic’s example workflow does this, and works as committed.
Two checks run before Claude starts. On issue and PR events, the person who triggers it must have write access to the repository. Bots are rejected unless you list them in allowed_bots, which stops a bot from triggering Claude in a loop.
Mentions give Claude write access to the branch, so treat them like any other change. Its commits go through the same build, review, and approval as an engineer’s.
Authenticate through Microsoft Foundry instead of a key
Microsoft-stack teams can route Claude through Microsoft Foundry, so usage is billed through Azure and no Anthropic key is stored. The workflow signs in to Azure with OpenID Connect (OIDC), and Claude Code uses those credentials.
You need three things on the Azure side:
- A Claude deployment in a Foundry resource.
- A Microsoft Entra application or user-assigned managed identity, with a federated credential that trusts GitHub tokens for your repository.
- The
Foundry Userrole on the Foundry resource for that identity.
Store AZURE_CLIENT_ID, AZURE_TENANT_ID, and AZURE_SUBSCRIPTION_ID as repository secrets. Then add the Azure sign-in to the review job, and replace anthropic_api_key with use_foundry. Keep the plugin and prompt inputs from the review job as they are.
permissions:
contents: read
pull-requests: read
issues: read
id-token: write
steps:
- uses: actions/checkout@v7
- name: Authenticate to Azure
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- uses: anthropics/claude-code-action@v1
env:
ANTHROPIC_FOUNDRY_RESOURCE: your-foundry-resource
with:
use_foundry: "true"
claude_args: "--model your-sonnet-deployment --max-turns 15"The --model value is the name of your Foundry deployment. Microsoft’s guide to connecting GitHub Actions to Azure with OIDC covers the federated credential.
On public repositories, the Azure sign-in runs before the action checks that the commenter has write access. Anthropic’s documentation advises adding a step that verifies write access before any credential step.
How do you run Claude Code in Azure Pipelines?
In Azure Pipelines, you install the Claude Code command-line interface (CLI) on the agent and run it in headless mode with -p. Anthropic recommends adding --bare for scripted runs, and says it will become the default for -p in a future release.
What —bare changes
Bare mode skips the project’s hooks, skills, plugins, Model Context Protocol (MCP) servers, and CLAUDE.md. That makes a run predictable, and it stops a branch’s own settings from running anything in your pipeline. The cost is that Claude does not see your conventions unless you pass them in, for example with --append-system-prompt-file pointing at a review rules file.
Bare mode needs ANTHROPIC_API_KEY, because it never reads subscription credentials.
A headless review step
This pipeline builds and tests the solution, writes the PR’s diff to a file, and asks Claude to review it with read-only tools. The output is saved as a pipeline artifact.
pr:
branches:
include: [main]
pool:
vmImage: ubuntu-latest
jobs:
- job: build_and_review
timeoutInMinutes: 30
steps:
- checkout: self
fetchDepth: 0
- task: UseDotNet@2
inputs:
packageType: sdk
version: '10.0.x'
- script: |
dotnet build --configuration Release
dotnet test --configuration Release --no-build
displayName: Build and test
- script: |
target="${SYSTEM_PULLREQUEST_TARGETBRANCH#refs/heads/}"
git diff "origin/${target}...HEAD" > pr.diff
displayName: Write the PR diff
- script: |
curl -fsSL https://claude.ai/install.sh | bash -s stable
export PATH="$HOME/.local/bin:$PATH"
claude --bare -p "Review the change in pr.diff for correctness and security in this .NET solution. Read the files it touches for context. List each finding with its file, line, and severity." \
--append-system-prompt-file .claude/review-rules.md \
--allowedTools "Read,Grep,Glob" \
--permission-mode dontAsk \
--model claude-sonnet-5-5 \
--max-turns 15 \
--max-budget-usd 2.00 \
--output-format json > claude-review.json
jq -r '.result' claude-review.json
echo "Estimated cost (USD): $(jq -r '.total_cost_usd' claude-review.json)"
displayName: Claude review
env:
ANTHROPIC_API_KEY: $(ANTHROPIC_API_KEY)
- publish: claude-review.json
artifact: claude-review
condition: always()The pr: trigger in YAML works for repositories on GitHub and Bitbucket Cloud. For Azure Repos, leave it out and add the pipeline as a build validation policy on the target branch, which runs it for every PR into that branch.
Check the PATH line against where the installer reports it put the claude command on your agents. Keep .claude/review-rules.md on your main branch and review changes to it like code, because it tells Claude what to look for.
What each flag does
--allowedTools "Read,Grep,Glob"lets Claude read and search the repository without asking.--permission-mode dontAskdenies every other tool call, which Anthropic describes as suited to locked-down CI.--max-turnslimits the number of agentic turns. There is no limit by default.--max-budget-usdstops the run when estimated spend reaches the amount. It is a client-side estimate and a run can pass it, so leave headroom.--output-format jsonreturns the result withtotal_cost_usdand asession_id, so you can log the estimated cost of every run.
Authenticate through Microsoft Foundry
To bill through Azure, add these variables to the review step’s env block, and remove ANTHROPIC_API_KEY:
env:
CLAUDE_CODE_USE_FOUNDRY: '1'
ANTHROPIC_FOUNDRY_RESOURCE: your-foundry-resource
ANTHROPIC_FOUNDRY_API_KEY: $(ANTHROPIC_FOUNDRY_API_KEY)
ANTHROPIC_DEFAULT_SONNET_MODEL: your-sonnet-deploymentThen pass --model sonnet instead of a model ID. Anthropic’s Foundry page explains why pinning matters: without it, the alias resolves to Claude Code’s built-in default, which may not be deployed in your resource.
If your organisation does not allow keys, Claude Code can authenticate with Microsoft Entra ID instead. With no key set, it uses the Azure default credential chain, which includes a signed-in Azure CLI. Running the step in an AzureCLI@2 task with an Azure Resource Manager service connection gives it that sign-in. Prove this once in a test pipeline before removing the key, and give the service connection’s identity the Foundry User role.
What should Claude be allowed to do in your pipeline?
Start Claude with a read-only job, and add write access only where an engineer reviews the result. A job that can only read files and post comments cannot change your code. A job that pushes commits needs the same branch protection, build, and approval as any engineer’s change.
Treat PR content as untrusted input
A PR’s title, description, and code are written by whoever opened it, and Claude reads all of them. That makes them a route for prompt injection, where text in the change tries to redirect the agent. Anthropic’s own security review action states that it is not hardened against prompt injection, and should review only trusted PRs.
The defence is a narrow tool list. A job that can only read files and post comments has little to misuse, whatever its input says.
Keep secrets out of reach
- Map secrets explicitly. In Azure Pipelines, secret variables are not passed to scripts unless you map them in
env. Microsoft also advises never passing secrets on the command line, because some systems log command-line arguments. - Watch fork PRs. On public GitHub repositories, secrets are withheld from runs triggered by PRs from forks, so a Claude review there runs only for branches in the same repository.
- Prefer federation. Signing in to Foundry with OIDC removes the stored key altogether.
How do you keep the cost of each run down?
The cost of Claude in CI is the number of runs times the cost of each run, plus the runner minutes. These controls cut each part:
- Run it once per PR. Trigger on
opened,reopened, andready_for_reviewrather than every push, and letconcurrencycancel superseded runs. - Make it wait for the build.
needs: buildmeans no tokens are spent on a change that does not compile. - Cap each run. Use
--max-turns, a job timeout, and in headless mode--max-budget-usd. - Pick the model per job. In the change we measured in Anatomy of an AI Change, the independent reviews ran on a Sonnet model for about $3 of the $71 total. A smaller model suits triage and labelling.
- Keep CLAUDE.md short. Claude reads it on every run in the GitHub Action, so every line is paid for each time.
- Log the cost. In headless mode, record
total_cost_usdfrom each run, so you can see the trend before the invoice arrives.
In our experience, pipeline cost grows faster than AI adoption, because more changes, more checks, and more runs multiply together. The pricing guide sets out the published prices and why the multiplication matters.
How does this fit with the rest of your Claude Code setup?
The pipeline is one layer of the harness around Claude, and it works best when the other layers are in place. These guides cover the rest:
- Claude Code for .NET developers: installation,
CLAUDE.md, and pre-approved commands on a developer machine. - Configuring Claude Code for .NET: hooks that build and test after edits, MCP servers, skills, and subagents.
- Running Claude Code against Azure DevOps: why we built an opinionated MCP server for work items, sprints, and test management.
How can Talk Think Do help?
We build delivery pipelines on GitHub Actions and Azure, and Claude models and Claude Code are our primary development stack. Static code analysis with GitHub Advanced Security, extended with our own in-house rules, runs automatically on every pull request.
- GitHub Actions CI/CD and Advanced Security: reusable workflows, code scanning, and AI steps set up with budgets and gates.
- Claude Code development: builds delivered with Claude Code under senior engineer review.
- AI Delivery Assessment: for engineering leaders who need to show whether AI tooling is changing delivery.
See our pricing page for current engagement ranges, or book a consultation to talk through your pipeline.
Frequently asked questions
Can we use a Claude subscription instead of an API key in CI?
Why don't Claude's commits trigger our CI workflows?
Is there an official Azure DevOps task for Claude Code?
How do we pin the Claude Code version on build agents?
Can Claude Code fail the build?
Related guides
Pricing AI in the Pipeline: Claude Tokens, GitHub Minutes and Copilot Credits
What AI in your CI pipeline costs: Claude tokens, GitHub Actions minutes, Copilot AI Credits and Advanced Security licences, and how to cap each one.
Claude Code vs GitHub Copilot for .NET Teams: A UK CTO's Guide
Claude Code vs GitHub Copilot for .NET teams: autocomplete versus agentic delivery, what Copilot running Claude models changes, and how UK CTOs decide.
Harness Engineering for Coding Agents
What harness engineering means for AI coding agents: inner vs outer harnesses, guides, sensors, and deterministic tools for Cursor and Claude Code.