Skip to content
Development Practice

Claude Code in GitHub Actions and Azure Pipelines for .NET Teams

11 min read

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.

Where Claude fits in a .NET pull request pipeline: after the build and tests pass, and before human review
A swimlane showing who does what when a pull request goes through a .NET pipeline, across three lanes: the pipeline, Claude, and the engineer. Stage 1, build: the pipeline builds the solution and runs unit tests and analysers. Stage 2, full checks: the pipeline runs the full test suite and code scanning. A gate follows: the checks must pass. Stage 3, AI review, highlighted: Claude reviews the change read-only, within a turn limit and a cost cap. Stage 4, human review: the engineer reads the findings, decides what to fix, and approves. Stage 5, fixes on request: Claude makes a fix when an engineer asks with @claude, and the engineer reviews the fix like any other change.

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.

YAML.github/workflows/claude-review.yml
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"
1A newer run for the same PR cancels the older one.
2Claude runs only when the build and tests pass.
3The action starts the inline comment server only when this tool is named here.

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 User role 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.

YAMLReview job, Foundry steps
    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"
1Required so GitHub can issue the OIDC token that Azure trusts.
2The resource name only, not a URL.

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.

YAMLazure-pipelines-claude-review.yml
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()
1A full history is needed to diff against the target branch.
2Secret variables reach a script only when mapped here.

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 dontAsk denies every other tool call, which Anthropic describes as suited to locked-down CI.
  • --max-turns limits the number of agentic turns. There is no limit by default.
  • --max-budget-usd stops 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 json returns the result with total_cost_usd and a session_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:

YAMLClaude review step, Foundry variables
        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-deployment
1Pins the sonnet alias to your deployment name.

Then 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, and ready_for_review rather than every push, and let concurrency cancel superseded runs.
  • Make it wait for the build. needs: build means 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_usd from 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:

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.

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?
With the GitHub Action, yes: store a token from claude setup-token as CLAUDE_CODE_OAUTH_TOKEN and pass it to the claude_code_oauth_token input. Anthropic recommends an API key for secrets shared across an organisation, because the token belongs to one person's subscription. Headless runs with --bare never read OAuth credentials, so they need ANTHROPIC_API_KEY.
Why don't Claude's commits trigger our CI workflows?
GitHub does not trigger workflows on commits made with the default GITHUB_TOKEN. If you pass that token to the Claude Code GitHub Action, remove it so the action authenticates as the Claude GitHub App, or pass a token from your own GitHub App instead.
Is there an official Azure DevOps task for Claude Code?
Anthropic documents GitHub Actions and GitLab CI/CD, not an Azure DevOps task. Third-party tasks exist in the Visual Studio Marketplace. Running the Claude Code command-line tool directly in a script step keeps the version, the flags, and the credentials under your own control.
How do we pin the Claude Code version on build agents?
Pass a channel or a version to the installer, for example bash -s stable for the stable channel, or a specific version number. With npm, pin the @anthropic-ai/claude-code package version. Pinning means a Claude Code release never changes your pipeline's behaviour without a commit.
Can Claude Code fail the build?
In headless mode, Claude Code exits with a non-zero code when the run itself fails, such as a missing credential. To fail on review findings, ask for structured output with --json-schema, read the structured_output field, and exit non-zero when it reports a blocking finding.

Ready to transform your software?

Let's talk about your project. Contact us for a free consultation and see how we can deliver a business-critical solution at startup speed.