Skip to main content
Because greg is engineered as a print agent conforming to the Unix philosophy—reading from stdin, streaming results to stdout, isolating diagnostic logs to stderr, and returning standard POSIX exit codes—it fits into automated headless pipelines, CI/CD runners, and pre-commit hooks. Unlike interactive coding assistants that stall waiting for terminal prompts, greg executes autonomously from command-line flags and exits deterministically.
Before running greg in automated pipelines, review Permissions & Safety to configure appropriate tool access, and Managing Providers for setting API credentials in CI environments.
This page covers:

Headless Execution Principles

When executing inside CI runners (like GitHub Actions, GitLab CI, or Jenkins), greg operates with zero interactive prompts:
  1. Non-Interactive by Design: greg never waits for user keyboard input. If an unauthorized tool execution is attempted, greg fails closed immediately without hanging.
  2. Stream Separation: Only final answers and structured payloads are sent to stdout. Progress indicators, tool notices, and warnings are isolated on stderr, ensuring pipeline steps (| jq, | gh pr comment) receive valid data.
  3. Automated Error Recovery: Built-in request retries (--max-retries) and model fallback chains (--fallback-model) ensure transient provider rate limits do not break CI builds.

POSIX Process Exit Codes

greg returns deterministic exit codes so automation scripts can make branching decisions:

Robust Shell Script Handling Recipe


Structured JSON Outputs

For machine-to-machine integrations, avoid parsing raw Markdown text. Use --output-format json to receive a structured JSON payload:
The emitted JSON payload includes:
  • result: The final model output text or parsed object.
  • sessionId: The unique thread identifier.
  • turnMetrics: Turn count, duration in milliseconds, and finish reason.
  • totalUsage: Input, output, reasoning, and total token counts.
You can inspect findings directly with jq:

Real-Time Event Streaming (stream-json)

For CI dashboards or live event telemetry, pass --output-format stream-json. greg emits newline-delimited JSON events for every token chunk, tool start, tool completion, and token step in real time.

Ephemeral CI Execution

By default, greg creates thread directories and delta checkpoints under ~/.greg/threads/. On ephemeral CI runners where disks are wiped after each job, this overhead is unnecessary. Pass --no-session-persistence to run completely in-memory:
When active:
  • No session JSON files are created on disk.
  • Pre-mutation snapshots are skipped.
  • Disk I/O is reduced to zero.

Enforcing Output Schemas

When downstream automation scripts expect an exact JSON schema, enforce structure using --json-schema:

GitHub Actions Workflows

1. Automated Pull Request Code Reviewer

Runs on every pull request, analyzes the diff against the target branch, and posts a review comment directly onto the PR:

2. Autonomous Bug Fixer & Test Verification

Fixes failing tests and automatically submits a pull request with the solution:

Pre-Commit Hooks

Audit uncommitted changes before pushing to remote repositories using standard Git hooks or Husky:

Setting Up a Git Pre-Commit Hook

Create .git/hooks/pre-commit (or configure via Husky):
Make the script executable:

Docker Containerization

To run greg inside containerized CI runners or Kubernetes jobs:

Minimal Dockerfile

Running the Container


Next Steps

Now that you know how to automate greg in continuous integration: