Getting Started¶
Applies to: CPersona 2.6.x. This page is the canonical installation and setup reference. The README keeps a condensed version of the same steps because it is also the PyPI project page; when the two disagree, this page wins.
CPersona is an MCP server. You install it,
point an MCP client at it, and the client's agent gains store / recall
tools that survive across sessions. Nothing else in your stack changes.
Let your agent set it up¶
In Claude Code or Codex, paste the setup prompt from the website. It asks the agent to read this guide, show you each step first, and wait for your approval before it runs commands, installs anything or changes files. The agent is all you need to start: it proposes whatever the steps below require, such as Python 3.11+ and uv, and installs nothing until you approve.
The rest of this page is the same setup, step by step, for doing it yourself.
Prerequisites¶
For doing the setup yourself:
- Python 3.11+ whose
sqlite3module links SQLite 3.34 or later: the full-text index uses the FTS5 trigram tokenizer, which first shipped in SQLite 3.34. Check withpython3 -c "import sqlite3; print(sqlite3.sqlite_version)". On an older SQLite the first start stops withno such tokenizer: trigram;CPERSONA_FTS_ENABLED=falseskips that index, and recall then has no keyword channel - uv for the one-command path (optional —
pipworks too) - An MCP client: Claude Desktop, Claude Code, Codex CLI, Cursor, VS Code, or any other MCP host — step 3 has the entry for each
Install the agent plugin (Claude Code and Codex)¶
This repository is also a plugin marketplace, for Claude Code and for Codex. Its
one plugin, cpersona, carries the
Agent Skill,
which walks the agent through the installation and then teaches it when to
store, recall, and archive, and three hooks that remind it at the moments it
tends not to (below). The plugin does not include the server: you connect that
in step 3 as usual, so the tool names are the same however you install.
Claude Code (2.1.275 or later):
/plugin install cpersona --marketplace Cloto-dev/cpersona
Codex:
codex plugin marketplace add Cloto-dev/cpersona
codex plugin add cpersona@cpersona
Codex runs a plugin's hooks only once you trust them: open /hooks in the
Codex TUI after installing, and again after an update that changes them.
codex exec runs them without asking.
Then tell the agent: "Set up CPersona — I want persistent memory."
Each hook adds one note to the agent's context and does nothing else. None of them blocks the agent or talks to the server, and a hook that cannot read its input adds nothing.
| When | The note asks the agent to | Size of the note |
|---|---|---|
A session starts (new, or after /clear) |
use the agent_id it names, call reconstruct before its first substantive action, and store what is worth keeping as it happens rather than at the end |
about 530 characters, once |
| You send a prompt | call reconstruct for this request, with the prompt as the suggested query, and confirm "there is no such record" with an exact search |
about 310 characters plus up to 200 of the prompt and the agent_id when one is set, every prompt |
| The conversation was compacted | use the agent_id it names, call reconstruct for the task in progress, and check the summary's claims before storing them as facts |
about 530 characters, after each compaction |
CPersona returns a record only to the agent_id it was stored under, so the
notes name one. It is the plugin's agent_id option (Claude Code asks for it
when you enable the plugin; change it later in /config), or else
CPERSONA_AGENT_ID in the environment the agent runs in (Codex has no plugin
options), or else default. With default, the notes tell the agent to keep
an agent_id that your CLAUDE.md or AGENTS.md already names. Leave it unset
on both clients to share one memory between them, or set a different id on
each to keep them apart. Before the notes named one, an agent guessed a name
per session (claude, default, the project's name), so records it stored
then can sit under several ids: list_memories with an empty agent_id shows
each row's id, and merge_memories moves an id's records into the one you use
now.
There is no hook before compaction: neither host lets one put text in front of
the agent, so storing as it goes is what keeps the memory current. To turn
hooks off, set CPERSONA_HOOKS_DISABLE to a comma-separated list of
session-start, prompt and compact, or to all, in the environment the
agent runs in.
If you already prompt CPersona from hooks you registered yourself (for example a
copy of the earlier examples/claude-code-hooks/prompt_hook.py), from a plugin of
your own, or from a copy of the skill, the plugin does not replace them. Both run:
the agent reads each note twice and sees the skill twice (in Claude Code the
plugin's copy is named cpersona:cpersona-memory). Keep one. To move to the
plugin, remove your hook's entry from .claude/settings.json or your Codex hooks
file, and delete the copied skill folder (~/.claude/skills/cpersona-memory or
~/.codex/skills/cpersona-memory). To keep yours, turn the matching plugin hooks
off with CPERSONA_HOOKS_DISABLE. Hooks and settings that name the tools
(mcp__cpersona__*) keep working either way: the plugin does not bundle the
server, so the tool names do not change.
The skill also ships on its own, without the hooks, for other clients or for copying by hand:
# Installed from PyPI? The skill ships inside the wheel — no clone needed:
python -c "import cpersona,pathlib,shutil; s=pathlib.Path(cpersona.__file__).parent/'skills'/'cpersona-memory'; shutil.copytree(s, pathlib.Path.home()/'.claude/skills/cpersona-memory', dirs_exist_ok=True)"
# Running via uvx (isolated environment), or not installed yet:
git clone --depth 1 https://github.com/Cloto-dev/cpersona.git /tmp/cpersona
mkdir -p ~/.claude/skills && cp -r /tmp/cpersona/plugin/skills/cpersona-memory ~/.claude/skills/
The manual steps below are for every other client, and for anyone who prefers to configure things by hand. Step 5 is the part the skill would otherwise do: it makes the memory triggers fire without being asked.
1. Install CPersona¶
uvx cpersona # run directly, no install step
# or
pip install cpersona # then the `cpersona` command is on your PATH
From source (for development)
git clone https://github.com/Cloto-dev/cpersona.git
cd cpersona
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install .
In a container
git clone https://github.com/Cloto-dev/cpersona.git
cd cpersona
docker build -t cpersona .
docker volume create cpersona-data
docker run -d --name cpersona -p 8402:8402 \
-e CPERSONA_AUTH_TOKEN="$(openssl rand -hex 32)" \
-v cpersona-data:/data cpersona
In containers, with an embedding server
`compose.yaml` in this repository runs CPersona and CEmbedding together, wired to each other, so vector search works without a second setup:export CPERSONA_AUTH_TOKEN=$(openssl rand -hex 32)
docker compose run --rm embedding cembedding-download-model --model bge-m3
docker compose up -d
At startup the server checks pypi.org for a newer release. It reports one
through recall and check_health, and check_update answers on demand. Set
CPERSONA_UPDATE_CHECK=false to turn the check off. Updating is never
automatic: it takes an explicit check_update(apply=true) and a restart.
2. Set up an embedding server (recommended)¶
Connect a compatible embedding server. Running CPersona without one is supported as a fallback, but is not recommended for normal operation.
Vector search is the strongest of the three retrieval layers, and the only one that needs an external process. Without it CPersona still runs on FTS5 + keyword search, and says so on every recall.
CEmbedding is the reference backend. Any other embedding server that satisfies the contract below is supported just as well. The choice is yours.
The contract¶
CPersona is embedding-server-agnostic. Point CPERSONA_EMBEDDING_URL at any
HTTP endpoint that implements this:
POST /embed
Request: { "texts": ["string", ...] } # non-empty array
Response: { "embeddings": [[float, ...], ...], "dimensions": <int> }
CPersona reads embeddings and nothing else. dimensions comes from the
reference server and is ignored by the client, so a backend that omits it
still works. CPersona sends at most 64 texts per request (when it
builds a record's sentence blocks; 32 elsewhere), and the reference server
accepts up to 100. Batch limits in that range are nothing you
need to plan around.
Three requirements are easy to miss. Each one degrades ranking silently:
- Embeddings MUST be L2-normalized. CPersona computes similarity as a raw
dot product, so a backend returning unnormalized vectors biases ranking by
vector magnitude. Every supported backend (the client's
apimode and all CEmbedding providers) already normalizes. - The contract is role-less. Queries and documents go through the same call, with no instruction prefix. Prompt-prefix models (e5-style, prompted bge) underperform here. Symmetric or retrieval-merged models (jina-v5-nano, bge-m3, MiniLM) are the intended fit.
- Swapping models behind one URL invalidates the corpus. The
/embedcontract carries no model identity. A backend that also answersGET /capabilities(CEmbedding 0.9.0 and later) names itself with a fingerprint, and from 2.6.3 every stored vector is labelled with it, socheck_healthcounts the vectors a different model wrote (embedding_model_mismatch). Without that report, from an older or another backend, CPersona can tell a swap only by embedding dimension, and a swap to a different model of the same dimension is undetectable. Vectors stored before 2.6.3 carry no label and are never counted.
Detecting a swap does not repair it. check_health(fix=true) re-embeds rows
whose blob is NULL, and the dimension check only NULLs blobs of the wrong
length. After a same-dimension swap every blob is the expected size, so
nothing is NULLed and nothing is re-embedded. No tool force-re-embeds a row
that already has a blob. Until the corpus is rebuilt,
CPERSONA_EMBEDDING_MODEL_MODE=reject stops comparing the old vectors with
queries; those rows are then found only by keyword.
To recover, rebuild the corpus: delete_agent_data, then re-store as in
the rebuild pattern, then
run calibrate_threshold.
The reference server¶
CEmbedding (MIT) runs bge-m3 on-device (CPU) and exposes exactly this endpoint:
# Download the model into ./data/models
uvx --from "cembedding[onnx]" cembedding-download-model --model bge-m3
# Run the server (it reads ./data/models from the current directory)
EMBEDDING_PROVIDER=onnx_bge_m3 uvx --from "cembedding[onnx]" cembedding
Or put it on your PATH with pip install "cembedding[onnx]" and run
cembedding-download-model --model bge-m3, then
EMBEDDING_PROVIDER=onnx_bge_m3 cembedding. From a source checkout the same two
steps are python -m cembedding.download_model --model bge-m3 and
EMBEDDING_PROVIDER=onnx_bge_m3 python -m cembedding. Name the provider every
time: a server started without it serves a different model from the one just
downloaded.
onnx_bge_m3 loads the int8 ONNX conversion of bge-m3
(Xenova/bge-m3, about 550 MB, 1024
dimensions). On Apple Silicon, mlx_bge_m3 and auto_bge_m3 run bge-m3 through
MLX at fp16, which is faster; their vectors differ from the ONNX ones, so keep
one store on one of the two.
Either way you should see
HTTP embedding endpoint started on http://127.0.0.1:8401/embed. Verify it
before wiring CPersona to it:
curl -s http://127.0.0.1:8401/embed \
-H 'content-type: application/json' \
-d '{"texts":["hello world"]}' | head -c 200
CPersona only needs the URL. But how you supervise the reference server matters, and the obvious way does not work.
It is an MCP server, not a plain HTTP process. On its default transport it
runs an MCP session on stdio in the foreground and serves the REST /embed
endpoint from a background task. Its lifetime is therefore bound to stdin:
at EOF the session ends and the finally clause cancels the HTTP task.
A service manager starts things with stdin on /dev/null. Started that way,
the server binds the port, logs HTTP embedding endpoint started, and exits
in the same second with status 0. The supervisor sees a clean exit, and
CPersona is left pointed at a URL nothing answers.
Give it a stdin that stays open. Under a service manager, run it through
something that holds the pipe: ExecStart=/bin/sh -c 'sleep infinity |
cembedding'. In a terminal, the terminal already does this.
EMBEDDING_TRANSPORT=streamable-http does not read stdin, so it supervises
cleanly. But it serves the MCP endpoint instead of REST /embed, so it is
not an option for CPersona's http mode, which posts to /embed.
Which model¶
bge-m3 is the recommended model: it is MIT-licensed and multilingual. Up to 2.6.16 these pages recommended jina-v5-nano, whose license (CC BY-NC 4.0) does not allow commercial use. The change is about the license; no accuracy difference between the two is claimed.
On a small machine, all-MiniLM-L6-v2 (--model miniml,
EMBEDDING_PROVIDER=onnx_miniml; Apache 2.0, 384 dimensions) is much smaller,
but it is an English-only model.
CPersona calibrates its recall thresholds per store, against the model you
connect, and recalibrates at startup when the stored vectors' dimension changes.
Any other server satisfying the contract works. Models with published
measurements are listed in
benchmarks/.
Moving a store from jina-v5-nano¶
jina-v5-nano's vectors (768 dimensions) cannot be compared with bge-m3's (1024). Nothing switches on its own: a store keeps using whatever server its URL names. To move one:
- Start the bge-m3 server as above, point
CPERSONA_EMBEDDING_URLat it, and restart CPersona. - Run
check_health(fix=true). It reportsembedding_dimension_mismatch, clears the 768-dimension vectors, and re-embeds those rows with bge-m3, up toCPERSONA_REEMBED_ROW_CAP(5,000) rows per table per run. Run it again until it reports no row without an embedding. - Run
calibrate_threshold.
Until a row is re-embedded, recall reaches it by keyword search only.
3. Register CPersona with your MCP client¶
Every client launches the same process: command uvx, argument cpersona,
and the environment shown below. They differ only in which file they read and
what they call the keys.
Pick an absolute CPERSONA_DB_PATH first. The examples use
/home/you/.claude/cpersona.db because that directory already exists for
Claude users, but any absolute path works. Write it out in full: ~ and
$HOME are not expanded, because the client starts the server without a shell.
| Client | Where the entry goes | Shape | Checked here |
|---|---|---|---|
| Claude Code | claude mcp add-json … -s user (writes the user config) |
JSON, type: stdio |
yes |
| Claude Desktop | claude_desktop_config.json |
JSON, mcpServers |
yes |
| Codex CLI | codex mcp add … -- uvx cpersona (writes ~/.codex/config.toml) |
TOML, [mcp_servers.cpersona] |
yes (codex-cli 0.147.0) |
| Cursor | ~/.cursor/mcp.json (global) or .cursor/mcp.json (project) |
JSON, mcpServers |
vendor docs |
| VS Code (Copilot) | .vscode/mcp.json (workspace) or the user mcp.json |
JSON, servers |
vendor docs |
| Any other MCP host | its stdio server configuration | the same command / args / env triple | vendor docs |
"Checked here" means the entry was written by that client's own tooling and read back on a maintainer machine while this page was written. "Vendor docs" means the shape was transcribed from the client's documentation and has not been executed here. If it disagrees with what your client accepts, the client is right — please report it.
Claude Desktop — add to claude_desktop_config.json:
{
"mcpServers": {
"cpersona": {
"command": "uvx",
"args": ["cpersona"],
"env": {
"CPERSONA_DB_PATH": "/home/you/.claude/cpersona.db",
"EMBEDDING_MODE": "http",
"EMBEDDING_HTTP_URL": "http://127.0.0.1:8401/embed"
}
}
}
}
Claude Code — one command:
Replace /home/you with your home directory (on Windows, C:/Users/you).
If you have not set up an embedding server
(step 2), change
"EMBEDDING_MODE":"http" to "EMBEDDING_MODE":"none".
claude mcp add-json cpersona '{"type":"stdio","command":"uvx","args":["cpersona"],"env":{"CPERSONA_DB_PATH":"/home/you/.claude/cpersona.db","EMBEDDING_MODE":"http","EMBEDDING_HTTP_URL":"http://127.0.0.1:8401/embed"}}' -s user
Codex CLI — one command; it writes the TOML shown after it into
~/.codex/config.toml:
Replace /home/you with your home directory (on Windows, C:/Users/you).
If you have not set up an embedding server
(step 2), change
EMBEDDING_MODE=http to EMBEDDING_MODE=none.
codex mcp add cpersona --env CPERSONA_DB_PATH=/home/you/.claude/cpersona.db --env EMBEDDING_MODE=http --env EMBEDDING_HTTP_URL=http://127.0.0.1:8401/embed -- uvx cpersona
[mcp_servers.cpersona]
command = "uvx"
args = ["cpersona"]
[mcp_servers.cpersona.env]
CPERSONA_DB_PATH = "/home/you/.claude/cpersona.db"
EMBEDDING_HTTP_URL = "http://127.0.0.1:8401/embed"
EMBEDDING_MODE = "http"
Codex can also deny-list tools per server (disabled_tools = ["delete_memory",
…] under the same table). That is a client-side way to give an agent read-
mostly access. The server-side equivalent, enforced for every client at once,
is the
per-client capability layer.
Cursor — ~/.cursor/mcp.json, or .cursor/mcp.json inside a project. Same
shape as Claude Desktop:
{
"mcpServers": {
"cpersona": {
"command": "uvx",
"args": ["cpersona"],
"env": {
"CPERSONA_DB_PATH": "/home/you/.claude/cpersona.db",
"EMBEDDING_MODE": "http",
"EMBEDDING_HTTP_URL": "http://127.0.0.1:8401/embed"
}
}
}
}
VS Code (Copilot) — .vscode/mcp.json in the workspace, or the user-level
mcp.json (MCP: Open User Configuration). The top-level key is servers,
not mcpServers:
{
"servers": {
"cpersona": {
"command": "uvx",
"args": ["cpersona"],
"env": {
"CPERSONA_DB_PATH": "/home/you/.claude/cpersona.db",
"EMBEDDING_MODE": "http",
"EMBEDDING_HTTP_URL": "http://127.0.0.1:8401/embed"
}
}
}
}
Three things account for most setup problems:
- Set
CPERSONA_DB_PATHto an absolute path. The default,data/cpersona.db, is relative to the client's working directory, so a client launched from somewhere else opens a different, empty database. On Windows, write the path asC:/Users/you/.claude/cpersona.db. - No embedding server yet? Drop the two
EMBEDDING_*lines (or setEMBEDDING_MODE=none). CPersona runs on FTS5 + keyword and reports that it is degraded. EMBEDDING_MODE/EMBEDDING_HTTP_URLare the generic aliases ofCPERSONA_EMBEDDING_MODE/CPERSONA_EMBEDDING_URL. The prefixed form wins when both are set. The configuration reference lists every variable the server reads, with its default.
4. Verify it works¶
Ask the agent to store something, then recall it in a new session. Surviving the session boundary is the whole point:
"Store this: the deploy runbook lives in ops/deploy.md."
…then, in a fresh session: "What did I tell you about the deploy runbook?"
Two checks worth running once the corpus is real:
check_health— the registry-driven health check.statusis the verdict; issues are severity-tagged (critical/warn/info), andcheck_health(fix=true)repairs the mechanical ones.- Watch recall responses for an
advisoryfield. It means vector search is not contributing. The severity says why: ahintmeans embeddings are unconfigured (mode=none), and a fault means a configured endpoint stopped answering. See detecting a dead embedding server.
5. Make the memory triggers fire in every session¶
Registration gives the agent the tools. It does not make the agent use them unprompted. Recall at session start, store on a decision, archive at session end: those rules have to live in a file the client loads on every session, not in a skill that activates only when the conversation happens to match. Every client has such a file:
| Client | Always-loaded file (user-level default) | Project-level alternative |
|---|---|---|
| Claude Code / Claude Desktop | ~/.claude/CLAUDE.md |
./CLAUDE.md |
| Codex CLI | ~/.codex/AGENTS.md |
./AGENTS.md at the repository root |
| Cursor | User Rules (Customize → Rules — a setting, not a file) | .cursor/rules/cpersona.mdc with alwaysApply: true, or ./AGENTS.md |
| VS Code (Copilot) | see the client's custom-instructions documentation | .github/copilot-instructions.md, or ./AGENTS.md with chat.useAgentsMdFile enabled |
Paste the block below into that file. Replace <AGENT_ID> with one stable
identifier the agent will use on every call ("claude-code", "codex", …).
Keep the markers. A later version of the block uses them to find and replace
this one instead of stacking a second copy. On Claude Code the cpersona-
memory skill does the paste for you, with your approval; everywhere else you
paste it by hand.
The rules the block follows — consent, placement, idempotency, the 40-line budget, client neutrality — are the policy block standard. The block itself is maintained in the skill, and this copy is checked against it in CI.
<!-- BEGIN cpersona-policy v5 (managed by the cpersona-memory skill; re-run the skill to update) -->
## CPersona memory policy
Use the CPersona MCP tools proactively with `agent_id="<AGENT_ID>"` — never wait to be asked.
**Session start** → `reconstruct(agent_id, query="<opening-topic keywords>")` before the first
substantive action; with no topic yet, `recall(agent_id, query="", limit=10)` for the latest.
`deep=true` when the first pass comes back thin. Skip only for trivial one-shot questions.
**Answering from memory** → `reconstruct(agent_id, query)`, not `recall`: 10 items by default, each
quoting the rows behind it, at fewer reader tokens per correct answer. Read an item to judge it.
**Decisions, rules, preferences, bug findings** → `store` immediately. Fire on phrases like
"let's go with X", "from now on always Y", "remember that…", "approved", "that's a bug".
Lock must-never-lose rules: `lock: true` on the `store` where it offers one, else `lock_memory`.
After a successful `git commit`, `store` a one-line record: hash, what changed, why.
**Changing an existing rule** → `update_memory`, never delete + store. If the memory is locked:
`unlock_memory` → `update_memory` → `lock_memory`.
**Session end** — fire on closing phrases ("that's all for today", "wrap it up", "good night") →
first `store` + lock any unsaved decisions, then `archive_episode(agent_id, history=<the REAL
turns>, summary=…, keywords=…, resolved=…)`, computing `summary` and `keywords` yourself.
**"Don't save this" / benchmark sessions** → `pause_persistence(ttl_seconds=1800)`;
`resume_persistence()` (or TTL expiry) restores. Reads still answer, minus the writes inside them.
**Degraded mode** — if a `recall` response carries an `advisory` field, surface it to the user
and follow its runbook. Never quietly serve keyword-only recall.
**Quality** — recall feels off → `set_recall_precision` (strict/balanced/lenient), the one policy
knob; after large corpus changes `calibrate_threshold(agent_id)`; monthly `check_health(agent_id, fix=true)`.
**If this client keeps a memory file that loads every session** (Claude Code's `MEMORY.md`), use it
as the deterministic index over this store: one line per memory — `- <slug> — <the sentence that
changes behaviour>` — with the body stored here under the id `memory-index:<slug>` and content
starting `[<slug>]`, so a line tells you what to `recall`. Recall is ranked and may not surface a
memory; the index always arrives. Its size cap fails **silently** when exceeded, so consolidate at
80%, not at the limit. Never migrate existing memories into this store without asking first.
Details, setup, and troubleshooting: the `cpersona-memory` skill.
<!-- END cpersona-policy -->
Where to go next¶
| You want to… | Read |
|---|---|
| Know which behaviors you can rely on | Behavior Contracts |
| See what each tool does | Tools |
| Understand how retrieval works | Architecture |
| Back up, tune, or diagnose a live instance | Operations Runbook |
| Look up a setting | Configuration |
| Serve several clients over the network | Remote HTTP transport |