The headless AI coding agent built for the Unix pipeline.
Most AI coding assistants try to replace your development environment with heavy Electron apps or fullscreen TUIs that hijack your terminal.
greg takes the opposite approach.
Designed as a pure print agent adhering to the Unix philosophy, greg runs non-interactively in your shell, script, or CI pipeline:
stdiningests your context, diffs, and prompt streams.stdoutemits pure, parseable results or structured JSON.stderrisolates diagnostics, tool status, and progress without polluting downstream commands.- Standard POSIX exit codes ensure your shell scripts and CI gates fail fast and reliably.
# Pipe code directly into greg, pipe the review straight into your tools
git diff | greg "Review this patch for memory leaks and race conditions"
# Extract strictly validated JSON for automation
greg "Analyze src/auth and list exposed endpoints" -o json | jq -r '.result'No popups, no prompts asking you to press Enter. Feed greg via pipes (cat error.log | greg "Diagnose failure"), redirect stdout to files, or stream newline-delimited JSON (-o stream-json) directly into other automated services.
Never fear an agent making bad edits. Every file change is cryptographically hashed with SHA-256 before modification. If you don't like what greg wrote, undo instantly:
greg checkpoints restore 1Choose how much autonomy you grant with built-in permission modes:
default: Safe reconnaissance (read-only file inspection and web search).acceptEdits: Automated code writing and refactoring with shell execution locked down.plan: Zero disk mutations—architectural planning only.- Scoped wildcard rules like
--allowed-tools "Read(src/*),Bash(bun test *)"keep operations strictly within your project boundaries.
Intercept, mutate, or veto actions using custom shell scripts or secondary LLM evaluators:
Start: Rewrites prompts, verifies environments, or injects repository context before the model starts.PreToolUse: Intercepts dangerous commands (git push, destructive scripts) before execution.PostToolUse: Automatically formats files (Prettier, Biome, rustfmt) right after edits.Stop: Runs tests before exit—vetoing completion and re-prompting the model if assertions fail.
Route queries to frontier intelligence across Anthropic Claude, Google Gemini, OpenAI, DeepSeek, Groq, or self-hosted local gateways. Configure fallbacks to seamlessly switch models if an API rate-limits.
curl -fsSL https://raw.githubusercontent.com/amaranthic/greg/main/installer/install.sh | bash# Pick your preferred provider (Anthropic, Gemini, OpenAI, etc.)
export GEMINI_API_KEY="your-api-key"
greg config set model google/gemini-3.8-flash# Ask questions about your code
greg "Explain the request flow in src/core"
# Autonomous refactoring with safe workspace edits
greg "Refactor src/utils/format.ts to export formatDuration" --permission-mode acceptEdits
# Fix bugs and run test suites
greg "Fix failing test cases" --permission-mode acceptEdits --allowed-tools "Bash(bun test *)"Looking for CLI flags, lifecycle hook recipes, permission policies, or CI/CD pipeline examples?
Visit the official documentation site:
👉 https://greg-docs.mintlify.site
- Quickstart Guide: Setup, credentials, and first run.
- Permission System: Fail-closed security rules and modes.
- Lifecycle Hooks: Automate linting, prompt mutation, and veto checks.
- Threads & Checkpoints: Session resumption and time-travel rollback.
- CI/CD & Pre-Commit: Headless pipeline automation.
- How Greg Works: Architectural deep dive into the Hernex engine.
MIT © Amaranthic