A failed build starts a session you can watch live.
K2 runs AI agents on a server you own. Add one job to your pipeline, and a failed build starts Claude Code in that repo's workspace. Read along, type in or stop it.
- Free on your own Apple Silicon Mac or Linux box
- $2.99 a month if a hosted runner needs an address
- Sessions auto-approve unless you switch that off
- lint0:41
- build2:08
- test2 failed
- hand offPOST 200
> Run 8841 failed. Fix it on a branch. Don't merge. ✓ Read the failed job's log Backoff resets on every 5xx, so the test times out. ✓ Tests pass on fix/retry-backoff ✓ Opened pull request 512 $ k2 respond --final "Not merged."
Sample data.








Your CI job ends. The session stays open.
- Your CICI
- Agent on your serverAgent
- YouYou
- Your CI: Test fails on main
- Your CI: Hand-off job sends one POST, ends
- Agent: Reads the log, plans a fix
- You, if you want: Type a change into the live tabOr let it finish with nobody there.
- Agent: Takes your change
- Agent: Tests pass on a branch
- Agent: Opens a pull request, reports back
- You: Review it and merge
- CI is done here. The agent keeps working on your server.
Watch
A live tab, on desktop or web.
Join
POST …/<id>Read back
GET …/<id>/messagesStop
POST …/<id>/kill
Your prompt sets the rule against merging, so keep it in the workflow.
One server, one key, one step in your workflow.
Use a K2 Connect address, or a self-hosted runner.
-
1
Give the repo a workspace
Run these yourself on your server, and sign in Claude Code there once.
$ k2 agent hire ~/agents/shop-api \ --agent claude $ git clone git@github.com:you/shop-api.git \ ~/agents/shop-api/repo $ gh auth login $ k2 workspace trust ~/agents/shop-api \ --always $ k2 api on
-
2
Scope a key to it
It opens that one workspace and nothing else. CI runs bill to your Anthropic key. Save the
k2sk_key as a CI secret; you see it once. To use your Claude plan instead, leave the Anthropic key out. That's automated use, so check your provider's terms.$ printf %s "$ANTHROPIC_API_KEY" | \ k2 api-key create --label ci \ --workspaces shop-api \ --allow host-sessions \ --provider anthropic --key-stdin
-
3
Add the failure job
It runs only after a failed push, so pull requests from forks stay away from the agent. The session outlives this job. Any CI that can send HTTP works.
hand-off: needs: test if: >- failure() && github.event_name == 'push' runs-on: ubuntu-latest env: K2_URL: ${{ secrets.K2_URL }} K2_KEY: ${{ secrets.K2_KEY }} K2_WS: shop-api steps: - run: | P="Run $GITHUB_RUN_ID failed. In repo/, read it with gh run view $GITHUB_RUN_ID --log-failed. Fix the cause in a new git worktree and open a pull request. Don't merge." B='{prompt:$p,timeout_secs:1800}' A="Authorization: Bearer $K2_KEY" jq -n --arg p "$P" "$B" | curl -fsS --json @- -H "$A" \ "$K2_URL/v1/w/$K2_WS/host-sessions"
Swipe sideways to read the longest lines →
Auto-approve is on by default. Choose it on purpose.
A pipeline can't answer a prompt, so API sessions start with prompts off. One switch per workspace.
On, the default
The agent acts without asking, with the full shell of the K2 user.
k2 workspace api-skip-permissions set shop-api on
Use it on a box you can wipe.- Edit a fileRuns
- Open a pull requestRuns
Off
The agent stops at each CLI prompt until someone answers in the live tab.
k2 workspace api-skip-permissions set shop-api off
Use it when someone is watching.- Edit a fileWaits for you
- Open a pull requestNot reached
Read this before it runs unattended.
Full list on our security pageNo spend caps
K2 shows token use but can't cap it.
Set a limit with your provider.
Commands and edits aren't logged
K2 records sign-ins, mail sends, agent messages, approvals and app calls.
Read git history for what changed.
One user account
Agents on one server share one user account, so text in a build log could steer one past K2's rules.
Give CI agents their own box.
No SSO, SAML or MFA. Logins use passwords, so give them only to people you'd trust with the box.
Three ways to run Claude Code from CI.
For a one-shot job in the runner, the first two are less to set up and can cap a run. K2 fits when you want the session on your own box, open to you while it works.
| claude -p | Claude Code GitHub Action | K2 host session | |
|---|---|---|---|
| Where it runs | Wherever you call it | GitHub-hosted runners, on your Actions minutes | Your K2 server |
| What you see | Text, JSON or a stream | A comment, or the run log | A live terminal tab you can type into |
| Permissions | By default, a call needing approval is denied. --allowedTools lists what runs | With a plain prompt, no shell or GitHub API access until you grant tools | Auto-approve on by default |
| Spend limits | --max-budget-usd, --max-turns | --max-turns, workflow timeouts | No caps. A kill route and your provider's limits |
Claude Code details from Anthropic's docs at code.claude.com, read 5 November 2026. K2 runs Claude Code and isn't affiliated with Anthropic.
Free to try. You pay for an address if CI needs one.
Your API key or AI plan is separate, with no markup. K2 is open source (MIT). Why K2
Hand your next failed build to an agent.
- Download K2 for Apple Silicon Mac or Linux.
- Hire one agent on a box you can wipe.
- Break a test in a throwaway pipeline.