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
74Add paths to the currently focused workspace instead of opening a new window. When multiple workspace windows are open, files open in the focused window:
75
76```sh
77zed -a newfile.txt
78```
79
80### `-r`, `--reuse`
81
82Reuse an existing window, replacing its current workspace with the new paths:
83
84```sh
85zed -r ~/projects/different-project
86```
87
88### `--diff <OLD_PATH> <NEW_PATH>`
89
90Open a diff view comparing two files. Can be specified multiple times:
91
92```sh
93zed --diff file1.txt file2.txt
94zed --diff old.rs new.rs --diff old2.rs new2.rs
95```
96
97### `--foreground`
98
99Run Zed in the foreground, keeping the terminal attached. Useful for debugging:
100
101```sh
102zed --foreground
103```
104
105### `--user-data-dir <DIR>`
106
107Use a custom directory for all user data (database, extensions, logs) instead of the default location:
108
109```sh
110zed --user-data-dir ~/.zed-custom
111```
112
113Default locations:
114
115- **macOS:** `~/Library/Application Support/Zed`
116- **Linux:** `$XDG_DATA_HOME/zed` (typically `~/.local/share/zed`)
117- **Windows:** `%LOCALAPPDATA%\Zed`
118
119### `-v`, `--version`
120
121Print Zed's version and exit:
122
123```sh
124zed --version
125```
126
127### `--uninstall`
128
129Uninstall Zed and remove all related files (macOS and Linux only):
130
131```sh
132zed --uninstall
133```
134
135### `--zed <PATH>`
136
137Specify a custom path to the Zed application or binary:
138
139```sh
140zed --zed /path/to/Zed.app myfile.txt
141```
142
143## Reading from Standard Input
144
145Read content from stdin by passing `-` as the path:
146
147```sh
148echo "Hello, World!" | zed -
149cat myfile.txt | zed -
150ps aux | zed -
151```
152
153This creates a temporary file with the stdin content and opens it in Zed.
154
155## URL Handling
156
157The CLI can open `zed://`, `http://`, and `https://` URLs:
158
159```sh
160zed zed://settings
161zed https://github.com/zed-industries/zed
162```
163
164## Using Zed as Your Default Editor
165
166Set Zed as your default editor for Git and other tools:
167
168```sh
169export EDITOR="zed --wait"
170export VISUAL="zed --wait"
171```
172
173Add these lines to your shell configuration file (e.g., `~/.bashrc`, `~/.zshrc`).
174
175## macOS: Switching Release Channels
176
177On macOS, you can launch a specific release channel by passing the channel name as the first argument:
178
179```sh
180zed --stable myfile.txt
181zed --preview myfile.txt
182zed --nightly myfile.txt
183```
184
185## WSL Integration (Windows)
186
187On Windows, the CLI supports opening paths from WSL distributions. This is handled automatically when launching Zed from within WSL.
188
189## Exit Codes
190
191| Code | Meaning |
192| ---- | --------------------------------- |
193| `0` | Success |
194| `1` | Error (details printed to stderr) |
195
196When using `--wait`, the exit code reflects whether the files were saved before closing.