Back to Examples

Run an Agent Headless in CI

Most terminal agents support a headless / print mode (-p) so you can run them non-interactively in CI for triage, fixes, or checks.

Workflow PatternsAdvancedyaml
Example Code
# .github/workflows/agent-triage.yml
# Runs a coding agent non-interactively on new issues.
# Works the same way across Claude Code, Codex, and Grok Build —
# each exposes a headless "-p" / print mode for automation.

name: Agent triage
on:
  issues:
    types: [opened]

jobs:
  triage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install agent
        run: npm install -g @anthropic-ai/claude-code
        # Grok Build: curl -fsSL https://x.ai/cli/install.sh | bash
        # Codex CLI:  npm install -g @openai/codex

      - name: Run agent headless
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
          # XAI_API_KEY for Grok Build, OPENAI_API_KEY for Codex
        run: |
          claude -p "Read AGENTS.md, then reproduce and root-cause the bug in
          issue #${{ github.event.issue.number }}. Post findings as a comment.
          Do NOT push code." \
            --allowedTools "Read,Grep,Bash(gh issue comment:*)"

# Safety in CI: grant the narrowest tool/permission scope possible,
# never expose write/deploy access, and keep secrets in the CI vault.

When to use this

Most terminal agents support a headless / print mode (-p) so you can run them non-interactively in CI for triage, fixes, or checks.