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) is also included by default, and you can [add custom ACP-compatible agents](#add-custom-agents) as well.
7
8## Gemini CLI {#gemini-cli}
9
10Zed provides the ability to run [Gemini CLI](https://github.com/google-gemini/gemini-cli) directly in the [agent panel](./agent-panel.md).
11
12Under the hood we run Gemini CLI in the background, and talk to it over ACP.
13This 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.
14
15### Getting Started
16
17As 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.
18
19If 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:
20
21```json
22[
23 {
24 "bindings": {
25 "cmd-alt-g": ["agent::NewExternalAgentThread", { "agent": "gemini" }]
26 }
27 }
28]
29```
30
31#### Installation
32
33If you don't yet have Gemini CLI installed, then Zed will install a version for you. If you do, then we will use the version of Gemini CLI on your path.
34
35You need to be running at least Gemini version `0.2.0`, and if your version of Gemini is too old you will see an
36error message.
37
38The instructions to upgrade Gemini depend on how you originally installed it, but typically, running `npm install -g @google/gemini-cli@latest` should work.
39
40#### Authentication
41
42After you have Gemini CLI running, you'll be prompted to choose your authentication method.
43
44Most 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.
45
46You 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.
47
48The "Vertex AI" option is for those who are using [Vertex AI](https://cloud.google.com/vertex-ai), and have already configured their environment correctly.
49
50For more information, see the [Gemini CLI docs](https://github.com/google-gemini/gemini-cli/blob/main/docs/index.md).
51
52### Usage
53
54Similar to Zed's first-party agent, you can use Gemini CLI to do anything that you need.
55And to give it context, you can @-mention files, recent threads, symbols, or fetch the web.
56
57> Note that some first-party agent features don't yet work with Gemini CLI: editing past messages, resuming threads from history, checkpointing, and using the agent in SSH projects.
58> We hope to add these features in the near future.
59
60## Claude Code
61
62Similar to Gemini CLI, you can also run [Claude Code](https://www.anthropic.com/claude-code) directly via Zed's [agent panel](./agent-panel.md).
63Under the hood, Zed runs Claude Code and communicate to it over ACP, through [a dedicated adapter](https://github.com/zed-industries/claude-code-acp).
64
65### Getting Started
66
67Open the agent panel with {#kb agent::ToggleFocus}, and then use the `+` button in the top right to start a new Claude Code thread.
68
69If 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:
70
71```json
72[
73 {
74 "bindings": {
75 "cmd-alt-c": ["agent::NewExternalAgentThread", { "agent": "claude_code" }]
76 }
77 }
78]
79```
80
81#### Installation
82
83If you don't yet have Claude Code installed, then Zed will install a version for you.
84If you do, then we will use the version of Claude Code on your path.
85
86### Usage
87
88Similar to Zed's first-party agent, you can use Claude Code to do anything that you need.
89And to give it context, you can @-mention files, recent threads, symbols, or fetch the web.
90
91In 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.
92However, the SDK doesn't yet expose everything needed to fully support all of them:
93
94- 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.
95- [Subagents](https://docs.anthropic.com/en/docs/claude-code/sub-agents) are supported.
96- [Hooks](https://docs.anthropic.com/en/docs/claude-code/hooks-guide) are currently _not_ supported.
97
98> 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, checkpointing, and using the agent in SSH projects.
99> We hope to add these features in the near future.
100
101#### CLAUDE.md
102
103Claude Code in Zed will automatically use any `CLAUDE.md` file found in your project root, project subdirectories, or root `.claude` directory.
104
105If you don't have a `CLAUDE.md` file, you can ask Claude Code to create one for you through the `init` slash command.
106
107## Add Custom Agents {#add-custom-agents}
108
109You can run any agent speaking ACP in Zed by changing your settings as follows:
110
111```json
112{
113 "agent_servers": {
114 "Custom Agent": {
115 "command": "node",
116 "args": ["~/projects/agent/index.js", "--acp"],
117 "env": {}
118 }
119 }
120}
121```
122
123This 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.
124
125## Debugging Agents
126
127When 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.
128
129