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