# ed cd []

> Sets the directory the later commands on that machine run in. It is not sent to the machine as a command; ed intercepts it, asks the machine where that path…

- Canonical URL: https://getedith.pro/docs/cli/machines-remote/machine-cd-directory
- Updated: 2026-12-02

Sets the directory the later commands on that machine run in. It is not sent to
the machine as a command; `ed` intercepts it, asks the machine where that path
resolves to, and records the answer.

```
ed <machine> cd <directory>
ed <machine> cd -
ed <machine> cd
```

## Arguments

| Name | Type / values | Default | What it does |
| --- | --- | --- | --- |
| `<directory>` | a path on the machine, absolute or relative to the current one, or `-` | omitted | Where to move to. Omitted means the home directory; `-` means back to the directory you were in before the last `cd`. |

`cd` is only intercepted when it is the whole command and there are at most two
words. `ed devbox cd` and `ed devbox cd Desktop` are interceptions;
`ed devbox cd a b` and the quoted one-shot `ed devbox 'cd /tmp && pwd'` are ordinary
commands that run and change nothing:

```
$ ed devbox 'cd /tmp && pwd'
/tmp
$ ed devbox pwd
/home/you
```

## Examples

```
ed devbox pwd                      /home/you
ed devbox cd Desktop
ed devbox pwd                      /home/you/Desktop
ed devbox ls                       lists Desktop
ed devbox cd -                     back to where you were before
ed devbox cd                       back to the home directory
```

## Behaviour notes

A successful `cd` prints nothing and exits 0. Under the covers `ed` runs
`pwd; cd -- '<target>' && pwd` on the machine, prefixed with a `cd` into the
directory you were already in, and keeps two lines: the first `pwd` becomes the
previous directory and the second becomes the current one. That is why `-`
works, and why it toggles rather than walking a stack.

The pair is stored in a file at
`~/Library/Application Support/Edith/machines/cwd/<machine>/<session>`, where
`<machine>` is the first ten characters of the machine's id with the dashes
removed and `<session>` is the name of the terminal your stdin is attached to,
`/dev/` stripped and anything that is not a letter or a digit turned into a
dash. So `/dev/ttys012` becomes `ttys012`, and two tabs on one machine never
move each other, the same way `cd` behaves in a local shell. When stdin is not a
terminal, which covers a pipe, a script and a cron job, the session is called
`shared` and every such invocation uses the same slot. The directory is created
mode `0700` and the file is written atomically.

A path that does not exist is reported with the machine's own message, exits 1,
and leaves the stored directory alone:

```
$ ed devbox cd nosuchdir
error: cannot change to nosuchdir on Devbox
hint: bash: line 1: cd: nosuchdir: No such file or directory
```

`cd -` with nothing recorded for this terminal exits 1 with `no previous
directory for <machine> in this terminal`, decided locally once the connection
is open and without asking the machine anything. The round trip a `cd` does
make is under the 60 second command timeout that `ed` puts on ordinary
commands, unlike the command path, which has none.

`--tty` reads the remembered directory but never sets it. The terminal branch
runs before the `cd` interception, so `ed machines exec --tty devbox cd Desktop`
changes directory inside that one pty session and nothing survives it.

The remembered directory reaches exactly two things: `ed machines exec`,
including the shorthand and the `--tty` form, and remote path completion.
Everything else keeps its own defaults, so `ed machines files ls devbox` still
lists the remote home directory after `ed devbox cd Desktop`, and the app's own
terminal and Finder windows are unaffected.

## Where to go next

- [Running commands on a machine](https://getedith.pro/docs/cli/machines-remote), the rest of this group
- [All `ed` commands](https://getedith.pro/docs/cli)

## Get Edith

Edith is a native Mac app for macOS 14 or later on Apple silicon with 100+ extensions, the `ed` command line and an MCP server. $35 once for one Mac, plus $7 for each additional Mac, with no subscription and a 30-day refund.

- [Buy Edith](https://getedith.pro/pricing): $35 once for one Mac, plus $7 for each additional Mac
- [Download Edith](https://getedith.pro/download): the installer, or Homebrew
