Docs

Reference for the Remaind CLI, the .context/ directory it manages, and the schemas that make it verifiable. To wire Remaind into an agent, see Integrate.

Install

pip install remaind            # core
pip install 'remaind[llm]'     # + the Anthropic LLM compactor

Requires Python 3.11+. The core install has no optional dependencies.

CLI reference

Six commands cover the full lifecycle. Every state-mutating command snapshots the prior version before writing.

CommandWhat it does
remaind init [--path P] [--force]Create .context/. --force backs up an existing one first.
remaind validate [--path P]Walk the v1 checklist: structure, schemas, state, handover, events, SQLite.
remaind status [--path P] [--json]Goal, status, next step, token band, event counts, compaction recommendation.
remaind compact [--path P]Run the compaction pipeline (rule-based by default), gated by structured validation.
remaind compact --llm [--model M]Compact with the Anthropic-backed LLM compactor. Needs remaind[llm] + ANTHROPIC_API_KEY.
remaind compact --compactor MOD:FNCompact with any model — imports MOD:FN as a (system, user) → str | dict callable.
remaind resume [--path P] [--next-tool T]Build active/resume_packet.md and consult the resume gate.
remaind rollback [--path P] --to TSRestore derived files from history as of TS. The raw log is never touched.

The .context/ directory

One directory per project. Files under active/ are derived and atomically replaced; events.jsonl is append-only and authoritative; schemas/ is the contract. Runtime files (resume_packet.md, history/, db/, artifacts/) are git-ignored.

.context/
├── CONTRACT.md                 the binding contract — read this first
├── active/
│   ├── state.json              derived working state (atomic replace)
│   ├── handover.md             compact continuity document (atomic replace)
│   ├── resume_packet.md        runtime — assembled fresh-context packet
│   └── history/                runtime — snapshots of every prior version
├── logs/
│   └── events.jsonl            append-only raw timeline (source of truth)
├── schemas/
│   ├── event.schema.json       JSON Schema Draft 2020-12
│   ├── state.schema.json
│   ├── memory.schema.json
│   ├── validation.schema.json
│   ├── thresholds.yaml         token-band math
│   ├── redaction.yaml          secret patterns redacted before logging
│   ├── tools.yaml              mechanical tool-risk flags
│   └── migrations/{state,events}/
├── db/context.sqlite           runtime — memory index + FTS5
└── artifacts/                  runtime — large + binary outputs

Schemas

JSON Schemas are canonical — runtime data is validated against them, not the other way around. The YAML files are configuration.

FilePurpose
event.schema.jsonEvery line of events.jsonl — validated before append.
state.schema.jsonactive/state.json — validated on every write.
memory.schema.jsonRows in the SQLite memory index.
validation.schema.jsonThe compaction validator's structured result.
thresholds.yamlToken-band math and the compaction budget.
redaction.yamlRegex patterns + replacement format for secret redaction.
tools.yamlPer-tool mutates / spends_money / external_side_effect flags.

Importance levels

Every event carries an importance 0–3. Compaction must preserve all importance ≥ 2 events; importance = 3 items must be explicitly represented in state or handover.

LevelMeaning
0trace / debug
1normal useful event
2decision, correction, constraint, file change, blocker, meaningful result
3remember-instruction, active next step, active blocker, critical user instruction

Threshold bands

The token estimate drives a band. Defaults below — all configurable in thresholds.yaml.

BandEstimated tokensRecommendation
normal< 60,000 tokenscontinue
warning≥ 60,000mark compaction pending
hard≥ 70,000compact before the next substantial step
emergency≥ 80,000compact immediately

Next

Integrate — wire Remaind into your agent loop: the public API, event logging, compaction, and resume, with runnable code. How it works — the mechanics behind the commands. The full binding contract ships as .context/CONTRACT.md after remaind init.