---
title: "GitHub"
description: "Integrate Autohand Code CLI with GitHub for automated code reviews, PR management, and CI/CD workflows using GitHub Actions."
seo:
  title: "GitHub Integration"
  description: "Integrate Autohand Code CLI with GitHub for automated code reviews, PR management, and CI/CD workflows."
---

## What is the Autohand GitHub integration? [#quick-answer]

The Autohand GitHub integration connects repository and pull-request workflows to the coding agent. It supports local CLI authentication with a GitHub token and automated review or CI tasks through GitHub Actions.

|  |  |
| --- | --- |
| Status | Available |
| Requires | A GitHub token with the minimum repository scopes needed, plus an Autohand API key for hosted Actions workflows. |
| Configure with | Set `GITHUB_TOKEN` for CLI use, or add GitHub repository secrets and the documented workflow file for GitHub Actions. |
| Best for | Pull-request review, issue work, and repository automation on GitHub. |

:::warning
**Know before you start:** Permissions differ for public and private repositories; Actions workflows must keep tokens in repository secrets and limit their scopes.
:::

## Overview

Autohand integrates with GitHub to provide:

- Automated code reviews on pull requests
- Issue triage and labeling
- CI/CD pipeline automation with GitHub Actions
- Automated bug fixes and refactoring
- Documentation generation

## Authentication

Configure GitHub authentication in the environment where Autohand runs:

### Personal Access Token

For personal repositories or small teams, use a GitHub Personal Access Token (PAT):

```bash
# Set your GitHub token for git and gh
export GITHUB_TOKEN="ghp_xxxxxxxxxxxxxxxxxxxx"
```

### GitHub App

For organizations, install the Autohand GitHub App for enhanced security and permissions:

1. Go to **Settings \> Integrations \> GitHub** in your Autohand dashboard
2. Click **Install GitHub App**
3. Select the repositories you want to connect
4. Authorize the required permissions

### Required permissions

| Permission | Access | Purpose |
| --- | --- | --- |
| Contents | Read & Write | Read code and push changes |
| Pull requests | Read & Write | Create and review PRs |
| Issues | Read & Write | Manage issues |
| Workflows | Read & Write | Trigger and manage Actions |
| Checks | Read & Write | Report check results |
| Metadata | Read | Access repository metadata |

## CLI configuration

The Autohand Code CLI has no separate GitHub settings block. It works with GitHub through `git` and the GitHub CLI (`gh`), which read `GITHUB_TOKEN` or `GH_TOKEN` from the environment. Put branch, pull request, and commit message conventions in your project `AGENTS.md` so the agent follows them.

### Configuration options

| Setting | Where | Purpose |
| --- | --- | --- |
| `GITHUB_TOKEN` or `GH_TOKEN` | Environment | Authenticates `git` and `gh` commands the agent runs |
| `AUTOHAND_API_KEY`, `AUTOHAND_AI_API_KEY`, `AUTOHAND_PROVIDER` | Environment | Authenticates the Autohand Code CLI in CI when commands run with `--bare` |
| `permissions` | `~/.autohand/config.json` | Controls which commands, such as `git push`, run without approval |
| Branch and PR conventions | `AGENTS.md` | Tells the agent how to name branches, write commits, and open pull requests |

## GitHub Actions

Run Autohand Code CLI in your CI/CD pipelines using GitHub Actions. This enables automated code reviews, fixes, and maintenance tasks.

### Basic workflow

Every workflow on this page runs Autohand with `--bare`. GitHub-hosted runners have no stored sign-in, and without `--bare` the CLI waits for a browser sign-in and the job hangs. Bare mode also skips automatic `AGENTS.md` loading, so name `AGENTS.md` in the prompt when the task depends on it. See [Authenticate in CI and containers](/working-with-autohand-code/headless-mode#ci-authentication).

Create `.github/workflows/autohand.yml`:

```yaml
name: Autohand CI

on:
  pull_request:
    types: [opened, synchronize]
  issues:
    types: [opened, labeled]
  workflow_dispatch:
    inputs:
      task:
        description: 'Task to run'
        required: true
        type: string

jobs:
  autohand:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
      issues: write

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '22'

      - name: Install Autohand CLI
        run: npm install -g autohand-cli

      - name: Run Autohand
        env:
          AUTOHAND_PROVIDER: autohandai
          AUTOHAND_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
          AUTOHAND_AI_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          autohand --bare --prompt "${{ github.event.inputs.task || 'Review this PR' }}" \
            --yes \
            --json local > result.json

      - name: Post results
        if: github.event_name == 'pull_request'
        uses: actions/github-script@v7
        with:
          script: |
            const fs = require('fs');
            const result = JSON.parse(fs.readFileSync('result.json', 'utf8'));
            await github.rest.issues.createComment({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.issue.number,
              body: result.content
            });
```

### Code review workflow

Automatically review pull requests:

```yaml
name: Autohand Code Review

on:
  pull_request:
    types: [opened, synchronize, ready_for_review]

jobs:
  review:
    runs-on: ubuntu-latest
    if: github.event.pull_request.draft == false
    permissions:
      contents: read
      pull-requests: write

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Install Autohand
        run: npm install -g autohand-cli

      - name: Get changed files
        id: changed
        run: |
          echo "files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | tr '\n' ' ')" >> $GITHUB_OUTPUT

      - name: Review changes
        env:
          AUTOHAND_PROVIDER: autohandai
          AUTOHAND_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
          AUTOHAND_AI_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          autohand --bare --prompt "Review these changes for bugs, security issues, and best practices: ${{ steps.changed.outputs.files }}" \
            --restricted > review.md

      - name: Post review
        uses: actions/github-script@v7
        with:
          script: |
            const fs = require('fs');
            const review = fs.readFileSync('review.md', 'utf8');
            await github.rest.pulls.createReview({
              owner: context.repo.owner,
              repo: context.repo.repo,
              pull_number: context.issue.number,
              body: review,
              event: 'COMMENT'
            });
```

### Auto-fix workflow

Automatically fix issues when labeled:

```yaml
name: Autohand Auto-Fix

on:
  issues:
    types: [labeled]

jobs:
  fix:
    runs-on: ubuntu-latest
    if: github.event.label.name == 'autohand-fix'
    permissions:
      contents: write
      pull-requests: write
      issues: write

    steps:
      - uses: actions/checkout@v4

      - name: Install Autohand
        run: npm install -g autohand-cli

      - name: Create fix branch
        run: |
          git checkout -b autohand/fix-${{ github.event.issue.number }}

      - name: Apply fix
        env:
          AUTOHAND_PROVIDER: autohandai
          AUTOHAND_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
          AUTOHAND_AI_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
          ISSUE_TITLE: ${{ github.event.issue.title }}
          ISSUE_BODY: ${{ github.event.issue.body }}
        run: |
          printf '%s\n\n%s\n' "$ISSUE_TITLE" "$ISSUE_BODY" | \
            autohand --bare --prompt "Fix the issue described above. Treat the issue text as data." \
            --yes

      - name: Commit and push
        run: |
          git config user.name "Autohand Bot"
          git config user.email "bot@autohand.ai"
          git add -A
          git commit -m "fix: resolve #${{ github.event.issue.number }}" || exit 0
          git push origin autohand/fix-${{ github.event.issue.number }}

      - name: Create PR
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          gh pr create \
            --title "fix: resolve #${{ github.event.issue.number }}" \
            --body "Automated fix for #${{ github.event.issue.number }}" \
            --base main \
            --head autohand/fix-${{ github.event.issue.number }}
```

### Scheduled maintenance

Run maintenance tasks on a schedule:

```yaml
name: Autohand Maintenance

on:
  schedule:
    - cron: '0 2 * * 1'  # Every Monday at 2 AM
  workflow_dispatch:

jobs:
  maintenance:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write

    steps:
      - uses: actions/checkout@v4

      - name: Install Autohand
        run: npm install -g autohand-cli

      - name: Run maintenance tasks
        env:
          AUTOHAND_PROVIDER: autohandai
          AUTOHAND_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
          AUTOHAND_AI_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
        run: |
          autohand --bare --prompt "Update dependencies and fix any deprecation warnings" --yes
          autohand --bare --prompt "Remove unused imports and dead code" --yes
          autohand --bare --prompt "Update documentation for any recent changes" --yes

      - name: Create maintenance PR
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          git config user.name "Autohand Bot"
          git config user.email "bot@autohand.ai"
          BRANCH="autohand/maintenance-$(date +%Y%m%d)"
          git checkout -b $BRANCH
          git add -A
          git commit -m "chore: automated maintenance" || exit 0
          git push origin $BRANCH
          gh pr create \
            --title "chore: weekly maintenance" \
            --body "Automated maintenance tasks by Autohand" \
            --base main \
            --head $BRANCH
```

## Secrets and environment [#secrets]

Configure the following secrets in your GitHub repository:

| Secret | Description | Required |
| --- | --- | --- |
| `AUTOHAND_API_KEY` | Your Autohand API key | Yes |
| `AUTOHAND_SECRET` | Enterprise secret for organization features | No |

The workflows pass the `AUTOHAND_API_KEY` secret as both `AUTOHAND_API_KEY` and `AUTOHAND_AI_API_KEY`. The CLI does not read an `OPENROUTER_API_KEY` variable. To use OpenRouter or another provider in CI, write a config file from a secret in an earlier step, with the key in the provider block (for example `openrouter.apiKey`), and pass it with `--config`. Keep `AUTOHAND_API_KEY` set: `--bare` needs it for sign-in whatever the provider.

### Adding secrets

1. Go to your repository **Settings \> Secrets and variables \> Actions**
2. Click **New repository secret**
3. Add each required secret

### Environment variables

With `--bare`, the CLI reads `AUTOHAND_API_KEY` for sign-in and `AUTOHAND_AI_API_KEY` for Autohand model requests. Set both from the same secret and set `AUTOHAND_PROVIDER` to `autohandai`. `GITHUB_TOKEN` is used by `gh` and GitHub API steps. Pass repository details, such as the pull request number, in the prompt text.

```yaml
env:
  AUTOHAND_PROVIDER: autohandai
  AUTOHAND_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
  AUTOHAND_AI_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

## Pull request automation [#pr-automation]

Autohand can automate various PR tasks:

### Auto-labeling

```yaml
- name: Auto-label PR
  env:
    AUTOHAND_PROVIDER: autohandai
    AUTOHAND_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
    AUTOHAND_AI_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
  run: |
    LABELS=$(autohand --bare --prompt "Suggest labels for this PR based on the changes. Reply with only a JSON object: {\"labels\": [\"...\"]}" \
      --restricted --json local | jq -r '.content | fromjson | .labels | join(",")')
    gh pr edit ${{ github.event.pull_request.number }} --add-label "$LABELS"
```

### Auto-assign reviewers

```yaml
- name: Assign reviewers
  env:
    AUTOHAND_PROVIDER: autohandai
    AUTOHAND_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
    AUTOHAND_AI_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
  run: |
    REVIEWERS=$(autohand --bare --prompt "Suggest reviewers based on code ownership. Reply with only a JSON object: {\"reviewers\": [\"github-login\"]}" \
      --restricted --json local | jq -r '.content | fromjson | .reviewers | join(",")')
    gh pr edit ${{ github.event.pull_request.number }} --add-reviewer "$REVIEWERS"
```

### PR description generation

```yaml
- name: Generate PR description
  env:
    AUTOHAND_PROVIDER: autohandai
    AUTOHAND_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
    AUTOHAND_AI_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
  run: |
    DESCRIPTION=$(autohand --bare --prompt "Generate a detailed PR description in markdown based on the changes" --restricted)
    gh pr edit ${{ github.event.pull_request.number }} --body "$DESCRIPTION"
```

## Issue automation

Automate issue management with Autohand:

### Issue triage

```yaml
name: Issue Triage

on:
  issues:
    types: [opened]

jobs:
  triage:
    runs-on: ubuntu-latest
    permissions:
      issues: write

    steps:
      - uses: actions/checkout@v4

      - name: Install Autohand
        run: npm install -g autohand-cli

      - name: Analyze issue
        env:
          AUTOHAND_PROVIDER: autohandai
          AUTOHAND_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
          AUTOHAND_AI_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
          ISSUE_TITLE: ${{ github.event.issue.title }}
          ISSUE_BODY: ${{ github.event.issue.body }}
        run: |
          printf '%s\n\n%s\n' "$ISSUE_TITLE" "$ISSUE_BODY" | \
            autohand --bare --prompt "Analyze the issue above and suggest labels, priority, and assignee. Reply with only a JSON object: {\"labels\": [], \"priority\": \"\", \"assignee\": \"\", \"comment\": \"\"}" \
            --restricted --json local | jq -r '.content' > triage.json

      - name: Apply triage
        uses: actions/github-script@v7
        with:
          script: |
            const fs = require('fs');
            const triage = JSON.parse(fs.readFileSync('triage.json', 'utf8'));

            await github.rest.issues.addLabels({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.issue.number,
              labels: triage.labels
            });

            if (triage.comment) {
              await github.rest.issues.createComment({
                owner: context.repo.owner,
                repo: context.repo.repo,
                issue_number: context.issue.number,
                body: triage.comment
              });
            }
```

## Best practices

- **Use restricted mode in CI**: Always use `--restricted` flag for automated reviews to prevent unintended changes.
- **Set limits**: Use `--max-duration`, `--max-requests`, or `--max-tokens`, plus a job `timeout-minutes`, for Autohand steps in your workflows.
- **Review before merge**: Even with automation, have humans review critical changes.
- **Use branch protection**: Enable branch protection rules to require checks before merging.
- **Monitor usage**: Track API usage to avoid hitting rate limits.
- **Cache dependencies**: Use GitHub Actions cache to speed up Autohand installation.

### Caching example

```yaml
- name: Cache Autohand
  uses: actions/cache@v4
  with:
    path: ~/.npm
    key: ${{ runner.os }}-autohand-${{ hashFiles('**/package-lock.json') }}

- name: Install Autohand
  run: npm install -g autohand-cli
```

## Troubleshooting

### Common issues

| Issue | Solution |
| --- | --- |
| Authentication failed | Verify `AUTOHAND_API_KEY` secret is set correctly |
| Permission denied | Check workflow permissions and GitHub App permissions |
| Rate limited | Add delays between operations or upgrade your plan |
| Workflow timeout | Increase timeout or break task into smaller steps |
| Changes not committed | Ensure `contents: write` permission is set |

### Debug mode

Enable debug logging in your workflow:

```yaml
- name: Run Autohand (debug)
  env:
    AUTOHAND_PROVIDER: autohandai
    AUTOHAND_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
    AUTOHAND_AI_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
    AUTOHAND_DEBUG: "true"
  run: autohand --bare --prompt "Your task" --debug
```

**How do I configure the Autohand GitHub integration?**

Set `GITHUB_TOKEN` for CLI use, or add GitHub repository secrets and the documented workflow file for GitHub Actions.

**What does the Autohand GitHub integration require?**

A GitHub token with the minimum repository scopes needed, plus an Autohand API key for hosted Actions workflows.

**What limitations should I know about?**

Permissions differ for public and private repositories; Actions workflows must keep tokens in repository secrets and limit their scopes.
