1---
2title: CLI Reference
3description: "Reference for Zed's command-line interface (CLI), including opening files and directories, integrating with tools, and controlling Zed from scripts."
4---
5
6# CLI Reference
7
8Use Zed's command-line interface (CLI) to open files and directories, integrate with other tools, and control Zed from scripts.
9
10## Installation
11
12**macOS:** Run the `cli: install` command from the command palette ({#kb command_palette::Toggle}) to install the `zed` CLI to `/usr/local/bin/zed`.
13
14**Linux:** The CLI is included with Zed packages. The binary name may vary by distribution (commonly `zed` or `zeditor`).
15
16**Windows:** The CLI is included with Zed. Add Zed's installation directory to your PATH, or use the full path to `zed.exe`.
17
18## Usage
19
20```sh
21zed [OPTIONS] [PATHS]...
22```
23
24## Opening Files and Directories
25
26Open a file:
27
28```sh
29zed myfile.txt
30```
31
32Open a directory as a workspace:
33
34```sh
35zed ~/projects/myproject
36```
37
38Open multiple files or directories:
39
40```sh
41zed file1.txt file2.txt ~/projects/myproject
42```
43
44Open a file at a specific line and column:
45
46```sh
47zed myfile.txt:42 # Open at line 42
48zed myfile.txt:42:10 # Open at line 42, column 10
49```
50
51## Options
52
53### `-w`, `--wait`
54
55Wait for all opened files to be closed before the CLI exits. When opening a directory, waits until the window is closed.
56
57This is useful for integrating Zed with tools that expect an editor to block until editing is complete (e.g., `git commit`):
58
59```sh
60export EDITOR="zed --wait"
61git commit # Opens Zed and waits for you to close the commit message file
62```
63
64### `-n`, `--new`
65
66Open paths in a new workspace window, even if the paths are already open in an existing window:
67
68```sh
69zed -n ~/projects/myproject
70```
71
72### `-a`, `--add`
73
74> **Changed in Preview (v0.225).** See [release notes](/releases#0.225).
75
76Add paths to the currently focused workspace instead of opening a new window. When multiple workspace windows are open, files open in the focused window:
77
78```sh
79zed -a newfile.txt
80```
81
82### `-r`, `--reuse`
83
84Reuse an existing window, replacing its current workspace with the new paths:
85
86```sh
87zed -r ~/projects/different-project
88```
89
90### `--diff <OLD_PATH> <NEW_PATH>`
91
92Open a diff view comparing two files. Can be specified multiple times:
93
94```sh
95zed --diff file1.txt file2.txt
96zed --diff old.rs new.rs --diff old2.rs new2.rs
97```
98
99### `--foreground`
100
101Run Zed in the foreground, keeping the terminal attached. Useful for debugging:
102
103```sh
104zed --foreground
105```
106
107### `--user-data-dir <DIR>`
108
109Use a custom directory for all user data (database, extensions, logs) instead of the default location:
110
111```sh
112zed --user-data-dir ~/.zed-custom
113```
114
115Default locations:
116
117- **macOS:** `~/Library/Application Support/Zed`
118- **Linux:** `$XDG_DATA_HOME/zed` (typically `~/.local/share/zed`)
119- **Windows:** `%LOCALAPPDATA%\Zed`
120
121### `-v`, `--version`
122
123Print Zed's version and exit:
124
125```sh
126zed --version
127```
128
129### `--uninstall`
130
131Uninstall Zed and remove all related files (macOS and Linux only):
132
133```sh
134zed --uninstall
135```
136
137### `--zed <PATH>`
138
139Specify a custom path to the Zed application or binary:
140
141```sh
142zed --zed /path/to/Zed.app myfile.txt
143```
144
145## Reading from Standard Input
146
147Read content from stdin by passing `-` as the path:
148
149```sh
150echo "Hello, World!" | zed -
151cat myfile.txt | zed -
152ps aux | zed -
153```
154
155This creates a temporary file with the stdin content and opens it in Zed.
156
157## URL Handling
158
159The CLI can open `zed://`, `http://`, and `https://` URLs:
160
161```sh
162zed zed://settings
163zed https://github.com/zed-industries/zed
164```
165
166## Using Zed as Your Default Editor
167
168Set Zed as your default editor for Git and other tools:
169
170```sh
171export EDITOR="zed --wait"
172export VISUAL="zed --wait"
173```
174
175Add these lines to your shell configuration file (e.g., `~/.bashrc`, `~/.zshrc`).
176
177## macOS: Switching Release Channels
178
179On macOS, you can launch a specific release channel by passing the channel name as the first argument:
180
181```sh
182zed --stable myfile.txt
183zed --preview myfile.txt
184zed --nightly myfile.txt
185```
186
187## WSL Integration (Windows)
188
189On Windows, the CLI supports opening paths from WSL distributions. This is handled automatically when launching Zed from within WSL.
190
191## Exit Codes
192
193| Code | Meaning |
194| ---- | --------------------------------- |
195| `0` | Success |
196| `1` | Error (details printed to stderr) |
197
198When using `--wait`, the exit code reflects whether the files were saved before closing.