title: "Headless and CI/CD" last_updated: 2026-03-21 status: experimental difficulty: advanced prerequisites: [04-hooks-and-commands, 05-sub-agents]
Headless and CI/CD
Coming in V2. This module is scaffolded with an outline.
Core Question
How do agents run without me?
Module Outline
Concepts
-
Headless mode — Running AI agents without an interactive terminal. The agent receives instructions programmatically and returns results via structured output (JSON).
-
Why headless matters — Enables automation: agents can run in CI/CD pipelines, cron jobs, PR review bots, and other automated workflows.
-
The trust boundary — Interactive sessions have a human in the loop. Headless mode does not. This changes the risk profile and requires stronger guardrails.
-
CI/CD integration patterns:
- PR review agent: automatically reviews code on pull request
- Test generation: agent writes tests for changed code
- Documentation updates: agent updates docs when code changes
- Migration assistance: agent helps with version upgrades
-
Guardrails for automated agents — Permission restrictions, output validation, cost limits, timeout controls, sandbox execution.
-
Structured output — Using JSON output mode for machine-readable results that can be consumed by other tools in your pipeline.
-
Monitoring automated agents — Logging, cost tracking, success/failure metrics, alerting on unexpected behavior.
Tool-Specific Content
- Claude Code: --print flag, -p for headless, JSON output, GitHub Actions integration, SDK usage
- Codex CLI: Non-interactive mode, automation patterns, scripting
Exercises
- Run your first headless command and parse the JSON output
- Create a GitHub Action that uses an AI agent to review PRs
- Build a cron job that generates a daily code quality report
- Set up cost monitoring and alerting for automated agent runs