Skip to content

Commit d0b6701

Browse files
authored
docs(sessions): add documentation for chat recording and session management (#13667)
1 parent 94c3eec commit d0b6701

File tree

4 files changed

+201
-1
lines changed

4 files changed

+201
-1
lines changed

docs/cli/commands.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,21 @@ Slash commands provide meta-level control over the CLI itself.
164164
- **Note:** Only available if checkpointing is configured via
165165
[settings](../get-started/configuration.md). See
166166
[Checkpointing documentation](../cli/checkpointing.md) for more details.
167+
- **`/resume`**
168+
- **Description:** Browse and resume previous conversation sessions. Opens an
169+
interactive session browser where you can search, filter, and select from
170+
automatically saved conversations.
171+
- **Features:**
172+
- **Session Browser:** Interactive interface showing all saved sessions with
173+
timestamps, message counts, and first user message for context
174+
- **Search:** Use `/` to search through conversation content across all
175+
sessions
176+
- **Sorting:** Sort sessions by date or message count
177+
- **Management:** Delete unwanted sessions directly from the browser
178+
- **Resume:** Select any session to resume and continue the conversation
179+
- **Note:** All conversations are automatically saved as you chat - no manual
180+
saving required. See [Session Management](../cli/session-management.md) for
181+
complete details.
167182

168183
- [**`/settings`**](./settings.md)
169184
- **Description:** Open the settings editor to view and modify Gemini CLI

docs/cli/session-management.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# Session Management
2+
3+
Gemini CLI includes robust session management features that automatically save
4+
your conversation history. This allows you to interrupt your work and resume
5+
exactly where you left off, review past interactions, and manage your
6+
conversation history effectively.
7+
8+
## Automatic Saving
9+
10+
Every time you interact with Gemini CLI, your session is automatically saved.
11+
This happens in the background without any manual intervention.
12+
13+
- **What is saved:** The complete conversation history, including:
14+
- Your prompts and the model's responses.
15+
- All tool executions (inputs and outputs).
16+
- Token usage statistics (input/output/cached, etc.).
17+
- Assistant thoughts/reasoning summaries (when available).
18+
- **Location:** Sessions are stored in `~/.gemini/tmp/<project_hash>/chats/`.
19+
- **Scope:** Sessions are project-specific. Switching directories to a different
20+
project will switch to that project's session history.
21+
22+
## Resuming Sessions
23+
24+
You can resume a previous session to continue the conversation with all prior
25+
context restored.
26+
27+
### From the Command Line
28+
29+
When starting the CLI, you can use the `--resume` (or `-r`) flag:
30+
31+
- **Resume latest:**
32+
33+
```bash
34+
gemini --resume
35+
```
36+
37+
This immediately loads the most recent session.
38+
39+
- **Resume by index:** First, list available sessions (see
40+
[Listing Sessions](#listing-sessions)), then use the index number:
41+
42+
```bash
43+
gemini --resume 1
44+
```
45+
46+
- **Resume by ID:** You can also provide the full session UUID:
47+
```bash
48+
gemini --resume a1b2c3d4-e5f6-7890-abcd-ef1234567890
49+
```
50+
51+
### From the Interactive Interface
52+
53+
While the CLI is running, you can use the `/resume` slash command to open the
54+
**Session Browser**:
55+
56+
```text
57+
/resume
58+
```
59+
60+
This opens an interactive interface where you can:
61+
62+
- **Browse:** Scroll through a list of your past sessions.
63+
- **Preview:** See details like the session date, message count, and the first
64+
user prompt.
65+
- **Search:** Press `/` to enter search mode, then type to filter sessions by ID
66+
or content.
67+
- **Select:** Press `Enter` to resume the selected session.
68+
69+
## Managing Sessions
70+
71+
### Listing Sessions
72+
73+
To see a list of all available sessions for the current project from the command
74+
line:
75+
76+
```bash
77+
gemini --list-sessions
78+
```
79+
80+
Output example:
81+
82+
```text
83+
Available sessions for this project (3):
84+
85+
1. Fix bug in auth (2 days ago) [a1b2c3d4]
86+
2. Refactor database schema (5 hours ago) [e5f67890]
87+
3. Update documentation (Just now) [abcd1234]
88+
```
89+
90+
### Deleting Sessions
91+
92+
You can remove old or unwanted sessions to free up space or declutter your
93+
history.
94+
95+
**From the Command Line:** Use the `--delete-session` flag with an index or ID:
96+
97+
```bash
98+
gemini --delete-session 2
99+
```
100+
101+
**From the Session Browser:**
102+
103+
1. Open the browser with `/resume`.
104+
2. Navigate to the session you want to remove.
105+
3. Press `x`.
106+
107+
## Configuration
108+
109+
You can configure how Gemini CLI manages your session history in your
110+
`settings.json` file.
111+
112+
### Session Retention
113+
114+
To prevent your history from growing indefinitely, you can enable automatic
115+
cleanup policies.
116+
117+
```json
118+
{
119+
"general": {
120+
"sessionRetention": {
121+
"enabled": true,
122+
"maxAge": "30d", // Keep sessions for 30 days
123+
"maxCount": 50 // Keep the 50 most recent sessions
124+
}
125+
}
126+
}
127+
```
128+
129+
- **`enabled`**: (boolean) Master switch for session cleanup. Default is
130+
`false`.
131+
- **`maxAge`**: (string) Duration to keep sessions (e.g., "24h", "7d", "4w").
132+
Sessions older than this will be deleted.
133+
- **`maxCount`**: (number) Maximum number of sessions to retain. The oldest
134+
sessions exceeding this count will be deleted.
135+
- **`minRetention`**: (string) Minimum retention period (safety limit). Defaults
136+
to `"1d"`; sessions newer than this period are never deleted by automatic
137+
cleanup.
138+
139+
### Session Limits
140+
141+
You can also limit the length of individual sessions to prevent context windows
142+
from becoming too large and expensive.
143+
144+
```json
145+
{
146+
"model": {
147+
"maxSessionTurns": 100
148+
}
149+
}
150+
```
151+
152+
- **`maxSessionTurns`**: (number) The maximum number of turns (user + model
153+
exchanges) allowed in a single session. Set to `-1` for unlimited (default).
154+
155+
**Behavior when limit is reached:**
156+
- **Interactive Mode:** The CLI shows an informational message and stops
157+
sending requests to the model. You must manually start a new session.
158+
- **Non-Interactive Mode:** The CLI exits with an error.

docs/get-started/configuration.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,12 @@ of v0.3.0:
882882
{
883883
"general": {
884884
"vimMode": true,
885-
"preferredEditor": "code"
885+
"preferredEditor": "code",
886+
"sessionRetention": {
887+
"enabled": true,
888+
"maxAge": "30d",
889+
"maxCount": 100
890+
}
886891
},
887892
"ui": {
888893
"theme": "GitHub",
@@ -1118,6 +1123,24 @@ for that specific session.
11181123
- Example: `gemini -e my-extension -e my-other-extension`
11191124
- **`--list-extensions`** (**`-l`**):
11201125
- Lists all available extensions and exits.
1126+
- **`--resume [session_id]`** (**`-r [session_id]`**):
1127+
- Resume a previous chat session. Use "latest" for the most recent session,
1128+
provide a session index number, or provide a full session UUID.
1129+
- If no session_id is provided, defaults to "latest".
1130+
- Example: `gemini --resume 5` or `gemini --resume latest` or
1131+
`gemini --resume a1b2c3d4-e5f6-7890-abcd-ef1234567890` or `gemini --resume`
1132+
- See [Session Management](../cli/session-management.md) for more details.
1133+
- **`--list-sessions`**:
1134+
- List all available chat sessions for the current project and exit.
1135+
- Shows session indices, dates, message counts, and preview of first user
1136+
message.
1137+
- Example: `gemini --list-sessions`
1138+
- **`--delete-session <identifier>`**:
1139+
- Delete a specific chat session by its index number or full session UUID.
1140+
- Use `--list-sessions` first to see available sessions, their indices, and
1141+
UUIDs.
1142+
- Example: `gemini --delete-session 3` or
1143+
`gemini --delete-session a1b2c3d4-e5f6-7890-abcd-ef1234567890`
11211144
- **`--include-directories <dir1,dir2,...>`**:
11221145
- Includes additional directories in the workspace for multi-directory
11231146
support.

docs/sidebar.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@
8484
"label": "Sandbox",
8585
"slug": "docs/cli/sandbox"
8686
},
87+
{
88+
"label": "Session Management",
89+
"slug": "docs/cli/session-management"
90+
},
8791
{
8892
"label": "Settings",
8993
"slug": "docs/cli/settings"

0 commit comments

Comments
 (0)