text-threads.md

  1# Text Threads
  2
  3## Overview {#overview}
  4
  5Text threads in the [Agent Panel](./agent-panel.md) function similarly to any other editor.
  6You can use custom key bindings and work with multiple cursors, allowing for seamless transitions between coding and engaging in discussions with the language models.
  7
  8However, the text threads differ in the inclusion of message blocks.
  9These blocks serve as containers for text that correspond to different roles within the context.
 10These roles include:
 11
 12- `You`
 13- `Assistant`
 14- `System`
 15
 16To begin, type a message in a `You` block.
 17
 18![Asking a question](https://zed.dev/img/assistant/ask-a-question.png)
 19
 20As you type, the remaining tokens count for the selected model is updated.
 21
 22Inserting 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.
 23
 24![Quoting a selection](https://zed.dev/img/assistant/quoting-a-selection.png)
 25
 26To submit a message, use {#kb assistant::Assist}(`assistant: assist`).
 27Unlike normal threads, where pressing <kbd>enter</kbd> would submit the message, in text threads, our goal is to make it feel as close to a regular editor as possible.
 28So, pressing {#kb editor::Newline} simply inserts a new line.
 29
 30After submitting a message, the response will be streamed below, in an `Assistant` message block.
 31
 32![Receiving an answer](https://zed.dev/img/assistant/receiving-an-answer.png)
 33
 34The stream can be canceled at any point with <kbd>escape</kbd>.
 35This is useful if you realize early on that the response is not what you were looking for.
 36
 37If 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.
 38
 39Simple back-and-forth conversations work well with the text threads.
 40However, there may come a time when you want to modify the previous text in the conversation and steer it in a different direction.
 41
 42## Editing a Text Thread {#edit-text-thread}
 43
 44Text threads give you the flexibility to have control over the context.
 45You can freely edit any previous text, including the responses from the LLM.
 46If you want to remove a message block entirely, simply place your cursor at the beginning of the block and use the `delete` key.
 47A typical workflow might involve making edits and adjustments throughout the context to refine your inquiry or provide additional information.
 48Here's an example:
 49
 501. Write text in a `You` block.
 512. Submit the message with {#kb assistant::Assist}.
 523. Receive an `Assistant` response that doesn't meet your expectations.
 534. Cancel the response with <kbd>escape</kbd>.
 545. Erase the content of the `Assistant` message block and remove the block entirely.
 556. Add additional context to your original message.
 567. Submit the message with {#kb assistant::Assist}.
 57
 58Being able to edit previous messages gives you control over how tokens are used.
 59You 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.
 60
 61> **Note**: The act of editing past messages is often referred to as "Rewriting History" in the context of the language models.
 62
 63Some additional points to keep in mind:
 64
 65- 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.
 66
 67## Commands Overview {#commands}
 68
 69Slash commands enhance the assistant's capabilities.
 70Begin by typing a `/` at the beginning of the line to see a list of available commands:
 71
 72- `/default`: Inserts the default rule
 73- `/diagnostics`: Injects errors reported by the project's language server
 74- `/fetch`: Fetches the content of a webpage and inserts it
 75- `/file`: Inserts a single file or a directory of files
 76- `/now`: Inserts the current date and time
 77- `/prompt`: Adds a custom-configured prompt to the context ([see Rules Library](./rules.md#rules-library))
 78- `/symbols`: Inserts the current tab's active symbols
 79- `/tab`: Inserts the content of the active tab or all open tabs
 80- `/terminal`: Inserts a select number of lines of output from the terminal
 81- `/selection`: Inserts the selected text
 82
 83> **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.
 84
 85### `/default`
 86
 87Read more about `/default` in the [Rules: Editing the Default Rules](./rules.md#default-rules) section.
 88
 89Usage: `/default`
 90
 91### `/diagnostics`
 92
 93The `/diagnostics` command injects errors reported by the project's language server into the context.
 94This is useful for getting an overview of current issues in your project.
 95
 96Usage: `/diagnostics [--include-warnings] [path]`
 97
 98- `--include-warnings`: Optional flag to include warnings in addition to errors.
 99- `path`: Optional path to limit diagnostics to a specific file or directory.
100
101### `/file`
102
103The `/file` command inserts the content of a single file or a directory of files into the context.
104This allows you to reference specific parts of your project in your conversation with the assistant.
105
106Usage: `/file <path>`
107
108You can use glob patterns to match multiple files or directories.
109
110Examples:
111
112- `/file src/index.js` - Inserts the content of `src/index.js` into the context.
113- `/file src/*.js` - Inserts the content of all `.js` files in the `src` directory.
114- `/file src` - Inserts the content of all files in the `src` directory.
115
116### `/now`
117
118The `/now` command inserts the current date and time into the context.
119This can be useful for letting the language model know the current time (and by extension, how old their current knowledge base is).
120
121Usage: `/now`
122
123### `/prompt`
124
125The `/prompt` command inserts a prompt from the prompt library into the context.
126It can also be used to nest prompts within prompts.
127
128Usage: `/prompt <prompt_name>`
129
130Related: `/default`
131
132### `/symbols`
133
134The `/symbols` command inserts the active symbols (functions, classes, etc.) from the current tab into the context.
135This is useful for getting an overview of the structure of the current file.
136
137Usage: `/symbols`
138
139### `/tab`
140
141The `/tab` command inserts the content of the active tab or all open tabs into the context.
142This allows you to reference the content you're currently working on.
143
144Usage: `/tab [tab_name|all]`
145
146- `tab_name`: Optional name of a specific tab to insert.
147- `all`: Insert content from all open tabs.
148
149Examples:
150
151- `/tab` - Inserts the content of the active tab.
152- `/tab "index.js"` - Inserts the content of the tab named "index.js".
153- `/tab all` - Inserts the content of all open tabs.
154
155### `/terminal`
156
157The `/terminal` command inserts a select number of lines of output from the terminal into the context.
158This is useful for referencing recent command outputs or logs.
159
160Usage: `/terminal [<number>]`
161
162- `<number>`: Optional parameter to specify the number of lines to insert (default is 50).
163
164### `/selection`
165
166The `/selection` command inserts the selected text in the editor into the context.
167This is useful for referencing specific parts of your code.
168
169This is equivalent to the `agent: add selection to thread` command ({#kb agent::AddSelectionToThread}).
170
171Usage: `/selection`
172
173## Commands in the Rules Library {#slash-commands-in-rules}
174
175[Commands](#commands) can be used in rules, in the Rules Library (previously known as Prompt Library), to insert dynamic content or perform actions.
176For 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.
177
178> **Warn:** Slash commands in rules **only** work when they are used in text threads. Using them in non-text threads is not supported.
179
180> **Note:** Slash commands in rules **must** be on their own line.
181
182See the [list of commands](#commands) above for more information on commands, and what slash commands are available.
183
184### Example
185
186```plaintext
187You are an expert Rust engineer. The user has asked you to review their project and answer some questions.
188
189Here is some information about their project:
190
191/file Cargo.toml
192```
193
194In 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.
195
196## Nesting Rules
197
198Similar to adding rules to the default rules, you can nest rules within other rules with the `/prompt` command (only supported in Text Threads currently).
199
200You might want to nest rules to:
201
202- Create templates on the fly
203- Break collections like docs or references into smaller, mix-and-matchable parts
204- Create variants of a similar rule (e.g., `Async Rust - Tokio` vs. `Async Rust - Async-std`)
205
206### Example
207
208```plaintext
209Title: Zed-Flavored Rust
210
211## About Zed
212
213/prompt Zed: Zed (a rule about what Zed is)
214
215## Rust - Zed Style
216
217/prompt Rust: Async - Async-std (zed doesn't use tokio)
218/prompt Rust: Zed-style Crates (we have some unique conventions)
219/prompt Rust - Workspace deps (bias towards reusing deps from the workspace)
220```
221
222_The text in parentheses above are comments and are not part of the rule._
223
224> **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!
225
226By using nested rules, you can create modular and reusable rule components that can be combined in various ways to suit different scenarios.
227
228> **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.
229
230## Extensibility
231
232Additional slash commands can be provided by extensions.
233
234See [Extension: Slash Commands](../extensions/slash-commands.md) to learn how to create your own.
235
236## Text Threads vs. Threads
237
238For a while, text threads were the only way to interact with AI in Zed.
239We have since introduced, back in May 2025, a new take on the agent panel, which, as opposed to being editor-driven, optimizes for readability.
240You can read more about it in [the Agent Panel page](./agent-panel.md).
241
242However, aside from many interaction differences, the major difference between one vs. the other is that tool calls don't work in Text Threads.
243So, it's accurate to say that Text Threads aren't necessarily "agentic", as they can't perform any action on your behalf.
244Think of it more like a regular and "traditional" AI chat, where what you'll get out of the model is simply just text.
245Consequently, [external agents](./external-agents.md) are also not available in Text Threads.
246
247## Advanced Concepts
248
249### Rule Templates {#rule-templates}
250
251Zed uses rule templates to power internal assistant features, like the terminal assistant, or the content rules used in the inline assistant.
252
253Zed has the following internal rule templates:
254
255- `content_prompt.hbs`: Used for generating content in the editor.
256- `terminal_assistant_prompt.hbs`: Used for the terminal assistant feature.
257
258At this point it is unknown if we will expand templates further to be user-creatable.
259
260### Overriding Templates
261
262> **Note:** It is not recommended to override templates unless you know what you are doing. Editing templates will break your assistant if done incorrectly.
263
264Zed 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.
265
266The following templates can be overridden:
267
2681. [`content_prompt.hbs`](https://github.com/zed-industries/zed/tree/main/assets/prompts/content_prompt.hbs): Used for generating content in the editor.
269
2702. [`terminal_assistant_prompt.hbs`](https://github.com/zed-industries/zed/tree/main/assets/prompts/terminal_assistant_prompt.hbs): Used for the terminal assistant feature.
271
272> **Note:** Be sure you want to override these, as you'll miss out on iteration on our built-in features.
273> This should be primarily used when developing Zed.
274
275You can customize these templates to better suit your needs while maintaining the core structure and variables used by Zed.
276Zed will automatically reload your prompt overrides when they change on disk.
277
278Consult Zed's [assets/prompts](https://github.com/zed-industries/zed/tree/main/assets/prompts) directory for current versions you can play with.
279
280### History {#history}
281
282After 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
283
284- `~/.config/zed/conversations` (macOS)
285- `~/.local/share/zed/conversations` (Linux)
286- `%LocalAppData%\Zed\conversations` (Windows)
287
288You can access and load previous contexts by clicking on the history button in the top-left corner of the agent panel.
289
290![Viewing assistant history](https://zed.dev/img/assistant/assistant-history.png)