Skip to content

CLI reference

Complete reference for the ctx command-line tool. For task-oriented recipes, see COOKBOOK.md. For the mental model, see ARCHITECTURE.md.

ctx [GLOBAL OPTIONS] <COMMAND> [COMMAND OPTIONS]

Every command accepts these flags. They can also be set via environment variables.

FlagEnv varDefaultDescription
--server <URL>CTX_SERVERhttp://localhost:3001Hub HTTP endpoint
--branch <REF>CTX_BRANCHmainBranch / ref to read and write
--format <FMT>CTX_FORMATtextOutput format: text, json, or id
--help / -hPrint help
--version / -VPrint version
  • text — human-readable (default). Pretty-printed, with headings and summary lines.
  • json — pretty JSON of the full response. Designed for jq, grep, and other tool-chain use.
  • id — minimal: just the canonical identifier (name / commit_id / path). For capture into shell variables: fact=$(ctx remember "..." --format id).

Follows sysexits.h conventions.

CodeNameMeaning
0OKSuccess
64USAGEClap handled an argument error
65DATAERRBad input data (empty fact, malformed file, no sections)
66NOINPUTInput file doesn’t exist or can’t be read
69UNAVAILABLEHub unreachable at --server
70SOFTWAREInternal error; ctx doctor failed a check
74IOERRFailed to read from stdin or write to a file
76PROTOCOLHub returned a 5xx or an unexpected response

Store a fact, preference, or decision.

USAGE: ctx remember <FACT> [OPTIONS]
ARGS:
<FACT> The fact to remember. Use "-" to read from stdin.
OPTIONS:
-i, --importance <LEVEL> high | medium | low [default: medium]
-c, --context <NAME> Group under /memory/<context>/
-t, --tags <TAGS> Queryable tags

Examples:

Terminal window
ctx remember "We use BSL-1.1" --importance high --context licensing
echo "fact" | ctx remember -
ctx remember "deployed" --format id # prints just the commit id

Retrieve memories relevant to a topic. Always includes pinned context first, then topic-matched facts, respecting a token budget.

USAGE: ctx recall <TOPIC> [OPTIONS]
ARGS:
<TOPIC> Topic to search for (single or multi-word; tokenized)
OPTIONS:
-b, --budget <N> Max token budget for the response [default: 1500]
--exact Re-tokenize response + full graph locally with
tiktoken (cl100k_base) and show exact counts
alongside the fast 4-char estimate

Count exact tokens in a piece of text using tiktoken’s cl100k_base encoding (GPT-3.5 / GPT-4 family). Reads from stdin if no argument or - is given. Shows both the exact count and the 4-char estimate for comparison.

Terminal window
ctx tokens "The quick brown fox jumps over the lazy dog"
# 43 chars
# 9 tokens (cl100k_base, exact)
# 10 tokens (4-char estimate)
echo "any text" | ctx tokens -

Load a markdown file as structured memory, split at H1 and H2 headings. Idempotent by --source name (re-running overwrites).

USAGE: ctx prime <FILE> [OPTIONS]
ARGS:
<FILE> Path to markdown file, or "-" for stdin
OPTIONS:
--pin Always include these sections in every recall
--source <NAME> Source name (default: file stem)

List all pinned memories, grouped by source.

Delete a memory at an exact path.

USAGE: ctx forget <PATH> [OPTIONS]
ARGS:
<PATH> Path to forget (from ctx search or ctx ls)
OPTIONS:
--reason <TEXT> Shows up in blame [default: "forgotten by user"]

Load the full context tree for a project (everything under /memory/projects/<project>/).


Literal substring search across all values. Unlike recall, this is not LLM-oriented: no token budget, no pinned-first behavior, all results returned.

USAGE: ctx search <QUERY> [OPTIONS]
OPTIONS:
-n, --max <N> Max results [default: 50]

List paths in the graph under a prefix.

USAGE: ctx ls [PREFIX] [OPTIONS]
ARGS:
[PREFIX] Prefix to list under [default: /]
OPTIONS:
--max-depth <N> Max tree depth [default: 50]

Read a value at an exact path. Pretty-printed as JSON.

Recent commit history.

USAGE: ctx log [OPTIONS]
OPTIONS:
-n, --limit <N> Max commits to show [default: 20]

Show the provenance chain for a path — who wrote it, when, and why.

Compare two refs (branches, tags, or commits).

USAGE: ctx diff <REF_A> <REF_B>
OUTPUT:
+ AddKey /memory/test/abc
~ SetValue /memory/foo/bar
- RemoveKey /memory/baz

Tail -f style live monitor of new commits. Polls the log endpoint at the given interval (default 2000ms). Ctrl-C to stop.


List all branches. The current branch (from --branch / CTX_BRANCH) is marked with *.

Create a new branch.

USAGE: ctx branch <NAME> [OPTIONS]
OPTIONS:
--from <REF> Ref to branch from [default: main]

One-line Hub health check plus session token summary.

Detailed token savings breakdown.

CTXone Token Savings
graph size: 451 tokens
tokens sent: 98
tokens saved: 1706
savings: 18.4x

Seed 21 realistic facts and run 4 recalls, showing per-query and cumulative savings. Use for first-time demos or to verify a fresh install.

End-to-end health check. Verifies:

  • ctxone-hub binary is discoverable
  • ~/.ctxone/memory.db parent is writable
  • Hub HTTP endpoint is reachable
  • main branch is accessible
  • Each detected AI tool has a CTXone MCP config

Prints each check with ✓ or ✗, plus suggested fixes. Exits 70 on failure so scripts can gate on it.

Start the Hub. Delegates to the ctxone-hub binary.

USAGE: ctx serve [OPTIONS]
OPTIONS:
-p, --port <PORT> Port [default: 3001]
--storage <TYPE> sqlite | postgres | memory [default: sqlite]
--path <PATH> Database path [default: ~/.ctxone/memory.db]
--http Also start HTTP API (otherwise stdio MCP only)

Auto-detect installed AI tools and write CTXone into their MCP configs.

USAGE: ctx init [OPTIONS]
OPTIONS:
--global User-level config instead of project-only
--project Project-only (default)
--tool <NAME> Target a specific tool: claude, cursor, vscode,
codex, gemini, grok
--config-path <PATH> Write MCP JSON to an arbitrary file — for MCP
clients ctx init doesn't know about yet
--dry-run Show what would be written without writing

Supported tools (auto-detection + auto-configuration): Claude Code, Claude Desktop, Cursor, VS Code (Copilot MCP), Codex, Gemini CLI, Grok CLI.

Generic fallback: use --config-path for any MCP client that ctx init doesn’t directly support. It writes the standard mcpServers JSON shape to any path you specify, merging with any existing file.

Generate a shell completion script to stdout.

USAGE: ctx completion <SHELL>
SHELLS: bash | zsh | fish | powershell | elvish

Typical install:

Terminal window
# zsh
ctx completion zsh > ~/.zfunc/_ctx
echo 'fpath+=(~/.zfunc); autoload -U compinit; compinit' >> ~/.zshrc
# bash
ctx completion bash > /usr/local/etc/bash_completion.d/ctx
# fish
ctx completion fish > ~/.config/fish/completions/ctx.fish

{
"status": "ok",
"ref": "main",
"path": "/memory/licensing/18a6...",
"commit_id": "sg_e762325fed96"
}
{
"topic": "licensing",
"ref": "main",
"results": [
{
"path": "/memory/pinned/vision/the-insight",
"title": "The Insight",
"body": "...",
"pinned": true
},
{
"path": "/memory/licensing/18a6...",
"value": "CTXone uses BSL-1.1",
"pinned": false,
"score": 2,
"full_match": true
}
],
"pinned_count": 5,
"topic_matches": 2,
"ctx_tokens_sent": 620,
"ctx_tokens_estimated_flat": 1191,
"ctx_savings_ratio": 1.92
}

Array of commits:

[
{
"id": "sg_e762325fed96",
"timestamp": "2026-04-14T17:47:43...",
"agent_id": "ctxone",
"confidence": 0.95,
"intent": {
"category": "Custom(\"Observe\")",
"description": "CTXone uses BSL-1.1",
"tags": []
},
"reasoning": null
}
]
{
"ref_a": "main",
"ref_b": "experiment",
"ops": [
{
"op": "AddKey",
"path": "/memory/test",
"key": "abc",
"value": "new fact"
}
]
}

Op tags: SetValue, AddKey, RemoveKey, AppendItem, RemoveItem.


VariableDescription
CTX_SERVERDefault value for --server
CTX_BRANCHDefault value for --branch
CTX_FORMATDefault value for --format
HOMEUsed by find_hub_binary and canonical_db_path
DATABASE_URLWhen ctxone-hub is launched with --storage postgres

Command-line flags always override environment variables.