Skip to content
context Changes To index
Login

Changes To index

Initial version of "index"



















































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
# ctx

ctx keeps the work you do with coding agents. It archives every Claude Code
session, with secrets redacted, into a private Fossil repository on your machine
and makes it searchable, so an agent can find why something was decided or what
already failed. Per project it keeps tickets, version-pinned sources and a wiki
whose every claim quotes an exact source version. Repositories sync between
machines and people.

It is one C binary built from SQLite and libfossil, with everything in one SQLite
file per machine.

## What it does

- **Archives sessions.** Hooks capture each Claude Code session as it runs; a
  periodic scan catches anything missed, and Pi and pic sessions too. Tool
  output is kept, trimmed, and known secret shapes are replaced with
  `[REDACTED]` before anything is stored.
- **Searches them.** `ctx search` ranks turns with SQLite's FTS5, this project
  first; `ctx turn` reads around a hit. The `ctx` skill teaches agents to do both.
  `ctx mcp` offers the same two as tools to clients that cannot run commands.
- **Reminds agents the archive exists.** `ctx gate`, run as a hook before an
  agent's first search in a session, tells it once that past sessions can be
  searched, then stays quiet.
- **Indexes a repository's documents.** `ctx docs add DIR` makes design notes,
  decision records and RFCs searchable where they sit, re-read when they change.
  Its checks compare documents with each other (dead links, a record that
  contradicts another); nothing compares documents with the code.
- **Audits the archive** for secret-shaped strings that redaction missed, and
  for values you already know are secret.
- **Keeps standing rules.** `ctx remember` records an instruction for future
  sessions, with an optional end date, and every scan imports each coding
  agent's instruction files (CLAUDE.md, AGENTS.md, GEMINI.md) and Claude Code's
  memory files as rules. Rules keep their history, sync, and can be replaced or
  retired.
- **Learns rules from what you say.** An instruction you give in two different
  sessions becomes a tentative rule, offered at the start of each session, and
  lapses 30 days after you last said it. `ctx rules` lists them,
  `ctx rules undo N` removes one, and `ctx rules proposed` holds the ones that
  wait for your yes.
- **Records decisions.** `ctx decisions` lists each question an agent asked you
  and your answer. After a compaction the agent is told where the session stood:
  questions still waiting, recent answers, messages from other sessions, and the
  pages it published. `ctx artifacts` lists every published page and the version
  you approved. `ctx page --open` gathers everything waiting on you into one
  page, and `ctx page apply` acts on the choices you hand back.
- **Tracks tickets** for each project, offered to agents at the start of a
  session.
- **Keeps sources with provenance.** Each source records where it came from, its
  hash, and how long it can be trusted. Sources are superseded, never edited.
- **Compiles a wiki** that refuses any claim it cannot trace to a literal quote
  in a pinned source version, and retires pages whose sources are gone.
- **Syncs** the private archive and project repositories with Fossil servers.

## Install

From a release archive, which is a Claude Code plugin with the binary, the skills
and the hooks:

```sh
tar xzf ctx-0.0.1-darwin-arm64.tar.gz
claude plugin marketplace add ./ctx-0.0.1-darwin-arm64
claude plugin install ctx@ctx
ln -s "$PWD/ctx-0.0.1-darwin-arm64/bin/ctx" ~/.local/bin/ctx
ctx init
ctx scan
```

Or build from source with a C compiler and zlib: `make`, then see
[docs/howto.md](docs/howto.md#install-from-source) for the hooks.

## Start

```sh
ctx search sync test hangs        # past sessions, this project first
ctx turn 1182 2 5                 # a turn with 2 before and 5 after
ctx audit                         # secret-shaped strings left in the archive
ctx project add myproj --clone ~/fossils/myproj.fossil   # this directory's project
ctx ticket new "Fix the importer"
```

[docs/howto.md](docs/howto.md) covers every task: projects, tickets, sources,
the wiki, syncing machines, rebuilding and measuring the skill.

[docs/benchmarks.md](docs/benchmarks.md) lists what ctx has been measured to do, with the
command behind each figure and the experiments that failed. [bench/head-to-head.md](bench/head-to-head.md)
is the plan, written before any run, for comparing ctx with other tools.

## How it is stored

Everything lives in `~/.ctx/ctx.sqlite` (or `$CTX_DB`), as SQLite tables and as
Fossil repositories held inside it:

- `repo:me` is your private repository. Each session is a technote, one per
  session per day, tagged with its project.
- Each project has a shared repository: sources are check-ins and the wiki is
  Markdown wiki pages.
- Tickets are in `repo:me` for now, each tagged with its project.
- The search index, citations and links are derived from the repositories.
  `ctx rebuild` drops and rebuilds them.

The schema is in `schema/`: `state.sql` holds what is kept, `index.sql` what is
derived, `ticket-table.sql` the ticket fields and `check.sql` checks for both.

## Building and checks

`make` builds `./ctx` from the SQLite and libfossil sources in `vendor/`, and
`make test` runs the suite. `make check` runs everything CI runs, and needs
python3 and sqlite3 as well:

- the suite, and the suite again under AddressSanitizer and
  UndefinedBehaviorSanitizer;
- a short fuzz of the redactor and the parsers, where a clang with libFuzzer
  exists;
- on Linux, the suite and every saved fuzz input under
  [Fil-C](https://fil-c.org), which makes any memory-safety error a crash
  (`tools/filc.sh` fetches a pinned release);
- the bench and schema checks.

## Releases

`make dist` builds a release archive for this machine in `build/dist/`.
`tools/dist-linux.sh [amd64|arm64]` builds a Linux one inside Ubuntu 22.04 under
docker, so it runs on glibc 2.34 or later; docker on an Apple Silicon Mac builds
both. `plugin/INSTALL.md` becomes the archive's README.

## Measuring

- `ctx stats` shows, per week and per project, how often agents really searched
  the archive, how often they found nothing, and how many sessions ran. With pic
  installed it ends with what pic measured its compaction on a cold resume to
  save.
- `ctx repeats` lists the shell commands agents run again and again, across
  sessions and projects, grouped by shape: candidates for a script or a check,
  so that agents stop rebuilding them each session.
- `eval/` measures the `ctx` skill against questions about past work, so a change
  to the skill is judged by results. See [eval/README.md](eval/README.md).
- `bench/` scores retrieval, grep against BM25, on pinned corpora. `bench/run.sh`
  reads them from `~/projects/ctx-corpora` (or `CTX_CORPORA`) and needs ripgrep
  and a `sqlite3` that can load extensions: on macOS, Homebrew's.

## License

BSD 2-Clause; see [LICENSE](LICENSE). The libfossil code in `vendor/libfossil`
is under its own BSD license, in `vendor/libfossil/LICENSE`. SQLite is in the
public domain.