text-threads.md

  1---
  2title: AI Chat in Your Editor - Zed Text Threads
  3description: Chat with LLMs directly in your editor with Zed's text threads. Full control over context, message roles, and slash commands.
  4---
  5
  6# Text Threads
  7
  8## Overview {#overview}
  9
 10Text threads in the [Agent Panel](./agent-panel.md) work like a regular editor. You can use custom keybindings, multiple cursors, and all standard editing features.
 11
 12Text threads organize content into message blocks with roles:
 13
 14- `You`
 15- `Assistant`
 16- `System`
 17
 18To begin, type a message in a `You` block.
 19
 20![Asking a question](https://zed.dev/img/assistant/ask-a-question.png)
 21
 22As you type, the remaining tokens count for the selected model is updated.
 23
 24Inserting text from an editor is as simple as highlighting the text and running `agent: add selection to thread` ({#kb agent::AddSelectionToThread}); Zed will wrap it in a fenced code block if it is code.
 25
 26![Quoting a selection](https://zed.dev/img/assistant/quoting-a-selection.png)
 27
 28To submit a message, use {#kb assistant::Assist}(`assistant: assist`).
 29In text threads, {#kb editor::Newline} inserts a new line rather than submitting. This preserves standard editor behavior.
 30
 31After submitting a message, the response will be streamed below, in an `Assistant` message block.
 32
 33![Receiving an answer](https://zed.dev/img/assistant/receiving-an-answer.png)
 34
 35The stream can be canceled at any point with <kbd>escape</kbd>.
 36This is useful if you realize early on that the response is not what you were looking for.
 37
 38If you want to start a new conversation at any time, you can hit <kbd>cmd-n|ctrl-n</kbd> or use the `New Chat` menu option in the hamburger menu at the top left of the panel.
 39
 40Text threads support straightforward conversations, but you can also go back and modify earlier messages to change direction.
 41
 42## Editing a Text Thread {#edit-text-thread}
 43
 44You can edit any text in a thread, including previous LLM responses.
 45If you want to remove a message block entirely, simply place your cursor at the beginning of the block and use the `delete` key.
 46A typical workflow might involve making edits and adjustments throughout the context to refine your inquiry or provide additional information.
 47Here's an example:
 48
 491. Write text in a `You` block.
 502. Submit the message with {#kb assistant::Assist}.
 513. Receive an `Assistant` response that doesn't meet your expectations.
 524. Cancel the response with <kbd>escape</kbd>.
 535. Erase the content of the `Assistant` message block and remove the block entirely.
 546. Add additional context to your original message.
 557. Submit the message with {#kb assistant::Assist}.
 56
 57Being able to edit previous messages gives you control over how tokens are used.
 58You don't need to start up a new chat to correct a mistake or to add additional information, and you don't have to waste tokens by submitting follow-up corrections.
 59
 60> **Note**: The act of editing past messages is often referred to as "Rewriting History" in the context of the language models.
 61
 62Some additional points to keep in mind:
 63
 64- You can cycle the role of a message block by clicking on the role, which is useful when you receive a response in an `Assistant` block that you want to edit and send back up as a `You` block.
 65
 66## Commands Overview {#commands}
 67
 68Type `/` at the beginning of a line to see available slash commands:
 69
 70- `/default`: Inserts the default rule
 71- `/diagnostics`: Injects errors reported by the project's language server
 72- `/fetch`: Fetches the content of a webpage and inserts it
 73- `/file`: Inserts a single file or a directory of files
 74- `/now`: Inserts the current date and time
 75- `/prompt`: Adds a custom-configured prompt to the context ([see Rules Library](./rules.md#rules-library))
 76- `/symbols`: Inserts the current tab's active symbols
 77- `/tab`: Inserts the content of the active tab or all open tabs
 78- `/terminal`: Inserts a select number of lines of output from the terminal
 79- `/selection`: Inserts the selected text
 80
 81> **Note:** Remember, commands are only evaluated when the text thread is created or when the command is inserted, so a command like `/now` won't continuously update, or `/file` commands won't keep their contents up to date.
 82
 83### `/default`
 84
 85Read more about `/default` in the [Rules: Editing the Default Rules](./rules.md#default-rules) section.
 86
 87Usage: `/default`
 88
 89### `/diagnostics`
 90
 91Injects errors reported by the project's language server into the context.
 92
 93Usage: `/diagnostics [--include-warnings] [path]`
 94
 95- `--include-warnings`: Optional flag to include warnings in addition to errors.
 96- `path`: Optional path to limit diagnostics to a specific file or directory.
 97
 98### `/file`
 99
100Inserts the content of a file or directory into the context. Supports glob patterns.
101
102Usage: `/file <path>`
103
104Examples:
105
106- `/file src/index.js` - Inserts the content of `src/index.js` into the context.
107- `/file src/*.js` - Inserts the content of all `.js` files in the `src` directory.
108- `/file src` - Inserts the content of all files in the `src` directory.
109
110### `/now`
111
112Inserts the current date and time. Useful for informing the model about its knowledge cutoff relative to now.
113
114Usage: `/now`
115
116### `/prompt`
117
118Inserts a rule from the Rules Library into the context. Rules can nest other rules.
119
120Usage: `/prompt <prompt_name>`
121
122Related: `/default`
123
124### `/symbols`
125
126Inserts the active symbols (functions, classes, etc.) from the current tab, providing a structural overview of the file.
127
128Usage: `/symbols`
129
130### `/tab`
131
132Inserts the content of the active tab or all open tabs.
133
134Usage: `/tab [tab_name|all]`
135
136- `tab_name`: Optional name of a specific tab to insert.
137- `all`: Insert content from all open tabs.
138
139Examples:
140
141- `/tab` - Inserts the content of the active tab.
142- `/tab "index.js"` - Inserts the content of the tab named "index.js".
143- `/tab all` - Inserts the content of all open tabs.
144
145### `/terminal`
146
147Inserts recent terminal output (default: 50 lines).
148
149Usage: `/terminal [<number>]`
150
151- `<number>`: Optional parameter to specify the number of lines to insert (default is 50).
152
153### `/selection`
154
155Inserts the currently selected text. Equivalent to `agent: add selection to thread` ({#kb agent::AddSelectionToThread}).
156
157Usage: `/selection`
158
159## Commands in the Rules Library {#slash-commands-in-rules}
160
161[Commands](#commands) can be used in rules, in the Rules Library (previously known as Prompt Library), to insert dynamic content or perform actions.
162For example, if you want to create a rule where it is important for the model to know the date, you can use the `/now` command to insert the current date.
163
164> **Warn:** Slash commands in rules **only** work when they are used in text threads. Using them in non-text threads is not supported.
165
166> **Note:** Slash commands in rules **must** be on their own line.
167
168See the [list of commands](#commands) above for more information on commands, and what slash commands are available.
169
170### Example
171
172```plaintext
173You are an expert Rust engineer. The user has asked you to review their project and answer some questions.
174
175Here is some information about their project:
176
177/file Cargo.toml
178```
179
180In the above example, the `/file` command is used to insert the contents of the `Cargo.toml` file (or all `Cargo.toml` files present in the project) into the rule.
181
182## Nesting Rules
183
184Similar to adding rules to the default rules, you can nest rules within other rules with the `/prompt` command (only supported in Text Threads currently).
185
186You might want to nest rules to:
187
188- Create templates on the fly
189- Break collections like docs or references into smaller, mix-and-matchable parts
190- Create variants of a similar rule (e.g., `Async Rust - Tokio` vs. `Async Rust - Async-std`)
191
192### Example
193
194```plaintext
195Title: Zed-Flavored Rust
196
197## About Zed
198
199/prompt Zed: Zed (a rule about what Zed is)
200
201## Rust - Zed Style
202
203/prompt Rust: Async - Async-std (zed doesn't use tokio)
204/prompt Rust: Zed-style Crates (we have some unique conventions)
205/prompt Rust - Workspace deps (bias towards reusing deps from the workspace)
206```
207
208_The text in parentheses above are comments and are not part of the rule._
209
210> **Note:** While you technically _can_ nest a rule within itself, we wouldn't recommend it (in the strongest of terms.) Use at your own risk!
211
212By using nested rules, you can create modular and reusable rule components that can be combined in various ways to suit different scenarios.
213
214> **Note:** When using slash commands to bring in additional context, the injected content can be edited directly inline in the text thread—edits here will not propagate to the saved rules.
215
216## Extensibility
217
218Additional slash commands can be provided by extensions.
219
220See [Extension: Slash Commands](../extensions/slash-commands.md) to learn how to create your own.
221
222## Text Threads vs. Threads
223
224Text threads were Zed's original AI interface. In May 2025, Zed introduced the current [Agent Panel](./agent-panel.md), optimized for readability and agentic workflows.
225
226The key difference: text threads don't support tool calls. They can't read files, write code, or run commands on your behalf. Text threads are for conversational interaction where you only receive text responses.
227
228[MCP servers](./mcp.md) and [external agents](./external-agents.md) are not available in text threads.
229
230## Advanced Concepts
231
232### Rule Templates {#rule-templates}
233
234Zed uses rule templates to power internal assistant features, like the terminal assistant, or the content rules used in the inline assistant.
235
236Zed has the following internal rule templates:
237
238- `content_prompt.hbs`: Used for generating content in the editor.
239- `terminal_assistant_prompt.hbs`: Used for the terminal assistant feature.
240
241At this point it is unknown if we will expand templates further to be user-creatable.
242
243### Overriding Templates
244
245> **Note:** It is not recommended to override templates unless you know what you are doing. Editing templates will break your assistant if done incorrectly.
246
247Zed allows you to override the default rules used for various assistant features by placing custom Handlebars (.hbs) templates in your `~/.config/zed/prompt_overrides` directory.
248
249The following templates can be overridden:
250
2511. [`content_prompt.hbs`](https://github.com/zed-industries/zed/tree/main/assets/prompts/content_prompt.hbs): Used for generating content in the editor.
252
2532. [`terminal_assistant_prompt.hbs`](https://github.com/zed-industries/zed/tree/main/assets/prompts/terminal_assistant_prompt.hbs): Used for the terminal assistant feature.
254
255> **Note:** Be sure you want to override these, as you'll miss out on iteration on our built-in features.
256> This should be primarily used when developing Zed.
257
258You can customize these templates to better suit your needs while maintaining the core structure and variables used by Zed.
259Zed will automatically reload your prompt overrides when they change on disk.
260
261Consult Zed's [assets/prompts](https://github.com/zed-industries/zed/tree/main/assets/prompts) directory for current versions you can play with.
262
263### History {#history}
264
265After you submit your first message in a text thread, a name for your context is generated by the language model, and the context is automatically saved to your file system in
266
267- `~/.config/zed/conversations` (macOS)
268- `~/.local/share/zed/conversations` (Linux)
269- `%LocalAppData%\Zed\conversations` (Windows)
270
271You can access and load previous contexts by clicking on the history button in the top-left corner of the agent panel.
272
273![Viewing assistant history](https://zed.dev/img/assistant/assistant-history.png)