# CLI

On a Mac with Char Next signed in, the `char-next` CLI reads and edits the same Pages as the hosted MCP, and also reads History. The user installs it from **Settings → Apps → Char CLI**. Run `char-next --help` for the full command list.

```sh
char-next search 'launch' --limit 10
char-next memory day --date yesterday
char-next memory preferences
char-next pages export --page-id '<page-id>'
char-next pages export --daily today
```

`search` covers Pages, chats and History and prints JSON. `memory day` recalls one day: its summaries, History and daily page; `--date` takes `today`, `yesterday` or `YYYY-MM-DD`. `memory preferences` prints the user's saved standing preferences.

`pages export` and `memory read` print Markdown with `char:block` IDs, starting with a page line naming the revision it was read at, such as `<!-- char:page id="<page-id>" revision="<revision>" -->`. The daily selector accepts `today` or `YYYY-MM-DD`. Pass exactly one selector.

For a requested edit, export the Page and copy a returned block ID:

```sh
char-next pages edit --page-id '<page-id>' --replace-block '<block-id>' --markdown 'Updated text'
char-next pages edit --page-id '<page-id>' --insert-after-block '<block-id>' --markdown 'New paragraph'
char-next pages edit --daily today --insert-after-block '<block-id>' --markdown 'New paragraph'
char-next pages export --page-id '<page-id>'
```

To rewrite a Page with `memory write`, edit the `pages export` or `memory read` output and pass all of it back, keeping the page line and the `char:block` markers. The CLI works out which blocks changed since that read and edits only those, so text others wrote meanwhile stays. Without the page line, Markdown with block markers is refused. If the Page changed since the read so that a whole rewrite would undo it, or Char no longer has that read, the write is refused too: read the Page again, then write. Plain Markdown with no page line and no markers replaces the whole Page. Omit `--page-id` and pass `--title` to create a new Page.

Use `--markdown-file <path>` for multiline content or `--markdown-file -` for stdin. Keep edits to the same Page sequential. When Char Next is running, edits go through the app and also work offline. An edit printed as `"status": "sent"` is on its way: don't send it again.
