# CLI reference

## Overview

`garnet` is Garnet Connect's command line client. It searches and reads the notes granted to one connection, appends to that connection's notebook, and runs the MCP server your AI client starts. It talks to the running Garnet app over a private socket, so Garnet must be open and unlocked.

It is part of the Garnet app for Mac, Windows and Linux, free on every plan. It is not a general Space tool: it reaches only what a connection grants, and it cannot create, edit or delete notes.

## Install

- **Mac and Linux:** in Garnet, open Settings › AI connections, and under Command line tool select Install. Garnet writes a small script to `~/.local/bin/garnet` that runs the Garnet app in command line mode. It needs no administrator rights. If `~/.local/bin` is not on your PATH, Settings shows the line to add. If another program already owns that file, Garnet leaves it alone and says so.
- **Windows:** Garnet installs no `garnet` command yet. Settings shows the full command to use instead, and the MCP client setup from Settings uses it. Running the tool in a Windows terminal is not supported yet.

Desktop AI apps often do not read your terminal's PATH, so give them the full path, as Copy setup does.

## Usage

```text
garnet <command> [options]
```

Every command except `status` needs a connection: pass `--connection`, `--plugin` or `--token`, or set `GARNET_CONNECTION` or `GARNET_TOKEN`. Find connection IDs in Settings › AI connections.

## Commands

### `garnet search`

```bash
garnet search <words…> --connection conn_…
```

Searches the notes granted to this connection. Every word must appear. Takes `--limit` (1 to 20) and `--cursor`.

```bash
garnet search garden plan --connection conn_… --limit 5
```

### `garnet list`

```bash
garnet list --connection conn_…
```

Lists the granted notes, most recently updated first. Takes `--limit` (1 to 50) and `--cursor`. Each line shows the title, type, date and ID. When there is another page, the tool prints `More: --cursor …` to stderr.

### `garnet read`

```bash
garnet read <id> --connection conn_…
```

Prints one granted note as Markdown. A note longer than 64 KiB is cut, and the tool prints `(Cut at 64 KiB.)` to stderr.

### `garnet notebook append`

```bash
garnet notebook append "<text>" --connection conn_…
echo "Summary of today" | garnet notebook append - --connection conn_…
```

Appends to this connection's notebook. Pass `-` to read the text from stdin. The connection must allow notebook writes.

### `garnet mcp`

```bash
garnet mcp --connection conn_…
```

Runs an MCP server on stdin and stdout. Your AI client starts this command; you do not run it yourself. See [Garnet Connect](/help/advanced/connect) for the tools it offers.

### `garnet status`

```bash
garnet status
garnet status --connection conn_…
```

Says whether Garnet is open and unlocked. With a connection, it also says whether the connection is active and whether it grants anything yet. It is the one command that works without a connection.

## Options

| Option | What it does |
| --- | --- |
| `--connection <id>` | The connection to use. Same as `GARNET_CONNECTION`. |
| `--plugin <name>` | Use the connection linked to a Garnet plugin in Settings: `claude`, `claude-desktop` or `chatgpt`. Not together with `--connection`. |
| `--token <token>` | The connection's access token, if it has one. It names the connection too. Prefer `GARNET_TOKEN`: other programs can see command lines. |
| `--json` | Print one JSON envelope. |
| `--limit <n>` | Page size, a whole number of 1 or more. |
| `--cursor <cursor>` | The next page, from the previous output. |
| `--help` | Print the usage. `-h` works too. |

## Environment variables

| Variable | What it does |
| --- | --- |
| `GARNET_CONNECTION` | The connection ID, when `--connection` is not given. |
| `GARNET_TOKEN` | The access token, when `--token` is not given. |

## JSON output

Without `--json`, the output is for people and may change. With `--json`, the tool prints exactly one JSON envelope, which is a versioned public contract:

```json
{ "garnetConnect": 1, "ok": true, "result": { "items": [], "nextCursor": null } }
```

```json
{ "garnetConnect": 1, "ok": false, "error": { "code": "not_found", "message": "No item with that ID." } }
```

`result` has the same shape as the matching MCP tool's output. For `status`, it holds `contract`, `running` and `locked`, plus `connection` (`ok`, `unavailable` or `unauthorized`) when a connection was named, and `grantEmpty` and `plugin` when that connection answers. The error codes are listed under [Errors](/help/advanced/connect#errors).

## Exit codes

| Code | Meaning |
| --- | --- |
| `0` | Success. |
| `2` | Usage error: an unknown command or option, or a missing value. |
| `3` | Garnet is not running, or is locked. |
| `4` | The connection is not active, or it needs a valid access token. |
| `5` | No item with that ID, or not granted. |
| `6` | Anything else. |

## Examples

```bash
# Is Garnet ready?
garnet status

# The ten most recent granted notes, as JSON
garnet list --connection conn_… --limit 10 --json

# Read a note by ID with an access token
GARNET_TOKEN=gct_… garnet read <item id>
```
