Skip to content

Commit 7421bf6

Browse files
Checkpointing documentation (#1321)
Co-authored-by: matt korwel <matt.korwel@gmail.com>
1 parent db57d38 commit 7421bf6

File tree

4 files changed

+80
-2
lines changed

4 files changed

+80
-2
lines changed

docs/checkpointing.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Checkpointing
2+
3+
The Gemini CLI includes a Checkpointing feature that automatically saves a snapshot of your project's state before any file modifications are made by AI-powered tools. This allows you to safely experiment with and apply code changes, knowing you can instantly revert back to the state before the tool was run.
4+
5+
## How It Works
6+
7+
When you approve a tool that modifies the file system (like `write_file` or `replace`), the CLI automatically creates a "checkpoint." This checkpoint includes:
8+
9+
1. **A Git Snapshot:** A commit is made in a special, shadow Git repository located in your home directory (`~/.gemini/history/<project_hash>`). This snapshot captures the complete state of your project files at that moment. It does **not** interfere with your own project's Git repository.
10+
2. **Conversation History:** The entire conversation you've had with the agent up to that point is saved.
11+
3. **The Tool Call:** The specific tool call that was about to be executed is also stored.
12+
13+
If you want to undo the change or simply go back, you can use the `/restore` command. Restoring a checkpoint will:
14+
15+
- Revert all files in your project to the state captured in the snapshot.
16+
- Restore the conversation history in the CLI.
17+
- Re-propose the original tool call, allowing you to run it again, modify it, or simply ignore it.
18+
19+
All checkpoint data, including the Git snapshot and conversation history, is stored locally on your machine. The Git snapshot is stored in the shadow repository while the conversation history and tool calls are saved in a JSON file in your project's temporary directory, typically located at `~/.gemini/tmp/<project_hash>/checkpoints`.
20+
21+
## Enabling the Feature
22+
23+
The Checkpointing feature is disabled by default. To enable it, you can either use a command-line flag or edit your `settings.json` file.
24+
25+
### Using the Command-Line Flag
26+
27+
You can enable checkpointing for the current session by using the `--checkpointing` flag when starting the Gemini CLI:
28+
29+
```bash
30+
gemini --checkpointing
31+
```
32+
33+
### Using the `settings.json` File
34+
35+
To enable checkpointing by default for all sessions, you need to edit your `settings.json` file.
36+
37+
Add the following key to your `settings.json`:
38+
39+
```json
40+
{
41+
"features": {
42+
"checkpointing": {
43+
"enabled": true
44+
}
45+
}
46+
}
47+
```
48+
49+
## Using the `/restore` Command
50+
51+
Once enabled, checkpoints are created automatically. To manage them, you use the `/restore` command.
52+
53+
### List Available Checkpoints
54+
55+
To see a list of all saved checkpoints for the current project, simply run:
56+
57+
```
58+
/restore
59+
```
60+
61+
The CLI will display a list of available checkpoint files. These file names are typically composed of a timestamp, the name of the file being modified, and the name of the tool that was about to be run (e.g., `2025-06-22T10-00-00_000Z-my-file.txt-write_file`).
62+
63+
### Restore a Specific Checkpoint
64+
65+
To restore your project to a specific checkpoint, use the checkpoint file from the list:
66+
67+
```
68+
/restore <checkpoint_file>
69+
```
70+
71+
For example:
72+
73+
```
74+
/restore 2025-06-22T10-00-00_000Z-my-file.txt-write_file
75+
```
76+
77+
After running the command, your files and conversation will be immediately restored to the state they were in when the checkpoint was created, and the original tool prompt will reappear.

docs/cli/commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Slash commands provide meta-level control over the CLI itself.
6868

6969
- **Description:** Restores the project files to the state they were in just before a tool was executed. This is particularly useful for undoing file edits made by a tool. If run without a tool call ID, it will list available checkpoints to restore from.
7070
- **Usage:** `/restore [tool_call_id]`
71-
- **Note:** Only available if the CLI is invoked with the `--checkpointing` option or configured via [settings](./configuration.md).
71+
- **Note:** Only available if the CLI is invoked with the `--checkpointing` option or configured via [settings](./configuration.md). See [Checkpointing documentation](../checkpointing.md) for more details.
7272

7373
- **`/stats`**
7474

docs/cli/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ In addition to a project settings file, a project's `.gemini` directory can cont
150150

151151
- **`checkpointing`** (object):
152152

153-
- **Description:** Configures the checkpointing feature, which allows you to save and restore conversation and file states. See the [Checkpointing Commands](./commands.md#checkpointing-commands) for more details.
153+
- **Description:** Configures the checkpointing feature, which allows you to save and restore conversation and file states. See the [Checkpointing documentation](../checkpointing.md) for more details.
154154
- **Default:** `{"enabled": false}`
155155
- **Properties:**
156156
- **`enabled`** (boolean): When `true`, the `/restore` command is available.

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This documentation is organized into the following sections:
1616
- **[CLI Introduction](./cli/index.md):** Overview of the command-line interface.
1717
- **[Commands](./cli/commands.md):** Description of available CLI commands.
1818
- **[Configuration](./cli/configuration.md):** Information on configuring the CLI.
19+
- **[Checkpointing](./checkpointing.md):** Documentation for the checkpointing feature.
1920
- **[Extensions](./extension.md):** How to extend the CLI with new functionality.
2021
- **[Telemetry](./telemetry.md):** Overview of telemetry in the CLI.
2122
- **Core Details:** Documentation for `packages/core`.

0 commit comments

Comments
 (0)