Skip to content
Esc
↑↓navigate↵open⌘Jpreview
Start
On this page

CI/CD Integrations

Adding the Autohand Code Agent SDK to CI/CD pipelines turns pull requests and commits into automated review, test, and deployment tasks.

Common pipeline tasks

  • Review pull requests and post comments.
  • Generate or update tests for changed files.
  • Validate migrations, configuration, and documentation.
  • Build release notes from commit history.

GitHub Actions example

Start with a workflow that runs the agent, then post the result with whatever language your CI image already has installed.

The runner has no stored Autohand sign-in, so the workflow runs the CLI with --bare and sets AUTOHAND_PROVIDER, AUTOHAND_API_KEY, and AUTOHAND_AI_API_KEY. Without --bare, the CLI waits for a browser sign-in and the job hangs. See Authenticate in CI and containers.

name: Autohand Review
on:
  pull_request:
    types: [opened, synchronize]

permissions:
  contents: read
  pull-requests: write

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: curl -fsSL https://autohand.ai/install.sh | sh
      - run: autohand --bare -p "Review this pull request" --restricted --json local > review.json
        env:
          AUTOHAND_PROVIDER: autohandai
          AUTOHAND_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
          AUTOHAND_AI_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
      - run: node scripts/post-review.js review.json
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          PR_NUMBER: ${{ github.event.pull_request.number }}
import fs from 'node:fs/promises';
import { Octokit } from '@octokit/rest';

const review = JSON.parse(await fs.readFile(process.argv[2], 'utf8'));
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');

await new Octokit({ auth: process.env.GITHUB_TOKEN }).rest.issues.createComment({
  owner,
  repo,
  issue_number: Number(process.env.PR_NUMBER),
  body: review.content
});
import fs from 'node:fs/promises';
import { Octokit } from '@octokit/rest';

type Review = { type: string; content: string };

const review = JSON.parse(await fs.readFile(process.argv[2], 'utf8')) as Review;
const [owner, repo] = process.env.GITHUB_REPOSITORY!.split('/');

await new Octokit({ auth: process.env.GITHUB_TOKEN }).rest.issues.createComment({
  owner,
  repo,
  issue_number: Number(process.env.PR_NUMBER),
  body: review.content
});
import json
import os
import requests
import sys

owner, repo = os.environ["GITHUB_REPOSITORY"].split("/")
review = json.load(open(sys.argv[1]))

requests.post(
    f"https://api.github.com/repos/{owner}/{repo}/issues/{os.environ['PR_NUMBER']}/comments",
    headers={"Authorization": f"Bearer {os.environ['GITHUB_TOKEN']}"},
    json={"body": review["content"]},
)
body, _ := os.ReadFile(os.Args[1])
var review struct{ Content string `json:"content"` }
json.Unmarshal(body, &review)

client := github.NewTokenClient(ctx, os.Getenv("GITHUB_TOKEN"))
owner, repo := splitRepo(os.Getenv("GITHUB_REPOSITORY"))
client.Issues.CreateComment(ctx, owner, repo, prNumber(), &github.IssueComment{
  Body: github.String(review.Content),
})
String review = Files.readString(Path.of(args[0]));
String body = Json.parse(review).getString("content");
String[] repo = System.getenv("GITHUB_REPOSITORY").split("/");

github.createIssueComment(
  repo[0],
  repo[1],
  Integer.parseInt(System.getenv("PR_NUMBER")),
  body
);
let review = try JSONDecoder().decode(Review.self, from: Data(contentsOf: URL(fileURLWithPath: CommandLine.arguments[1])))
let repository = ProcessInfo.processInfo.environment["GITHUB_REPOSITORY"]!.split(separator: "/")

try await github.createIssueComment(
    owner: String(repository[0]),
    repo: String(repository[1]),
    number: Int(ProcessInfo.processInfo.environment["PR_NUMBER"]!)!,
    body: review.content
)
curl -X POST \
  -H "Authorization: Bearer $GITHUB_TOKEN" \
  -H "Accept: application/vnd.github+json" \
  "https://api.github.com/repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments" \
  -d "$(jq -n --arg body "$(jq -r .content review.json)" '{body:$body}')" 

The post scripts read PR_NUMBER to find the pull request, so the workflow sets it from github.event.pull_request.number. The permissions block lets GITHUB_TOKEN write the comment. See CI Reviewer Bot for a full walkthrough, including how pull requests from forks behave.

Security in CI

  • Run agents in ephemeral containers with minimal permissions.
  • Use read-only file systems when possible.
  • Never expose AUTOHAND_API_KEY in logs.
  • Require human approval before the agent can push or deploy.

Best practices

  • Keep pipeline agents focused on a single task. Long, open-ended prompts are harder to debug.
  • Exit with a non-zero status only when the agent found a blocking issue.
  • Cache the Autohand Code CLI and dependencies between runs.
  • Store agent output as artifacts so developers can inspect it.

Last updated on

Was this helpful?

Send Feedback

Help us improve this documentation page. Your feedback is valuable.

We'll only contact you if we need clarification