greg. Because greg is designed as a print agent that conforms strictly to the Unix philosophy—reading from stdin, streaming clean answers to stdout, isolating diagnostic logs to stderr, and managing state through content-addressed checkpoints—it fits seamlessly into interactive terminals, shell scripts, and automated CI pipelines alike.
For deep dives on session persistence and time-travel rollback mechanics, see Managing Threads. For configuring model providers and API keys, see Managing Providers.
- Prompt Recipes: Step-by-step patterns for exploring unfamiliar code, debugging errors, refactoring, writing test suites, and handling PR reviews.
- Plan Before Editing: Reconnaissance mode to inspect proposed architectural changes before touching disk files.
- Resume Conversations & Iterative Sittings: Continuing tasks across multiple commands with
-cand-r. - Snapshot Rollbacks with Checkpoints: Preflighting diffs and restoring previous workspace states.
- Run Parallel Sessions with Git Worktrees: Running concurrent agent turns without branch collisions.
- Unix Pipelines & Shell Automation: Piping
stdin, filtering structured JSON, and handling POSIX exit codes in shell scripts.
Prompt Recipes
These prompt patterns tackle core development tasks. Run them directly in your shell or adapt the wording to your repository conventions.Understand New Codebases
When joining a new project or auditing an unfamiliar service, usegreg to quickly map the architecture, identify key entry points, and trace execution flows.
1. Get a High-Level Architecture Overview
Navigate to the project root and askgreg to inspect the directory layout and explain the core patterns:
greg activates Glob, Read, and language server analysis (Lsp) to inspect configuration files, package manifests, and directory trees before producing a structured breakdown.
2. Find Relevant Code & Symbols
Pinpoint where specific business logic lives without searching manually through thousands of lines:3. Trace Execution Flow
Trace how data moves from an external request down to storage:Fix Bugs Efficiently
Resolve test regressions, runtime exceptions, and type errors by givinggreg reproduction steps and allowing safe, verified edits.
1. Pipe the Error Stack Trace Directly into Greg
Pipe your failing test output or application crash log straight intogreg via stdin:
greg ingests piped standard input automatically, you don’t need to copy and paste lengthy stack traces into string literals.
2. Apply Surgical Edits with --permission-mode acceptEdits
Once you understand the fix, authorize greg to edit workspace files directly while restricting arbitrary shell commands:
3. Verify the Fix with Scoped Tool Permissions
Instructgreg to apply the fix and verify it immediately by running your test runner using --allowed-tools:
greg can mutate files and run bun test, but cannot execute any unauthorized shell commands (like rm or curl).
Refactor & Modernize Code
Modernize legacy patterns, migrate deprecated API calls, and maintain consistency across large codebases.1. Identify Legacy or Deprecated Code
Search for outdated patterns across your repository:2. Execute Multi-File Modernization
Execute the refactor across affected modules with auto-approved file edits:3. Verify Formatting & Type Checking
Ensure your refactored code passes type checks and linter rules:Work with Tests
Generate robust, framework-idiomatic unit and integration tests that mirror your existing testing conventions.1. Identify Untested Code Paths
Askgreg to analyze test coverage and highlight missed edge cases:
2. Generate Test Suites Matching Project Patterns
Directgreg to scaffold tests following existing style, assertions, and mock helpers:
3. Run and Iterate on Test Failures
Instructgreg to execute the new test suite and iterate until every assertion passes:
Git & Pull Request Workflows
Generate release notes, conventional commit messages, and detailed PR descriptions directly from your Git working tree.1. Generate Conventional Commit Messages
Pipe your staged Git diff intogreg to produce a concise, semantic commit message:
2. Draft Comprehensive Pull Request Descriptions
Generate a structured markdown description for your pull request:3. Review Staged Changes for Security & Performance
Audit your diff before pushing to remote:Plan Before Editing
For complex tasks involving architectural changes or high-risk modifications, use Plan Mode (--permission-mode plan).
In plan mode, greg runs in reconnaissance:
- Write and execute tools (
Write,Edit,Bash) are completely hidden from the model. - Only read-only tools (
Read,Glob,Grep,Lsp,WebFetch,WebSearch) are active. greginspects files, maps dependencies, and presents a detailed implementation blueprint without touching a single file on disk.
Step 1: Run in Plan Mode
greg will explore your repository and stream a structured plan to stdout:
Step 2: Execute the Approved Plan
Once you have reviewed the plan, execute the first step with auto-approved file edits:Resume Conversations & Iterative Sittings
Tasks often require multi-turn refinement.greg maintains workspace-scoped conversation threads so you never have to repeat context.
Continue the Latest Workspace Session (-c)
Use the -c (or --continue) flag to pick up right where your last command left off:
Resume a Specific Historical Thread (-r)
If you switch branches or work on multiple features concurrently, list your workspace threads and resume any session by its ID:
Time-Travel Branching (--resume-session-at)
If a solution took a wrong turn, you can fork or step back to an earlier message turn without re-running earlier steps:
Snapshot Rollbacks with Checkpoints
Whenevergreg modifies or writes files, it automatically records content-addressed SHA-256 pre-mutation snapshots using Hernex’s FileCheckpointStore. If an agent run produces undesirable changes, you can inspect the diff and restore your workspace safely.
1. List Recorded Checkpoints
View the checkpoints captured during your current or latest session:2. Inspect the File Diff
Inspect the unified diff between your current workspace files and the recorded checkpoint:3. Preflight Dry-Run Restoration
Verify which files will be overwritten or restored before touching disk:4. Execute Restoration
Instantly revert the workspace back to the snapshot state:Run Parallel Sessions with Git Worktrees
When working on multiple features or running long-running agent tasks simultaneously, avoid branch collisions by combininggreg with Git worktrees.
Because greg scopes threads and checkpoints to process.cwd(), each worktree operates as a completely isolated workspace with its own conversation history and rollback tree.
1. Create a New Git Worktree
2. Run Greg in the Isolated Worktree
3. Work Simultaneously in Your Main Repository
Whilegreg works in the worktree, your main working tree remains completely untouched:
4. Clean Up When Finished
Once the feature branch is merged, remove the worktree:Unix Pipelines & Shell Automation
greg is built for command-line composability. It reads input from stdin, streams output to stdout, and sends diagnostics to stderr.
Stream Clean Output to Downstream Utilities
Extract data, copy to clipboard, or write directly to target files:Pipe External Command Diagnostics into Greg
Diagnose build failures or linter errors without leaving the terminal:Batch Processing with Structured JSON
When integratinggreg into CI/CD scripts or automated tools, request structured JSON output with --output-format json:
--output-format stream-json to receive newline-delimited JSON events for every step, tool invocation, and token chunk.
Shell Exit Codes in CI/CD Scripts
greg returns standard POSIX exit codes so your automation scripts can react deterministically:
Here is an example CI workflow script that runs
greg to verify type safety and automatically exits on failure: