> ## Documentation Index
> Fetch the complete documentation index at: https://docs.docwriter.org/llms.txt
> Use this file to discover all available pages before exploring further.

# CLI

> Every docwriter command-line flag and what it does.

```
docwriter [options] [directory]
```

If `[directory]` is omitted, DocWriter opens the current working
directory.

## Options

| Flag              | Description                                                                                                  |
| ----------------- | ------------------------------------------------------------------------------------------------------------ |
| `-p, --port <n>`  | Port to listen on. Defaults to `7723`, or the next free port if `7723` is taken.                             |
| `--host [addr]`   | Bind address. Default: `127.0.0.1`. Bare `--host` (no argument) binds to `0.0.0.0` for LAN access.           |
| `--no-open`       | Do not auto-open a browser window on start.                                                                  |
| `-w, --watch`     | Reload the browser UI when workspace files change on disk. Useful when editing files from outside DocWriter. |
| `--restart`       | Restart the server if it crashes. Default: exit on crash.                                                    |
| `--root <dir>`    | Workspace root. Same as the positional `[directory]` argument.                                               |
| `--new-session`   | Clear any persisted AI session before starting. Files and tabs are not affected.                             |
| `--api-key <key>` | Anthropic API key. Overrides the `ANTHROPIC_API_KEY` environment variable.                                   |
| `--model <name>`  | Default model for the session: `opus`, `sonnet`, or `haiku`. Overrides the UI's model selector.              |
| `--version`       | Print the installed version and exit.                                                                        |
| `-h, --help`      | Print help and exit.                                                                                         |

## Environment variables

| Variable                  | Equivalent flag           |
| ------------------------- | ------------------------- |
| `ANTHROPIC_API_KEY`       | `--api-key`               |
| `DOCWRITER_ROOT`          | `--root` / positional arg |
| `DOCWRITER_DEFAULT_MODEL` | `--model`                 |
| `DOCWRITER_NEW_SESSION`   | `--new-session`           |

Flags take precedence over environment variables.

## Examples

Open the current directory:

```sh theme={null}
docwriter
```

Open a specific project:

```sh theme={null}
docwriter ~/projects/mybook
```

Open with a fresh agent session:

```sh theme={null}
docwriter --new-session ~/projects/mybook
```

Live-reload when files change on disk (useful when editing in another
editor too):

```sh theme={null}
docwriter --watch ~/projects/mybook
```

Expose to the local network (so you can edit from a tablet):

```sh theme={null}
docwriter --host --watch ~/projects/mybook
```

Force a specific port:

```sh theme={null}
docwriter --port 8080 ~/projects/mybook
```

Use a specific model for this session:

```sh theme={null}
docwriter --model opus ~/projects/mybook
```

Run without an auto-opened browser (useful in scripts / remote shells):

```sh theme={null}
docwriter --no-open --host ~/projects/mybook
```

## Auth precedence

DocWriter resolves credentials in this order:

1. `--api-key` flag
2. `ANTHROPIC_API_KEY` environment variable
3. Credentials stored by `claude login`

If none of these are present, you see an authentication error when you
try to start an agent turn. The file editor still works without
authentication.
