AI-Native CI/CD — Wire Agents Into Your Pipeline Safely
Your CI catches failures in seconds. A human fixes them hours later. Here's the stack that closes that gap with self-correcting pipelines — and the guardrails that...
The stack (6 tools)
Only native agent-in-Actions system with five-layer defense architecture built in — no custom wrapper scripts required
Production-proven at Elastic via CLI in Buildkite; intelligent mode detection; native codebase context integration
Non-negotiable for production — blocks exfiltration and prompt injection at the network level
Prevents agents from holding write credentials; agent failure cannot become repository compromise
First-class agentic workflow support; Elastic's reference implementation runs here; MCP server integration for bidirectional agent-to-pipeline comms
Elastic found that teaching agents org norms via CLAUDE.md was the difference between useful agents and ones that had to be babysat
TL;DR
- GitHub Agentic Workflows (technical preview, Feb 2026) and
anthropics/claude-code-action@v1give you the primitives for self-correcting CI pipelines today - Elastic ran Claude Code via a CLI wrapper in Buildkite for one month at 45% of dependencies: 24 broken PRs fixed with 22 commits, roughly 20 days of dev work saved
- The security architecture has five layers — sandbox isolation, read-only agent tokens, Agent Workflow Firewall, safe-outputs job separation, and AI-powered threat detection — skip any one of them and you have a different product
- Confidence thresholds (0.70–0.90) gate what agents do autonomously versus what they escalate — most teams haven’t defined these, which is why they either run agents with no guardrails or don’t run them at all
- Cost: ~$0.04–0.15 per autonomous repair run; ROI breakeven at roughly 2–4 successful fixes per month
The human in your break-fix path is now the bottleneck, not the safeguard. That’s the uncomfortable math most engineering teams haven’t confronted yet: your CI pipeline catches failures in seconds, your Slack notification reaches a human in minutes, and that human is busy. The median time-to-fix on a broken dependency bump is measured in hours, sometimes days. The agent that could have patched it sat idle because nobody architected the trigger.
Elastic shipped that architecture. Over a single month running Claude Code via a custom CLI wrapper in their Buildkite pipeline — limited to 45% of their dependencies — the agent fixed 24 broken PRs with 22 commits and saved an estimated 20 days of engineering work. That’s not a benchmark in a controlled environment. That’s a production result from a company with a real monorepo and real stakes. They didn’t use anthropics/claude-code-action@v1 directly; they built a thin Buildkite-native wrapper around the Claude Code CLI. The Action and the CLI share the same underlying capability — the difference is integration surface, not agent behavior.
I’m not arguing for removing humans from the loop. I’m arguing that you need to design which decisions agents make autonomously and which ones they escalate. Most teams haven’t done that work. So they either run agents with no guardrails — one bad PR away from a production incident — or they don’t run them at all and keep paging engineers at 2am for dependency version conflicts. This stack is the middle path: agents handle the mechanical failures, humans review the edge cases, and the architecture makes the boundary explicit.
Stack Overview
This stack puts a coding agent in the failure path of your CI pipeline, gives it the context to diagnose what broke, and gates its write access through a structured handoff — so a confused or manipulated agent cannot compromise your repository even if it tries.
What you’re building: A pipeline where build failures trigger an agent that reads logs, identifies the fix, proposes or commits a change based on a confidence threshold, and escalates when it doesn’t know. Humans review agent PRs instead of debugging stack traces.
Components at a glance:
- GitHub Agentic Workflows — Markdown-to-YAML compilation layer that produces security-hardened Actions workflows with trust boundaries baked in
- Claude Code GitHub Action (
anthropics/claude-code-action@v1) — Autonomous code agent that detects whether it’s being triggered by a human mention or an automated failure event, and adjusts behavior accordingly - Agent Workflow Firewall — Squid proxy sidecar that routes all agent outbound traffic through a domain allowlist; blocks exfiltration at the network level
- Safe Outputs Gating — Structured artifact handoff that separates what the agent proposes from what actually gets written; the agent never holds write credentials
- Buildkite (optional but recommended at team scale) — Pipeline orchestration with first-class agent isolation and MCP server support for bidirectional log and annotation access
- CLAUDE.md Context Layer — Repository-local instructions that teach the agent your coding standards, forbidden patterns, and escalation rules before it touches anything
What the combination solves that individual tools cannot: each component handles part of the problem in isolation. GitHub Actions catches failures. Claude Code can write fixes. But without the Firewall blocking exfiltration, without safe-outputs separating read from write, and without CLAUDE.md teaching the agent your norms, you have an autonomous system with no meaningful guardrails. The security architecture and the agent capability have to be designed together — they’re not separable.
The architecture flows like this: CI failure → agentic workflow trigger → agent sandbox loads with read-only token → CLAUDE.md context injected → Claude Code analyzes logs and generates fix → all outbound traffic routes through Agent Workflow Firewall → fix proposal writes to structured artifact → confidence threshold gates the outcome (auto-commit above 0.90, draft PR between 0.70–0.90, human escalation below 0.70) → threat detection scan runs before any change is applied → only clean proposals reach the scoped write job.
graph TD
A[CI Failure Event] --> B[Agentic Workflow Trigger]
B --> C[Agent Sandbox — Read-Only Token]
C --> D[CLAUDE.md Context Loaded]
D --> E[Claude Code — Log Analysis + Fix Generation]
E --> F[Agent Workflow Firewall — Egress Control]
F --> G[Safe Outputs Artifact]
G --> H{Confidence Threshold}
H -->|"> 0.90 — High confidence"| I[Auto-commit — Scoped Write Job]
H -->|"0.70–0.90 — Medium confidence"| J[Draft PR — Human Review Required]
H -->|"< 0.70 — Low confidence"| K[Human Escalation — Agent Blocked]
I --> L[Threat Detection Scan]
J --> L
L -->|Pass| M[Change Applied]
L -->|Fail| N[Workflow Blocked — Alert Fired]
Fallback: CI failure triggers an agent sandbox with a read-only token. The agent analyzes logs with CLAUDE.md context, generates a fix proposal, and routes all traffic through the Agent Workflow Firewall. A confidence score determines the outcome — above 0.90 auto-commits via a separate scoped write job, 0.70–0.90 opens a draft PR, below 0.70 escalates to a human. A threat detection scan runs before any write job executes.
Components
GitHub Agentic Workflows (Technical Preview)
GitHub shipped Agentic Workflows into technical preview on February 13, 2026. The core mechanic: you write a Markdown file describing what you want the agent to do, run gh aw compile, and get back a security-hardened GitHub Actions YAML with trust boundaries enforced at the workflow level.
The key architectural decision is that agents receive a read-only GitHub token by default. Even if the agent attempts write operations, the underlying token doesn’t allow them. Write access lives in a separate job that reads a structured artifact the agent produces — it never flows through the agent itself.
Why this in the stack:
- Eliminates custom wrapper scripts; the compilation step handles permission scoping automatically
- Supports Claude Code, GitHub Copilot CLI, and Codex as interchangeable agent backends
- Agent Workflow Firewall is built into the system, not bolted on afterward
Agentic Workflows is in early development and may change significantly. GitHub itself recommends caution — run it on non-critical repositories first, expand after validation.
Claude Code GitHub Action (anthropics/claude-code-action@v1)
The GitHub Action is Claude Code’s production CI integration. It automatically detects whether it’s being triggered by a @claude mention in a PR comment (interactive mode) or by an automated pipeline event (automation mode), and adjusts behavior accordingly. In automation mode, it runs immediately with the provided prompt — no human in the loop.
This is the integration path for GitHub Actions-native deployments. Elastic took a different route: they use the Claude Code CLI invoked via a custom claude-fix-build.sh wrapper script inside Buildkite, not this Action directly. Both approaches give you the same agent — the difference is that Buildkite’s MCP server lets Elastic feed structured build logs and annotations back into the agent context, which the GitHub Action alone doesn’t handle as cleanly.
Why this in the stack:
- Intelligent mode detection eliminates a class of configuration bugs where agents run interactively when they should be autonomous
- Elastic’s production deployment (via CLI path) validates the underlying capability at real scale
- Supports both GitHub Actions (Action) and Buildkite (CLI wrapper) — pick the integration surface that fits your pipeline
Security note: Claude Code operates without network restrictions by default. If you’re not using GitHub Agentic Workflows (which bundles the Agent Workflow Firewall), add Harden-Runner or equivalent egress control to your Actions setup. Not optional in production.
Agent Workflow Firewall
The Firewall routes all agent outbound traffic through a Squid proxy enforcing an explicit domain allowlist. The agent cannot call arbitrary external services, cannot exfiltrate secrets to a remote endpoint, and cannot be manipulated via prompt injection into phoning home. It operates at the container level — agent-agnostic, enforced below the application layer.
Why this in the stack:
- Blocks data exfiltration at the network level regardless of which agent is running
- Required defense against prompt injection attacks via malicious commit messages or issue content
- The one control that most tutorials skip entirely, and the one most likely to save you when something goes wrong
StepSecurity Harden-Runner is the drop-in alternative if you can’t use the technical preview. Self-hosted runners with iptables rules work if compliance requires owning the full network stack. No egress control is non-negotiable — don’t ship without one.
Safe Outputs Gating System
The safe-outputs pattern is what makes the whole architecture trustworthy. The agent’s job is to analyze the failure and produce a structured JSON artifact describing what it wants to do. A separate job — with a scoped write token — reads that artifact and applies only the explicitly permitted operations. The agent never touches the write credential.
Hard limits are configurable: at most one new PR created per workflow run, comment additions only (no edits), PR titles must match a prefix pattern. If the agent’s artifact requests something outside those limits, the gating job rejects it without alerting the agent — it simply doesn’t apply. This matters because a confused or manipulated agent can’t probe its own write boundaries by watching what succeeds.
Why this in the stack:
- Agent failure or confusion cannot become repository compromise
- Audit trail is clean: the artifact shows exactly what the agent proposed before anything was applied
- Builds organizational trust — teams adopt agent automation faster when write access is visibly bounded
Buildkite (Optional — Recommended at Team Scale)
Elastic’s reference implementation runs on Buildkite, not GitHub Actions directly. Buildkite’s value in this stack is agent isolation by default (each step runs in a container), first-class MCP server support for bidirectional agent-to-pipeline communication, and webhook-triggered dispatch that integrates cleanly with multi-stage pipelines.
The Buildkite MCP server gives Claude Code access to build logs, annotations, and pipeline metadata without requiring broad API credentials. That’s how Elastic feeds failure context back into the agent loop — not just the error message, but the full structured log from the failing step. Without that richer context, the agent is diagnosing from a stack trace. With it, the agent sees the full build graph. The difference shows up in fix quality: stack-trace-only diagnoses produce plausible-but-wrong patches more often than full-log diagnoses do.
CLAUDE.md Context Layer
Elastic’s most important operational finding: teaching the agent your org norms via CLAUDE.md was the difference between useful agents and agents that produced fixes failing style checks, using deprecated APIs, or requiring two or three iterations before producing something mergeable. CLAUDE.md loads repository context before the agent touches anything — it’s not documentation, it’s configuration.
The CLAUDE.md file is also where your confidence thresholds live. You define — in plain text, version-controlled alongside your code — exactly what “autonomous” means for your organization. Change the threshold, commit the file, done. No workflow YAML to touch, no infrastructure redeploy.
Setup Walkthrough
Step 1: Install the GitHub Agentic Workflows CLI
Enable GitHub Agentic Workflows for your organization (requires beta access as of April 2026), then install the CLI extension.
# Install gh aw extension
gh extension install github/gh-aw
# Verify installation
gh aw --version
Step 2: Create your agent intent file
Write the Markdown file that describes what your repair agent should do. Keep scope narrow — dependency fixes first, general errors only after you’ve validated behavior on the simpler cases.
<!-- .github/workflows/repair-agent.md -->
# Pipeline Repair Agent
## Trigger
On: workflow_run [ci-build] — completed, conclusion: failure
## Goal
Analyze the failing CI build, identify the root cause, and propose or commit a fix.
## Permissions
- Read: repository contents, workflow logs, pull requests
- Write: pull request comments, draft pull requests (via safe-outputs only)
## Scope
- Only trigger on dependency-bump PRs (branch prefix: deps/, renovate/, dependabot/)
- Do not modify files outside: package.json, package-lock.json, pyproject.toml, requirements*.txt
- Maximum one PR created per workflow run
## Escalation
- Confidence > 0.90: commit fix directly to branch
- Confidence 0.70–0.90: open draft PR with explanation
- Confidence < 0.70: post comment with diagnosis, do not attempt fix
## Context
Load CLAUDE.md from repository root before analysis.
Step 3: Compile the intent file to a hardened workflow
The compilation step validates your permissions, injects the Agent Workflow Firewall configuration, and produces a .lock.yml file that GitHub Actions actually executes. Review this file before committing — it shows exactly what will run and which permissions are in scope.
# Compile Markdown intent to security-hardened workflow
gh aw compile .github/workflows/repair-agent.md
# Output: .github/workflows/repair-agent.lock.yml
# Review the generated YAML before committing — it shows exactly what runs
Step 4: Create your CLAUDE.md file
Most teams underinvest here. Be specific about what the agent should not do, not just what it should do. An agent without explicit forbidden actions will find creative ways to do things you didn’t intend. The first version of CLAUDE.md is never the final version — plan to iterate based on the first two weeks of agent output.
<!-- CLAUDE.md -->
# Agent Context for [Your Repo]
## Coding Standards
- TypeScript strict mode; no `any` types without explicit justification
- All imports must be from approved internal packages (see package.json allowlist)
- Tests required for any logic change; test file must be in same PR
## Forbidden Actions
- Do not modify database migration files
- Do not change environment variable names or add new required env vars
- Do not upgrade major versions of core dependencies (patch and minor only)
- Do not touch files in /infrastructure or /terraform
## Escalation Rules
- If the fix requires understanding business logic: escalate, do not guess
- If the failing test is testing behavior that changed intentionally: post comment asking for clarification
- If confidence score < 0.70: always escalate, never commit
## Common Fix Patterns
- Missing dependency: add to package.json, run npm install, commit lock file
- Version mismatch: check package.json for peer dependency constraints before bumping
- Type error after dependency bump: check @types/* package for corresponding update
Step 5: Configure safe-outputs boundaries
In the compiled workflow, define exactly which write operations the gating job is permitted to perform. This is your hard limit — the agent cannot exceed it regardless of what its artifact requests.
# Excerpt from .github/workflows/repair-agent.lock.yml
# Generated by gh aw compile — shown here for context
jobs:
agent-analysis:
permissions:
contents: read
pull-requests: read
# Agent runs here — read-only token; no write access
apply-safe-outputs:
needs: agent-analysis
permissions:
contents: write # Only for branch commits on deps/* branches
pull-requests: write # Only for draft PR creation
steps:
- name: Apply agent proposal
uses: github/safe-outputs-apply@v1
with:
artifact: agent-proposal
allowed-operations: |
create-draft-pr: true
commit-to-branch: "refs/heads/deps/*"
add-pr-comment: true
max-prs-created: 1
title-prefix: "[agent-fix]"
Step 6: Wire the Agent Workflow Firewall egress rules
The Firewall ships with a default allowlist. Add your specific package registries and remove anything your agents don’t need. The narrower the allowlist, the more effective the control.
# .github/agent-workflow-firewall.yml
egress:
allowed-domains:
- registry.npmjs.org
- pypi.org
- files.pythonhosted.org
- api.github.com
- uploads.github.com
- objects.githubusercontent.com
deny-all-others: true
log-blocked-requests: true # Review these logs weekly for the first month
Step 7: Add the Claude Code Action for autonomous mode
Configure the Action to run in automation mode — no @claude mention required, just the failure trigger and your CLAUDE.md context. Set max_turns explicitly; an unbounded agent on a complex failure will loop. Elastic rate-limits to 100 API calls per hour across their agent fleet — that number is not arbitrary.
# Excerpt from the agent-analysis job in your compiled workflow
- name: Run Claude Code repair agent
uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
prompt: |
A CI build has failed on branch ${{ github.head_ref }}.
Failure logs: ${{ steps.fetch-logs.outputs.content }}
Analyze the failure, determine the root cause, and propose a fix.
Load repository context from CLAUDE.md before starting.
Output your proposal as a structured artifact per the safe-outputs schema.
Include your confidence score (0.0–1.0) in the artifact.
max_turns: 15
# Hard limit: agent stops after 15 turns regardless of completion state
Step 8: Test in isolation before production
Run the workflow manually on a non-critical repository with a known-broken dependency before connecting it to your production failure events. The first run on a real repo surfaces CLAUDE.md gaps faster than any amount of dry-run testing.
# Trigger the workflow manually on a test branch
gh workflow run repair-agent.lock.yml \
--field branch=test/intentionally-broken-dep \
--field simulate-failure=true
# Monitor execution
gh aw logs repair-agent --follow
# Audit what the agent proposed vs. what was applied
gh aw audit repair-agent --run-id <run-id>
Pricing
| Component | License | Free Tier | Paid from | Note |
|---|---|---|---|---|
| GitHub Agentic Workflows | GitHub TOS | Technical preview; included with GitHub Actions | — | 1–2 Copilot premium requests consumed per workflow run |
| Claude Code Action (Anthropic API) | Proprietary | None | $3.00/1M input, $15.00/1M output (Opus) | ~$0.04–0.15 per repair run at typical log + fix token volume |
| GitHub Actions runners | GitHub TOS | 2,000 min/mo (free plans) | $0.008/min (standard runner) | Agent jobs run 2–10 min each; costs climb fast with retry loops |
| Buildkite | Proprietary | None | $450/mo (25 users) | Only needed at team scale; GitHub Actions sufficient for prototype phase |
| Agent Workflow Firewall | Included with Agentic Workflows | Included | — | No separate cost; Squid proxy overhead negligible |
| CLAUDE.md | Free | — | — | Text file; no cost |
GitHub Actions minute costs climb fast when agents retry in loops. Set
max_turnson every Claude Code invocation and add a workflow-leveltimeout-minutes: 15. An unbounded retry loop on a complex failure can burn $50–200 in a single incident. Elastic rate-limits to 100 API calls per hour across their agent fleet — that number is a hard-learned constraint, not an arbitrary default.
At prototype scale (5–10 failures/week), total monthly cost runs $50–200. At Elastic’s scale — 30–50 dependency failures per week across a monorepo — expect $500–1,500/month including Buildkite. ROI breakeven is approximately 2–4 successful autonomous fixes per month at a $150/hour fully-loaded engineering cost. If your break-fix path takes two hours on average, the math closes fast.
When This Stack Fits
- Dependency-heavy monorepos with frequent automated bumps. Renovate/Dependabot produce predictable breakage patterns — version conflicts, missing peer deps, type mismatches. Bounded scope, clear fix patterns. This is where Elastic’s 45% rollout landed.
- Teams where on-call engineers are the bottleneck, not the safeguard. If median time-to-fix is hours, an agent PR review is faster than raw debugging — “does this diff fix it” is easier than “why did this break.”
- Trunk-based development with short-lived branches and small PRs. Long-lived feature branches create context agents don’t have access to; confidence scores will reflect that honestly.
- Teams willing to do the CLAUDE.md work upfront. Teaching the agent your norms is the difference between failure and success. If you won’t maintain repository context, you’ll spend more time supervising than the agent saves.
When This Stack Does Not Fit
- Architectural failures and logic bugs. Repair agents work for mechanical failures — broken deps, missing files, type mismatches after version bumps. For architectural bugs they produce plausible-looking wrong fixes. CLAUDE.md escalation rules are your defense — write them before the first bad auto-commit.
- Regulated environments prohibiting autonomous commits. If compliance requires human sign-off on every change, the autonomous loop doesn’t apply. The safe-outputs pattern still helps (agents propose, humans approve faster), but not the repair loop itself.
- Pipelines without branch protection. An agent with a miscalibrated confidence score could auto-commit directly to main. Branch protection is a prerequisite. Add it first.
- Teams that haven’t defined what agents can touch. If you can’t write a CLAUDE.md “forbidden actions” section, you’re not ready. Running agents without scope constraints means your first incident sets the program back six months.
- Public repositories with untrusted external content. This stack does not survive targeted prompt injection. The Agent Workflow Firewall limits blast radius but doesn’t eliminate the attack surface. Add explicit input sanitization before agent context loading.
Elastic’s pattern — 45% first, validate for a month, then expand — is the right sequence regardless of scale. The number isn’t the point; the patience is.