# Editors through ACP

> Use zelk as the agent in an editor that speaks the Agent Client Protocol, on standard input and output or on a socket many editors share.

`zelk acp` serves the [Agent Client Protocol](https://github.com/agentclientprotocol/agent-client-protocol)
(ACP), so an editor that supports ACP agents can use zelk as its agent:
your prompts, its streamed answers, tool calls, the plan, approvals and
questions all show in the editor.

## Add zelk to your editor

An editor starts its agent as a command and talks to it on standard input
and output. Register this command in your editor's settings for external
ACP agents, run in the project's directory:

```sh
zelk acp
```

Like print mode, `zelk acp` takes its provider from flags and variables,
not from the terminal UI's providers, so give it the same environment you
would give `zelk -p`:

```sh
ANTHROPIC_API_KEY=… zelk acp -provider anthropic -model claude-sonnet-5-5
```

In Zed, add zelk as a custom agent in `settings.json` (Agent Settings ›
External Agents › Add Custom Agent opens it), then pick **zelk** from the
new-thread menu:

```json title="~/.config/zed/settings.json"
{
  "agent_servers": {
    "zelk": {
      "type": "custom",
      "command": "zelk",
      "args": ["acp", "-provider", "anthropic", "-model", "claude-sonnet-5-5"],
      "env": {}
    }
  }
}
```

zelk gets the key from the environment Zed runs in, so start Zed from a
shell that has `ANTHROPIC_API_KEY` set, or name it in `env`; a key written
there sits in plain text in Zed's settings. Other editors take the same
command and arguments in their own settings for ACP agents.

It starts in `default` mode, so actions that aren't reads ask through the
editor. The editor's mode menu offers every mode the session allows.

## Options for editors

| Flag | Does |
|---|---|
| `-models MODEL` | another model the editor may switch to (repeatable) |
| `-client-fs` | read and write files through the editor when it offers to, so the agent sees unsaved buffers and its edits appear in them |
| `-client-terminal` | run commands in the editor's terminals when it offers them. They run outside zelk's sandbox |

Every flag the other hosts share works too: `-mode`, rules, `-sandbox`,
`-mcp-config` and the rest ([CLI reference](/reference/cli/#zelk-acp)). A
[managed policy](/cli/policy/) can turn `-client-terminal` off.

## What the editor gets

- **Sessions** are kept as the terminal UI keeps them. An editor can list
  this workspace's sessions, load one with its history, and fork one.
- **Commands.** A prompt of `/compact [focus]` compacts the conversation,
  `/status` shows the session's model, mode, run and background work, and
  `/name args` runs a skill.
- **Approvals** come as the editor's permission requests: allow once,
  always allow, or deny. Questions the agent asks come as forms, where the
  editor supports them.
- **Images** in a prompt reach models that take them.
- **MCP servers** the editor passes are connected for the session.

When the editor disconnects, `zelk acp` exits with it, and a run still
working is cancelled; what it did is in the session's log. An approval it
was waiting for stays pending, and the next client that loads the session
and prompts it is asked again. Under `-listen` (below), zelk outlives each
editor, so a run goes on when its editor leaves.

## One zelk for many editors

`-listen` serves any number of clients from one zelk, until you stop it.
Sessions then outlive the editor that started them: a session one client
started, another can load, and a run keeps going when its client leaves.

On a Unix socket only you can use:

```sh
zelk acp -listen unix:$XDG_RUNTIME_DIR/zelk-acp.sock
```

Editors start agents as commands, so give the editor this command instead
of `zelk acp`; it relays standard input and output to the socket:

```sh
zelk acp -connect unix:$XDG_RUNTIME_DIR/zelk-acp.sock
```

`-connect` takes no other flags. Give them to the serving zelk.

On Windows, use the same `unix:` prefix with a short NTFS path in an existing
private directory. The listener and relay verify that the peer runs as your
Windows user. For example, in PowerShell:

```powershell
zelk acp -listen "unix:$env:LOCALAPPDATA\zelk\acp.sock"
zelk acp -connect "unix:$env:LOCALAPPDATA\zelk\acp.sock"
```

Or on a WebSocket on this machine's loopback:

```sh
zelk acp -listen ws://127.0.0.1:7777
```

A WebSocket client connects to `/acp` and sends
`Authorization: Bearer TOKEN`, with the token from the file `-token-file`
names (default `acp-token` in the state directory, made with a random token
if missing). The token file uses private permissions, including a Windows DACL.
Only loopback hosts are accepted, and a request from a web page (one with an
`Origin`) is refused.

## Where to go deeper

- [The ACP contract](/internals/acp/): every method and how it maps onto zelk, the limitations, and zelk's extensions
- [`zelk acp`](/reference/cli/#zelk-acp) in the CLI reference
- [The `acp` package](/reference/go/acp/), to serve ACP from your own Go host
