Skip to main content
Every time you execute greg, the agent organizes its work into a Thread. A thread encapsulates multi-turn conversational memory, message sequence, tool invocations, results, and associated file delta checkpoints for your task. Unlike stateless CLI tools that forget context between commands, greg’s thread system allows you to build features across iterative turns, inspect file mutation diffs, branch conversations into divergent experiments, and roll back changes safely.
Looking for practical everyday examples of continuing sessions and reverting checkpoints? See Common Workflows for step-by-step developer recipes.
This page covers:

How Threads Work

Threads are powered by the @amaranthic/hernex FileThreadStore and adhere to four core architectural principles:
  1. Workspace Scoped: Threads are automatically tied to the directory where you execute greg (process.cwd()). When you switch between project folders, greg keeps their conversation histories completely isolated.
  2. Persistent on Disk: Sessions are stored under ~/.greg/threads/<thread-id>/ (or $HERNEX_HOME/threads/<thread-id>/), with thread metadata in thread.json and append-only conversation events in transcript.jsonl.
  3. Automated Titles: Thread titles are automatically derived from your initial prompt (normalized up to 80 characters).
  4. Coupled to Checkpoints: Every thread maintains an associated checkpoint manifest at threads/<id>/checkpoints/manifest.json and content-addressed blobs at blobs/sha256/<hash>, capturing SHA-256 pre-mutation snapshots before any file write or edit touches disk.

Continuing & Resuming Sessions

You can interact with existing threads using standard CLI flags:

1. Continue the Latest Workspace Thread (-c)

To continue your most recent task in the current workspace without repeating previous context:

2. Resume a Specific Thread by ID (-r)

To resume any historical thread by its unique identifier:

3. Time-Travel Branching (--resume-session-at)

If you want to step back to an earlier point in a conversation without re-running previous turns, pass --resume-session-at <index>. This truncates the active message transcript to that specific turn index:
1-Based Turn Indexing: The --resume-session-at <index> flag uses 1-based indexing representing the exact count of conversational turns to keep. For example, --resume-session-at 1 retains only the first turn, while --resume-session-at 2 preserves the first two turns and discards subsequent turns for divergent branching.

Time-Travel Checkpoints & Safe Undo

Checkpoints protect your code by capturing exact pre-mutation file states before tools like Write or Edit modify files. Every checkpoint is bound to its parent thread and indexed by both a unique UUID and a sequential integer (1, 2, 3…). You can manage checkpoints using the greg checkpoints (or greg checkpoint) subcommand tree:

1. List Recorded Checkpoints

List all file mutation checkpoints recorded for a thread:
Output includes the sequential index, checkpoint UUID, label, turn index, number of files affected, and creation timestamp:

2. Show Checkpoint Details

Inspect the exact metadata and file entries stored in a checkpoint:

3. View Mutation Diffs (diff)

Review file mutation actions and SHA-256 hash transitions recorded by a checkpoint:
The output displays git-style status indicators (A added, D deleted, M modified) alongside 8-character SHA-256 hash transitions:
To emit machine-readable JSON for tooling:

4. Restore Workspace to a Checkpoint (restore)

Revert your workspace files back to their recorded pre-mutation state:

Preflight Inspection (--dry-run)

Before rolling back files on disk, inspect the planned restoration actions and verify potential conflicts:
Outputs the restoration plan (files to restore, delete, or potential conflicts) in JSON without touching any files on disk.

Force Restoration (--force)

If files in your workspace were modified outside of greg after the checkpoint was created, greg will guard against overwriting external changes. Pass --force to override conflicts:

Managing Threads Subcommand Tree (greg threads)

greg provides a comprehensive threads subcommand tree to inspect, branch, and maintain your session history:

1. List Threads

List recent threads for the current workspace (shows ID, title, turn count, model, status, and last update timestamp):
Options:
  • -n, --limit <number>: Maximum number of threads to list (default: 20).
  • --working-directory <dir>: Filter threads by an alternative workspace path.

2. Show Thread Details

View complete metadata, working directory, model, reasoning level, and turn metrics for a specific session:

3. Create a Thread Explicitly

Initialize a new persistent conversation thread before executing tasks:

4. Resume a Thread via Subcommand

Resume a thread directly using the subcommand, optionally passing your next prompt:

5. Fork a Thread for Divergent Experiments

Branch an existing session into a brand new thread. The new thread inherits the full transcript history of the parent thread, allowing you to experiment with divergent approaches without altering the original:
You can also fork up to a specific transcript sequence number using --at-sequence:

6. Export Session Transcripts

Display or pipe the complete structured event log of a session (user prompts, model messages, tool calls, and outputs):
Options:
  • -n, --limit <number>: Maximum number of entries to return.
  • --after <sequence>: Only return transcript events recorded after this sequence number.

7. Prune & Purge Threads

Clean up disk space by pruning the oldest conversation threads or purging all sessions:
Purging All Threads: Pass -1 as the count to prune all conversation threads at once. To purge threads across every project on your machine rather than just the active directory, include --all-workspaces:
The -y (--yes) flag bypasses the interactive confirmation prompt ([y/N]) and is mandatory when executing prune commands in CI/CD pipelines or non-interactive scripts.

8. Delete a Thread Permanently

Permanently delete an individual thread and its transcript history from disk:

Execution Modifiers for Threads

When running or resuming a thread, customize execution behavior with dedicated flags:

Next Steps

Now that you understand session persistence and rollback mechanics:
  • Common Workflows: Explore step-by-step recipes for bug fixing, refactoring, and test automation.
  • Managing Providers: Configure your preferred model, reasoning effort levels, and automatic fallback chains.
  • Quickstart: Return to the quickstart to practice everyday agent commands.