Skip to main content
The Coconut CLI is a command-line client for the Coconut Context HTTP API. It covers pages, structured metadata, full-text search and metadata queries, typed records, templates, spaces (including export and import), and space agents. It’s built on the Coconut SDK, so every call goes through the same typed client; the CLI adds auth flows, profiles, and terminal UX on top. Use it when you want to work with your context layer from a shell, a CI pipeline, or an agent runtime that can shell out.

View on npm

The coconut package, published under Apache-2.0.

Source on GitHub

lovelybunch/coconut-cli, including tests and the release workflow.

Install

Requires Node 20 or later.
The package installs one binary under two names, coco and coconut. The docs use coco throughout.

Authenticate

Credentials are stored in named profiles in ~/.config/coco/config.json (XDG_CONFIG_HOME is respected, and the file is written with mode 0600). There are two credential types.
This discovers the OAuth endpoints, registers a client with a loopback redirect, opens your browser at the sign-in page, and exchanges the code (PKCE S256 plus state). The browser step needs a signed-in human, so this is the interactive path.Scopes default to context:read context:write. Pass --read-only for a context:read-only token; writes are then denied with a 403 regardless of your role. Access tokens refresh automatically. When a refresh fails, you get a clear message asking you to run coco auth login again (exit code 4).The OAuth flow refuses to proceed unless the discovery document’s issuer matches the base URL and every endpoint is on that same origin. Endpoints must be https; plain http is allowed only for loopback hosts.
Check what you’re signed in as:

Profiles, flags, and environment

Every command accepts --profile, --base-url, --org-slug, --json, and --quiet. Precedence is flags, then environment, then profile. The environment variables are COCO_BASE_URL, COCO_API_KEY, and COCO_ORG_SLUG, so a CI job needs no config file at all:

Command surface

Run coco <command> --help for the full option list of any command.

Filter syntax

coco query and coco records list take repeatable --filter expressions. Filters are AND-ed together. Values are JSON-parsed when they look like JSON: 0.7 is a number, "0.7" is a string, true is a boolean. The same rule applies to --metadata and --set values, and --set k=null deletes a key. The list operators in and not-in take a comma-separated list or a JSON array literal. Each item is JSON-parsed like any other filter value.
The list operators shipped in coconut 0.2.0. Run coco --version if a filter using them is rejected as a usage error. A few details worth knowing:
  • in and not-in are whitespace-delimited word operators, and the earliest operator in the expression wins. note=check in later is still an equality check on the string check in later, and a key literally named in still works.
  • A single JSON scalar is one candidate, so note in "a,b" keeps the comma.
  • An empty list or an empty item is a usage error (exit code 2).

Safe writes

Writes are safe by construction. page put and page edit read the current version and send If-Match, so a concurrent edit surfaces as a clear 412 conflict message (exit code 6) instead of a silent overwrite. A leading --- block of flat key: value lines in content you provide is folded into the title and frontmatter client-side; the REST API stores content verbatim. For nested structures, use --frontmatter with one-line JSON.

Output and exit codes

Human-readable tables print by default. --json prints the raw API payload alone on stdout, so you can pipe it to jq. Informational chatter goes to stderr, and --quiet silences it. NO_COLOR is respected.

A worked session

This walks the same deal-pipeline shape used in the SDK examples: author a record type, create records from it, query and patch them, move the space, then hand work to the space agent.
1

Sign in

The headless path is shown here. Use coco auth login for the browser flow.
2

Author a record type

A record type is a template with a metadata schema. Records created from it are validated against that schema.
3

Create records

Records are born conforming. A value outside the schema is rejected with a 400 and exit code 2.
4

Work the pipeline

5

Move a space around

6

Ask the space agent to work

Next steps

SDK

The typed TypeScript client the CLI is built on, for when a script needs more than the CLI gives you.

HTTP API

The routes underneath every CLI command.

Page metadata

How keys, schemas, and the audit trail behind coco meta work.

Agents

Tasks, schedules, and run records behind coco agent.