Skip to main content
This guide collects practical, battle-tested recipes for everyday development with 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.
This page covers:

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, use greg 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 ask greg 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:
Enabling & Configuring Language Servers: greg includes built-in LSP integration for TypeScript, Python, Rust, Go, CSS, HTML, and JSON to achieve compiler-grade definition navigation and type checking.By default, enableLsp is false to optimize startup time. To enable LSP code intelligence globally:
Language servers can be inspected, customized, or registered using the greg lsp subcommand tree:
To run a prompt without language server overhead or to disable LSP for a single execution, pass the --disable-lsp flag:

Fix Bugs Efficiently

Resolve test regressions, runtime exceptions, and type errors by giving greg 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 into greg via stdin:
Because 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

Instruct greg to apply the fix and verify it immediately by running your test runner using --allowed-tools:
Here, greg can mutate files and run bun test, but cannot execute any unauthorized shell commands (like rm or curl).
If greg’s edits introduce unexpected regressions, you can instantly revert the workspace with greg checkpoints restore 1. See Snapshot Rollbacks.

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

Ask greg to analyze test coverage and highlight missed edge cases:

2. Generate Test Suites Matching Project Patterns

Direct greg to scaffold tests following existing style, assertions, and mock helpers:

3. Run and Iterate on Test Failures

Instruct greg 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 into greg to produce a concise, semantic commit message:
You can commit directly in one line:

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.
  • greg inspects 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

Whenever greg 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:
Output:

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:
Output:

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 combining greg 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

While greg 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 integrating greg into CI/CD scripts or automated tools, request structured JSON output with --output-format json:
For real-time streaming event pipelines, use --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: