1# External Agents
  2
  3Zed supports terminal-based agents through the [Agent Client Protocol (ACP)](https://agentclientprotocol.com).
  4
  5Currently, [Gemini CLI](https://github.com/google-gemini/gemini-cli) serves as the reference implementation.
  6[Claude Code](https://www.anthropic.com/claude-code) and [Codex](https://developers.openai.com/codex) are also included by default, and you can [add custom ACP-compatible agents](#add-custom-agents) as well.
  7
  8> Note that Zed's affordance for external agents is strictly UI-based; the billing and legal/terms arrangement is directly between you and the agent provider.
  9> Zed does not charge for use of external agents, and our [zero-data retention agreements/privacy guarantees](./ai-improvement.md) are **_only_** applicable for Zed's hosted models.
 10
 11## Gemini CLI {#gemini-cli}
 12
 13Zed provides the ability to run [Gemini CLI](https://github.com/google-gemini/gemini-cli) directly in the [agent panel](./agent-panel.md).
 14
 15Under the hood we run Gemini CLI in the background, and talk to it over ACP.
 16This means that you're running the real Gemini CLI, with all of the advantages of that, but you can see and interact with files in your editor.
 17
 18### Getting Started
 19
 20As of [Zed Stable v0.201.5](https://zed.dev/releases/stable/0.201.5) you should be able to use Gemini CLI directly from Zed. First open the agent panel with {#kb agent::ToggleFocus}, and then use the `+` button in the top right to start a new Gemini CLI thread.
 21
 22If you'd like to bind this to a keyboard shortcut, you can do so by editing your `keymap.json` file via the `zed: open keymap` command to include:
 23
 24```json [keymap]
 25[
 26  {
 27    "bindings": {
 28      "cmd-alt-g": ["agent::NewExternalAgentThread", { "agent": "gemini" }]
 29    }
 30  }
 31]
 32```
 33
 34#### Installation
 35
 36The first time you create a Gemini CLI thread, Zed will install [@google/gemini-cli](https://github.com/zed-industries/claude-code-acp). This installation is only available to Zed and is kept up to date as you use the agent.
 37
 38By default, Zed will use this managed version of Gemini CLI even if you have it installed globally. However, you can configure it to use a version in your `PATH` by adding this to your settings:
 39
 40```json [settings]
 41{
 42  "agent_servers": {
 43    "gemini": {
 44      "ignore_system_version": false
 45    }
 46  }
 47}
 48```
 49
 50#### Authentication
 51
 52After you have Gemini CLI running, you'll be prompted to choose your authentication method.
 53
 54Most users should click the "Log in with Google". This will cause a browser window to pop-up and auth directly with Gemini CLI. Zed does not see your OAuth or access tokens in this case.
 55
 56You can also use the "Gemini API Key". If you select this, and have the `GEMINI_API_KEY` set, then we will use that. Otherwise Zed will prompt you for an API key which will be stored securely in your keychain, and used to start Gemini CLI from within Zed.
 57
 58The "Vertex AI" option is for those who are using [Vertex AI](https://cloud.google.com/vertex-ai), and have already configured their environment correctly.
 59
 60For more information, see the [Gemini CLI docs](https://github.com/google-gemini/gemini-cli/blob/main/docs/index.md).
 61
 62### Usage
 63
 64Similar to Zed's first-party agent, you can use Gemini CLI to do anything that you need.
 65And to give it context, you can @-mention files, recent threads, symbols, or fetch the web.
 66
 67> Note that some first-party agent features don't yet work with Gemini CLI: editing past messages, resuming threads from history, and checkpointing.
 68> We hope to add these features in the near future.
 69
 70## Claude Code
 71
 72Similar to Gemini CLI, you can also run [Claude Code](https://www.anthropic.com/claude-code) directly via Zed's [agent panel](./agent-panel.md).
 73Under the hood, Zed runs Claude Code and communicate to it over ACP, through [a dedicated adapter](https://github.com/zed-industries/claude-code-acp).
 74
 75### Getting Started
 76
 77Open the agent panel with {#kb agent::ToggleFocus}, and then use the `+` button in the top right to start a new Claude Code thread.
 78
 79If you'd like to bind this to a keyboard shortcut, you can do so by editing your `keymap.json` file via the `zed: open keymap` command to include:
 80
 81```json [keymap]
 82[
 83  {
 84    "bindings": {
 85      "cmd-alt-c": ["agent::NewExternalAgentThread", { "agent": "claude_code" }]
 86    }
 87  }
 88]
 89```
 90
 91### Authentication
 92
 93As of version `0.202.7` (stable) and `0.203.2` (preview), authentication to Zed's Claude Code installation is decoupled entirely from Zed's agent. That is to say, an Anthropic API key added via the [Zed Agent's settings](./llm-providers.md#anthropic) will _not_ be utilized by Claude Code for authentication and billing.
 94
 95To ensure you're using your billing method of choice, [open a new Claude Code thread](./agent-panel.md#new-thread). Then, run `/login`, and authenticate either via API key, or via `Log in with Claude Code` to use a Claude Pro/Max subscription.
 96
 97#### Installation
 98
 99The first time you create a Claude Code thread, Zed will install [@zed-industries/claude-code-acp](https://github.com/zed-industries/claude-code-acp). This installation is only available to Zed and is kept up to date as you use the agent.
100
101Zed will always use this managed version of the Claude Code adapter, which includes a vendored version of the Claude Code CLI, even if you have it installed globally.
102
103If you want to override the executable used by the adapter, you can set the `CLAUDE_CODE_EXECUTABLE` environment variable in your settings to the path of your preferred executable.
104
105```json
106{
107  "agent_servers": {
108    "claude": {
109      "env": {
110        "CLAUDE_CODE_EXECUTABLE": "/path/to/alternate-claude-code-executable"
111      }
112    }
113  }
114}
115```
116
117### Usage
118
119Similar to Zed's first-party agent, you can use Claude Code to do anything that you need.
120And to give it context, you can @-mention files, recent threads, symbols, or fetch the web.
121
122In complement to talking to it [over ACP](https://agentclientprotocol.com), Zed relies on the [Claude Code SDK](https://docs.anthropic.com/en/docs/claude-code/sdk/sdk-overview) to support some of its specific features.
123However, the SDK doesn't yet expose everything needed to fully support all of them:
124
125- Slash Commands: A subset of [built-in commands](https://docs.anthropic.com/en/docs/claude-code/slash-commands#built-in-slash-commands) are supported, while [custom slash commands](https://docs.anthropic.com/en/docs/claude-code/slash-commands#custom-slash-commands) are fully supported.
126- [Subagents](https://docs.anthropic.com/en/docs/claude-code/sub-agents) are supported.
127- [Hooks](https://docs.anthropic.com/en/docs/claude-code/hooks-guide) are currently _not_ supported.
128
129> Also note that some [first-party agent](./agent-panel.md) features don't yet work with Claude Code: editing past messages, resuming threads from history, and checkpointing.
130> We hope to add these features in the near future.
131
132#### CLAUDE.md
133
134Claude Code in Zed will automatically use any `CLAUDE.md` file found in your project root, project subdirectories, or root `.claude` directory.
135
136If you don't have a `CLAUDE.md` file, you can ask Claude Code to create one for you through the `init` slash command.
137
138## Codex CLI
139
140You can also run [Codex CLI](https://github.com/openai/codex) directly via Zed's [agent panel](./agent-panel.md).
141Under the hood, Zed runs Codex CLI and communicates to it over ACP, through [a dedicated adapter](https://github.com/zed-industries/codex-acp).
142
143### Getting Started
144
145As of Zed Stable v0.208 you should be able to use Codex directly from Zed. Open the agent panel with {#kb agent::ToggleFocus}, and then use the `+` button in the top right to start a new Codex thread.
146
147If you'd like to bind this to a keyboard shortcut, you can do so by editing your `keymap.json` file via the `zed: open keymap` command to include:
148
149```json
150[
151  {
152    "bindings": {
153      "cmd-alt-c": ["agent::NewExternalAgentThread", { "agent": "codex" }]
154    }
155  }
156]
157```
158
159### Authentication
160
161Authentication to Zed's Codex installation is decoupled entirely from Zed's agent. That is to say, an OpenAI API key added via the [Zed Agent's settings](./llm-providers.md#openai) will _not_ be utilized by Codex for authentication and billing.
162
163To ensure you're using your billing method of choice, [open a new Codex thread](./agent-panel.md#new-thread). The first time you will be prompted to authenticate with one of three methods:
164
1651. Login with ChatGPT - allows you to use your existing, paid ChatGPT subscription. _Note: This method isn't currently supported in remote projects_
1662. `CODEX_API_KEY` - uses an API key you have set in your environment under the variable `CODEX_API_KEY`.
1673. `OPENAI_API_KEY` - uses an API key you have set in your environment under the variable `OPENAI_API_KEY`.
168
169If you are already logged in and want to change your authentication method, type `/logout` in the thread and authenticate again.
170
171#### Installation
172
173The first time you create a Codex thread, Zed will install [codex-acp](https://github.com/zed-industries/codex-acp). This installation is only available to Zed and is kept up to date as you use the agent.
174
175Zed will always use this managed version of Codex even if you have it installed globally.
176
177### Usage
178
179Similar to Zed's first-party agent, you can use Codex to do anything that you need.
180And to give it context, you can @-mention files, symbols, or fetch the web.
181
182> Note that some first-party agent features don't yet work with Codex: editing past messages, resuming threads from history, and checkpointing.
183> We hope to add these features in the near future.
184
185## Add Custom Agents {#add-custom-agents}
186
187You can run any agent speaking ACP in Zed by changing your settings as follows:
188
189```json [settings]
190{
191  "agent_servers": {
192    "Custom Agent": {
193      "command": "node",
194      "args": ["~/projects/agent/index.js", "--acp"],
195      "env": {}
196    }
197  }
198}
199```
200
201This can also be useful if you're in the middle of developing a new agent that speaks the protocol and you want to debug it.
202
203You can also specify a custom path, arguments, or environment for the builtin integrations by using the `claude` and `gemini` names.
204
205## Debugging Agents
206
207When using external agents in Zed, you can access the debug view via with `dev: open acp logs` from the Command Palette. This lets you see the messages being sent and received between Zed and the agent.
208
209
210
211## MCP Servers
212
213Note that for external agents, access to MCP servers [installed from Zed](./mcp.md) may vary depending on the ACP agent implementation.
214
215Regarding the built-in ones, Claude Code and Codex both support it, and Gemini CLI does not yet.
216In the meantime, learn how to add MCP server support to Gemini CLI through [their documentation](https://github.com/google-gemini/gemini-cli?tab=readme-ov-file#using-mcp-servers).