claude-db 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +306 -0
- package/dist/capture/command.d.ts +20 -0
- package/dist/capture/command.js +81 -0
- package/dist/capture/flush.d.ts +20 -0
- package/dist/capture/flush.js +102 -0
- package/dist/capture/identity.d.ts +13 -0
- package/dist/capture/identity.js +26 -0
- package/dist/capture/index.d.ts +7 -0
- package/dist/capture/index.js +5 -0
- package/dist/capture/transcript.d.ts +41 -0
- package/dist/capture/transcript.js +160 -0
- package/dist/capture/turn-extractor.d.ts +13 -0
- package/dist/capture/turn-extractor.js +135 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +349 -0
- package/dist/cli/install.d.ts +40 -0
- package/dist/cli/install.js +156 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.js +2 -0
- package/dist/config/load.d.ts +11 -0
- package/dist/config/load.js +31 -0
- package/dist/config/schema.d.ts +28 -0
- package/dist/config/schema.js +66 -0
- package/dist/context.d.ts +22 -0
- package/dist/context.js +25 -0
- package/dist/embed/builtin.d.ts +20 -0
- package/dist/embed/builtin.js +66 -0
- package/dist/embed/embedder.d.ts +27 -0
- package/dist/embed/embedder.js +18 -0
- package/dist/embed/index.d.ts +15 -0
- package/dist/embed/index.js +39 -0
- package/dist/embed/local.d.ts +17 -0
- package/dist/embed/local.js +41 -0
- package/dist/hooks/payload.d.ts +21 -0
- package/dist/hooks/payload.js +33 -0
- package/dist/hooks/relevance.d.ts +20 -0
- package/dist/hooks/relevance.js +84 -0
- package/dist/hooks/session-end.d.ts +2 -0
- package/dist/hooks/session-end.js +35 -0
- package/dist/hooks/session-start.d.ts +2 -0
- package/dist/hooks/session-start.js +46 -0
- package/dist/hooks/user-prompt.d.ts +2 -0
- package/dist/hooks/user-prompt.js +56 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +5 -0
- package/dist/mcp/server.d.ts +8 -0
- package/dist/mcp/server.js +87 -0
- package/dist/search/index.d.ts +2 -0
- package/dist/search/index.js +2 -0
- package/dist/search/rank.d.ts +17 -0
- package/dist/search/rank.js +43 -0
- package/dist/search/service.d.ts +44 -0
- package/dist/search/service.js +78 -0
- package/dist/store/adapter.d.ts +47 -0
- package/dist/store/adapter.js +1 -0
- package/dist/store/index.d.ts +14 -0
- package/dist/store/index.js +39 -0
- package/dist/store/mongo/driver.d.ts +44 -0
- package/dist/store/mongo/driver.js +28 -0
- package/dist/store/mongo/index.d.ts +36 -0
- package/dist/store/mongo/index.js +275 -0
- package/dist/store/postgres/index.d.ts +30 -0
- package/dist/store/postgres/index.js +289 -0
- package/dist/store/sqlite/index.d.ts +30 -0
- package/dist/store/sqlite/index.js +309 -0
- package/dist/store/sqlite/schema.sql +61 -0
- package/dist/types.d.ts +55 -0
- package/dist/types.js +5 -0
- package/dist/util/project.d.ts +14 -0
- package/dist/util/project.js +24 -0
- package/dist/util/scope.d.ts +10 -0
- package/dist/util/scope.js +17 -0
- package/dist/util/shortid.d.ts +11 -0
- package/dist/util/shortid.js +36 -0
- package/dist/util/vector.d.ts +5 -0
- package/dist/util/vector.js +17 -0
- package/dist/util/warnings.d.ts +12 -0
- package/dist/util/warnings.js +27 -0
- package/package.json +96 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Kishan Lal Rai
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
<img src="./assets/wordmark.svg" alt="claude-db" width="330">
|
|
2
|
+
|
|
3
|
+
**Persistent memory for Claude Code. Bring your own database.**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/claude-db)
|
|
6
|
+
[](https://github.com/Avijit07x/claude-db/actions/workflows/ci.yml)
|
|
7
|
+
[](./LICENSE)
|
|
8
|
+
[](https://nodejs.org)
|
|
9
|
+
|
|
10
|
+
Your agent forgets everything when a session ends. You re-explain the
|
|
11
|
+
architecture, why you chose X over Y, and which approaches already failed.
|
|
12
|
+
|
|
13
|
+
claude-db records that as it happens and gives it back on the next session.
|
|
14
|
+
No hosted service, no subscription, no account, no database URL required.
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install -g claude-db
|
|
18
|
+
cd your-project
|
|
19
|
+
claude-db install --project
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Restart Claude Code. Done.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## What it actually remembers
|
|
27
|
+
|
|
28
|
+
Most memory tools capture file paths, because that is all a tool hook can see.
|
|
29
|
+
claude-db reads the session transcript, so it captures **intent and reasoning**:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
[decision] Chose WebSocket over polling for live order updates
|
|
33
|
+
|
|
34
|
+
Asked: the plan was not good, the output was really bad, it should
|
|
35
|
+
feel hand made not ai
|
|
36
|
+
|
|
37
|
+
Polling at 3s hammered the API and still lagged behind. Switched to a
|
|
38
|
+
WebSocket subscription with exponential backoff reconnect and a replay
|
|
39
|
+
flag so no order is missed during a drop.
|
|
40
|
+
|
|
41
|
+
Files: src/ws/client.ts, src/ws/reconnect.ts
|
|
42
|
+
Ran: Test run: pnpm test
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Compare that with what a file-watching approach stores: `Write client.ts`.
|
|
46
|
+
|
|
47
|
+
The prompt is the only record of *what you wanted*. The agent's reply is the
|
|
48
|
+
only record of *why it did that*. Both exist in the transcript, and nowhere
|
|
49
|
+
else.
|
|
50
|
+
|
|
51
|
+
## Recall is automatic, not left to the model
|
|
52
|
+
|
|
53
|
+
| Moment | Who decides | Reliability |
|
|
54
|
+
| ---------------- | --------------------- | ------------- |
|
|
55
|
+
| Capture | hook, unconditional | always |
|
|
56
|
+
| Session start | hook, unconditional | always |
|
|
57
|
+
| **Every prompt** | **hook, if relevant** | **always** |
|
|
58
|
+
| Mid-conversation | the agent, via MCP | its judgment |
|
|
59
|
+
|
|
60
|
+
Exposing search as a tool and hoping the agent calls it is unreliable.
|
|
61
|
+
`UserPromptSubmit` searches with your prompt text and injects the best match
|
|
62
|
+
in full, so the reasoning is already in context before the agent decides
|
|
63
|
+
anything.
|
|
64
|
+
|
|
65
|
+
Three things keep this cheap and quiet:
|
|
66
|
+
|
|
67
|
+
- **Trivial prompts are rejected before any query runs.** "ok", "continue",
|
|
68
|
+
"thanks" cost 43ms and inject nothing.
|
|
69
|
+
- **A relevance floor suppresses noise.** Nearest-neighbour search always
|
|
70
|
+
returns its top k however poor the match, so anything below the embedder's
|
|
71
|
+
measured noise floor is dropped. An unrelated prompt injects nothing at all.
|
|
72
|
+
- **A character budget caps the block.**
|
|
73
|
+
|
|
74
|
+
Measured: about **350 tokens** on a prompt with relevant history, **0** on one
|
|
75
|
+
without, 114ms of latency.
|
|
76
|
+
|
|
77
|
+
## Works fully local, out of the box
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
$ claude-db doctor
|
|
81
|
+
database : ~/.claude-memory/memory.db
|
|
82
|
+
adapter : sqlite
|
|
83
|
+
reachable: yes
|
|
84
|
+
embedder : builtin-hashing (256d)
|
|
85
|
+
vectors : working (256d)
|
|
86
|
+
search : hybrid (keyword + vector)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
No connection string, no config file, no model download, no network. SQLite
|
|
90
|
+
comes from Node's builtin `node:sqlite`, so there is no native compilation
|
|
91
|
+
step and nothing to fail at install time.
|
|
92
|
+
|
|
93
|
+
## Bring your own database
|
|
94
|
+
|
|
95
|
+
Only needed if you want memory shared across machines. The connection string
|
|
96
|
+
picks the backend; nothing else changes.
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
claude-db use "mongodb+srv://user:pass@cluster.mongodb.net/memory"
|
|
100
|
+
claude-db use "postgres://user:pass@host:5432/memory"
|
|
101
|
+
claude-db use "~/.claude-memory/memory.db" # SQLite, the default
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Or set `CLAUDE_DB_URL`, which overrides the config file so containers and CI
|
|
105
|
+
can share a database without editing anything on disk.
|
|
106
|
+
|
|
107
|
+
| Backend | Keyword search | Vector search | Setup |
|
|
108
|
+
| -------- | ---------------- | -------------------------------------- | ------------------------ |
|
|
109
|
+
| SQLite | FTS5 + bm25 | exact cosine, in process | none, builtin to Node |
|
|
110
|
+
| MongoDB | text index | Atlas `$vectorSearch`, else in process | any Mongo, Atlas not req |
|
|
111
|
+
| Postgres | tsvector/ts_rank | pgvector HNSW when available | any Postgres |
|
|
112
|
+
|
|
113
|
+
Every adapter implements one small interface. Ranking, fusion and token
|
|
114
|
+
budgeting live outside the adapters, so recall behaves identically no matter
|
|
115
|
+
what you plug in. Only the retrieval cost changes.
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
npm install mongodb # only if you use a mongodb:// URL
|
|
119
|
+
npm install pg # only if you use a postgres:// URL
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Multiple projects
|
|
123
|
+
|
|
124
|
+
One database, partitioned by the project's canonical absolute path.
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
$ claude-db projects
|
|
128
|
+
* 412 2026-08-15 /Users/you/work/animateicons
|
|
129
|
+
87 2026-08-14 /Users/you/work/shop-api
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Searches only ever see one row. The project token is indexed inside FTS rather
|
|
133
|
+
than applied as a post-match filter, so adding a project costs the others
|
|
134
|
+
nothing.
|
|
135
|
+
|
|
136
|
+
Two limits worth knowing: opening Claude Code in `~/repo` and
|
|
137
|
+
`~/repo/packages/web` creates two separate memories, so install at the repo
|
|
138
|
+
root. And moving a project orphans its memory, since the path is the key;
|
|
139
|
+
`claude-db flush` rebuilds it.
|
|
140
|
+
|
|
141
|
+
## Commands
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
claude-db install [--project] register hooks + MCP server
|
|
145
|
+
claude-db uninstall [--project] remove them, leaving memory intact
|
|
146
|
+
claude-db status is it wired up, has it recorded anything
|
|
147
|
+
claude-db doctor resolved config and connectivity
|
|
148
|
+
claude-db use <url> switch database and verify it
|
|
149
|
+
claude-db search <query> search this project's memory
|
|
150
|
+
claude-db projects every project with memory
|
|
151
|
+
claude-db flush re-ingest every transcript for this project
|
|
152
|
+
claude-db reset [--project] --yes delete memory (dry run without --yes)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
`cdb` is a shorter alias for all of the above.
|
|
156
|
+
|
|
157
|
+
`--project` scopes to one repo via `.claude/settings.local.json` and
|
|
158
|
+
`.mcp.json`, instead of every project on the machine. Add `.mcp.json` to your
|
|
159
|
+
`.gitignore`: it holds an absolute path that would break for teammates.
|
|
160
|
+
|
|
161
|
+
## The part worth stealing: progressive disclosure
|
|
162
|
+
|
|
163
|
+
Naive memory search returns whole records and burns thousands of tokens on
|
|
164
|
+
results the agent throws away. Retrieval here is split into three layers, so
|
|
165
|
+
the agent pays for detail only after deciding what is relevant.
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
search() compact index, ~50-100 tokens per hit, no bodies
|
|
169
|
+
timeline() chronological neighbours of a promising hit
|
|
170
|
+
get_observations() full bodies, only for hand-picked ids
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Filter at layer 1, expand at layer 3. That is where the roughly 10x saving
|
|
174
|
+
comes from. These are exposed as three MCP tools whose descriptions state the
|
|
175
|
+
intended order, because the saving only materialises if the agent filters
|
|
176
|
+
before fetching.
|
|
177
|
+
|
|
178
|
+
### Hybrid ranking
|
|
179
|
+
|
|
180
|
+
Keyword scores (bm25, ts_rank) and vector scores (cosine) live on
|
|
181
|
+
incompatible scales, so normalising one against the other is guesswork.
|
|
182
|
+
claude-db uses Reciprocal Rank Fusion instead: it discards magnitudes and
|
|
183
|
+
fuses on rank position alone, which needs no per-backend tuning. A mild
|
|
184
|
+
recency boost follows, 45-day half life with a floor, so a recent decision
|
|
185
|
+
edges out an equally relevant old one without burying it.
|
|
186
|
+
|
|
187
|
+
## Privacy
|
|
188
|
+
|
|
189
|
+
Nothing leaves your machine unless you point it at a remote database.
|
|
190
|
+
|
|
191
|
+
- Paths matching `capture.exclude` (`.env`, `secrets`, `node_modules`,
|
|
192
|
+
`.git/`) are never persisted
|
|
193
|
+
- Text wrapped in `<private>...</private>` is stripped before storage
|
|
194
|
+
- API keys, GitHub tokens and `password`/`secret`/`token` values are redacted
|
|
195
|
+
by pattern before anything is written
|
|
196
|
+
|
|
197
|
+
Embeddings are computed locally in both modes. There is no API key, no
|
|
198
|
+
per-token cost, and no path that sends your code to a third party.
|
|
199
|
+
|
|
200
|
+
## Embedding providers
|
|
201
|
+
|
|
202
|
+
| Provider | Install cost | What it catches |
|
|
203
|
+
| --------- | -------------- | -------------------------------------------------- |
|
|
204
|
+
| `auto` | none | default: tries `local`, falls back to `builtin` |
|
|
205
|
+
| `builtin` | none | morphology and typos: `reconnect` ~ `reconnecting` |
|
|
206
|
+
| `local` | ~25MB download | real semantics: `car` ~ `automobile` |
|
|
207
|
+
| `none` | none | keyword only |
|
|
208
|
+
|
|
209
|
+
The builtin embedder uses the hashing trick over word and character trigrams.
|
|
210
|
+
Being honest about it: that is lexical similarity, not meaning. It will match
|
|
211
|
+
`reconnect` to `reconnecting` where FTS5 token matching fails, but it will not
|
|
212
|
+
match `car` to `automobile`. It exists so a zero-config install gets fuzzy
|
|
213
|
+
recall rather than nothing.
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
npm install @xenova/transformers # upgrade to real sentence embeddings
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
`auto` probes the model with a real inference call, so a broken ONNX runtime
|
|
220
|
+
degrades silently instead of failing.
|
|
221
|
+
|
|
222
|
+
## Configuration
|
|
223
|
+
|
|
224
|
+
Everything is optional. These are the defaults with no file present.
|
|
225
|
+
|
|
226
|
+
`~/.claude-memory/config.json`:
|
|
227
|
+
|
|
228
|
+
```json
|
|
229
|
+
{
|
|
230
|
+
"database": "",
|
|
231
|
+
"embeddings": { "provider": "auto", "maxScanCandidates": 25000 },
|
|
232
|
+
"capture": {
|
|
233
|
+
"tools": ["Edit", "Write", "Bash", "NotebookEdit"],
|
|
234
|
+
"exclude": [".env", "secrets", "node_modules", ".git/"],
|
|
235
|
+
"maxBodyChars": 4000
|
|
236
|
+
},
|
|
237
|
+
"inject": {
|
|
238
|
+
"sessions": 5,
|
|
239
|
+
"maxChars": 6000,
|
|
240
|
+
"perPrompt": true,
|
|
241
|
+
"promptResults": 4,
|
|
242
|
+
"promptMaxChars": 500,
|
|
243
|
+
"expandTop": 1,
|
|
244
|
+
"expandMaxChars": 900
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Set `inject.perPrompt` to `false` for tool-only recall.
|
|
250
|
+
|
|
251
|
+
## How it works
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
SessionStart inject summaries of recent sessions
|
|
255
|
+
UserPromptSubmit flush the previous turn, then inject relevant memory
|
|
256
|
+
SessionEnd final flush and close
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
Memory is written **on every prompt**, not only at session end. A prompt is
|
|
260
|
+
the moment the previous turn is provably finished, and it is the one event
|
|
261
|
+
guaranteed to fire while a session is alive. Sessions that crash, are
|
|
262
|
+
force-quit, or stay open for days never reach `SessionEnd`.
|
|
263
|
+
|
|
264
|
+
That is only safe because observation ids are content-derived
|
|
265
|
+
(`sha256(session + turn timestamp + prompt)`), so re-reading a turn rewrites
|
|
266
|
+
the same row instead of appending a duplicate. A byte cursor per session means
|
|
267
|
+
each flush parses only the new tail, which matters because these transcripts
|
|
268
|
+
reach 90MB.
|
|
269
|
+
|
|
270
|
+
## Failure behaviour
|
|
271
|
+
|
|
272
|
+
A memory layer that breaks your session is worse than one that forgets, so
|
|
273
|
+
degradation is deliberate and tested:
|
|
274
|
+
|
|
275
|
+
- A hook that throws logs to stderr and exits 0. It never fails your session.
|
|
276
|
+
- If the sentence-transformer is unavailable, `auto` falls back to the builtin
|
|
277
|
+
and hybrid search keeps working.
|
|
278
|
+
- If embedding fails outright, observations are still persisted.
|
|
279
|
+
- If a backend cannot do vector search, fusion proceeds with keyword results.
|
|
280
|
+
|
|
281
|
+
## Requirements
|
|
282
|
+
|
|
283
|
+
Node 22.5 or newer. That is the only hard requirement. `mongodb`, `pg` and
|
|
284
|
+
`@xenova/transformers` are optional peers, loaded lazily, only if you opt in.
|
|
285
|
+
|
|
286
|
+
## Development
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
git clone https://github.com/Avijit07x/claude-db
|
|
290
|
+
cd claude-db
|
|
291
|
+
npm install
|
|
292
|
+
npm run build
|
|
293
|
+
npm test # 87 checks
|
|
294
|
+
npm run try # simulate a session end to end, touches nothing
|
|
295
|
+
npm run bench # scaling curve
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
CI runs on Node 22 and 24, on Linux and macOS. macOS is not optional there:
|
|
299
|
+
`/tmp` is a symlink to `/private/tmp`, which is exactly the case that once
|
|
300
|
+
split a single project's memory in two.
|
|
301
|
+
|
|
302
|
+
See [RELEASING.md](./RELEASING.md) for the publish process.
|
|
303
|
+
|
|
304
|
+
## License
|
|
305
|
+
|
|
306
|
+
Apache-2.0
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ObservationKind } from '../types.js';
|
|
2
|
+
export interface CommandClassification {
|
|
3
|
+
kind: ObservationKind;
|
|
4
|
+
/** Short human label used as the observation title. */
|
|
5
|
+
label: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Decides whether a shell command is worth remembering.
|
|
9
|
+
*
|
|
10
|
+
* Agents run far more commands to *look* than to *change*, and the looking is
|
|
11
|
+
* worthless later: nobody needs to recall that you grepped for easing curves
|
|
12
|
+
* three weeks ago. Capturing it crowds out the handful that genuinely mattered.
|
|
13
|
+
*
|
|
14
|
+
* So this is an allowlist of consequential operations rather than a blocklist
|
|
15
|
+
* of exploration. Exploration is unbounded in variety and impossible to
|
|
16
|
+
* enumerate; the operations that change project state are a short, stable list.
|
|
17
|
+
*
|
|
18
|
+
* Returns null for anything unrecognised, which means "do not store".
|
|
19
|
+
*/
|
|
20
|
+
export declare function classifyCommand(command: string): CommandClassification | null;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decides whether a shell command is worth remembering.
|
|
3
|
+
*
|
|
4
|
+
* Agents run far more commands to *look* than to *change*, and the looking is
|
|
5
|
+
* worthless later: nobody needs to recall that you grepped for easing curves
|
|
6
|
+
* three weeks ago. Capturing it crowds out the handful that genuinely mattered.
|
|
7
|
+
*
|
|
8
|
+
* So this is an allowlist of consequential operations rather than a blocklist
|
|
9
|
+
* of exploration. Exploration is unbounded in variety and impossible to
|
|
10
|
+
* enumerate; the operations that change project state are a short, stable list.
|
|
11
|
+
*
|
|
12
|
+
* Returns null for anything unrecognised, which means "do not store".
|
|
13
|
+
*/
|
|
14
|
+
export function classifyCommand(command) {
|
|
15
|
+
// Agents chain aggressively: `pnpm lint; echo "==="; git status`. Classifying
|
|
16
|
+
// the raw string stores the whole chain as one title, most of which is
|
|
17
|
+
// exploration. Split first, then label only the segment that qualified.
|
|
18
|
+
for (const segment of splitSegments(command)) {
|
|
19
|
+
for (const rule of RULES) {
|
|
20
|
+
if (rule.pattern.test(segment)) {
|
|
21
|
+
return { kind: rule.kind, label: `${rule.prefix}: ${truncate(segment, 64)}` };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
/** Splits on shell separators, keeping each simple command intact. */
|
|
28
|
+
function splitSegments(command) {
|
|
29
|
+
return command
|
|
30
|
+
.split(/(?:\|\||&&|[;\n|])/)
|
|
31
|
+
.map((segment) => segment.trim().replace(/\s+/g, ' '))
|
|
32
|
+
.filter((segment) => segment.length > 0);
|
|
33
|
+
}
|
|
34
|
+
/** Optional leading `cd foo &&`-style noise is already stripped by splitting. */
|
|
35
|
+
const PM = '(?:npm|pnpm|yarn|bun|npx)';
|
|
36
|
+
/**
|
|
37
|
+
* Every pattern is anchored to the start of a segment so a bare word inside a
|
|
38
|
+
* filename cannot match. `sed -n '1,50p' test.ts` is exploration; `pnpm test`
|
|
39
|
+
* is not, and only anchoring tells them apart.
|
|
40
|
+
*/
|
|
41
|
+
const RULES = [
|
|
42
|
+
{
|
|
43
|
+
pattern: new RegExp(`^${PM} (?:install|add|remove|uninstall|ci)\\b`, 'i'),
|
|
44
|
+
kind: 'decision',
|
|
45
|
+
prefix: 'Dependency change',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
pattern: new RegExp(`^(?:${PM} (?:run )?)?(?:test|jest|vitest|pytest|playwright)(?:\\s|$)`, 'i'),
|
|
49
|
+
kind: 'bugfix',
|
|
50
|
+
prefix: 'Test run',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
pattern: new RegExp(`^(?:${PM} (?:run )?)?(?:build|tsc|typecheck|lint)(?:\\s|$)`, 'i'),
|
|
54
|
+
kind: 'context',
|
|
55
|
+
prefix: 'Build',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
pattern: /^git (?:commit|merge|rebase|revert|cherry-pick|tag)\b/i,
|
|
59
|
+
kind: 'decision',
|
|
60
|
+
prefix: 'Git',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
pattern: /^git reset --hard\b/i,
|
|
64
|
+
kind: 'decision',
|
|
65
|
+
prefix: 'Git',
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
pattern: /^(?:npx )?(?:prisma|drizzle-kit|knex|alembic|rails)\s+(?:migrate|db|migration)\b/i,
|
|
69
|
+
kind: 'decision',
|
|
70
|
+
prefix: 'Migration',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
pattern: /^(?:docker|docker-compose|kubectl|terraform|vercel|wrangler|fly)\s+(?!(?:ps|logs|status|get|describe|version|list|ls)\b)\S+/i,
|
|
74
|
+
kind: 'context',
|
|
75
|
+
prefix: 'Infra',
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
function truncate(text, max) {
|
|
79
|
+
const clean = text.trim();
|
|
80
|
+
return clean.length <= max ? clean : `${clean.slice(0, max)}...`;
|
|
81
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RecallContext } from '../context.js';
|
|
2
|
+
export interface FlushResult {
|
|
3
|
+
observations: number;
|
|
4
|
+
summary: string | null;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Persists everything new in a session's transcript.
|
|
8
|
+
*
|
|
9
|
+
* Gating all writes on SessionEnd was the original design and it loses data
|
|
10
|
+
* constantly: a session that is force-quit, crashes, or simply stays open for
|
|
11
|
+
* days never reaches the hook, so its memory is never written. A session left
|
|
12
|
+
* open for two weeks produced hundreds of observations under one id and none
|
|
13
|
+
* of them searchable until it finally closed.
|
|
14
|
+
*
|
|
15
|
+
* Flushing incrementally removes that dependency entirely. It is only safe
|
|
16
|
+
* because observation ids are content-derived: re-reading a turn rewrites the
|
|
17
|
+
* same row rather than appending a duplicate.
|
|
18
|
+
*/
|
|
19
|
+
export declare function flushSession(ctx: RecallContext, sessionId: string, project: string, transcriptPath?: string): Promise<FlushResult>;
|
|
20
|
+
export declare function resetCursor(sessionId: string): void;
|