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.- Headless Execution Principles: Stream isolation, non-interactive mode, and fail-closed security.
- POSIX Process Exit Codes: Scripting against exit codes (
0,1,2,4) in CI automation. - Structured JSON Outputs: Parsing results with
jqvia--output-format jsonand--output-format stream-json. - Ephemeral CI Execution: Preventing disk bloat on ephemeral runners.
- Enforcing Output Schemas: Guaranteeing valid JSON data structures.
- GitHub Actions Workflows: Production recipes for PR review, automated bug fixing, and security audits.
- Pre-Commit Hooks: Auditing staged Git diffs locally before commits.
- Docker Containerization: Packaging
gregin minimal containerized runners. - Next Steps: Guided links to deeper topics.
Headless Execution Principles
When executing inside CI runners (like GitHub Actions, GitLab CI, or Jenkins),greg operates with zero interactive prompts:
- Non-Interactive by Design:
gregnever waits for user keyboard input. If an unauthorized tool execution is attempted,gregfails closed immediately without hanging. - Stream Separation: Only final answers and structured payloads are sent to
stdout. Progress indicators, tool notices, and warnings are isolated onstderr, ensuring pipeline steps (| jq,| gh pr comment) receive valid data. - 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:
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.
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:
- 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):
Docker Containerization
To rungreg inside containerized CI runners or Kubernetes jobs:
Minimal Dockerfile
Running the Container
Next Steps
Now that you know how to automategreg in continuous integration:
- Permissions & Safety: Harden tool authorization with fail-closed rules.
- Lifecycle Hooks: Build event-driven pre-commit and post-execution guardrails.
- Common Workflows: Explore everyday terminal developer recipes.
- Managing Providers: Configure fallback chains and custom proxy gateways for CI.