opencode-claude-memory 0.1.0 → 1.0.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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +128 -83
  3. package/package.json +1 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 kuitos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,19 +1,71 @@
1
- # opencode-memory
1
+ <div align="center">
2
2
 
3
- Cross-session memory plugin for [OpenCode](https://opencode.ai) — **fully compatible with Claude Code's memory format**.
3
+ # 🧠 opencode-claude-memory
4
4
 
5
- Claude Code writes memories OpenCode reads them.
6
- OpenCode writes memories → Claude Code reads them.
5
+ **A 1:1 replica of [Claude Code's memory system](https://github.com/anthropics/claude-code) for OpenCode**
7
6
 
8
- ## Features
7
+ *Ported from the original source — same paths, same format, same tools, same prompts. Zero drift.*
9
8
 
10
- - **5 tools**: `memory_save`, `memory_delete`, `memory_list`, `memory_search`, `memory_read`
11
- - **Claude Code compatible**: shares the same `~/.claude/projects/<project>/memory/` directory
12
- - **Auto-extraction**: shell wrapper that automatically extracts memories after each session
13
- - **System prompt injection**: existing memories are injected into every conversation
14
- - **4 memory types**: `user`, `feedback`, `project`, `reference` (same taxonomy as Claude Code)
9
+ Claude Code writes memories OpenCode reads them. OpenCode writes memories → Claude Code reads them.
15
10
 
16
- ## Quick Start
11
+ [![npm version](https://img.shields.io/npm/v/opencode-claude-memory.svg?style=flat-square)](https://www.npmjs.com/package/opencode-claude-memory)
12
+ [![npm downloads](https://img.shields.io/npm/dm/opencode-claude-memory.svg?style=flat-square)](https://www.npmjs.com/package/opencode-claude-memory)
13
+ [![License](https://img.shields.io/npm/l/opencode-claude-memory.svg?style=flat-square)](https://github.com/kuitos/opencode-claude-memory/blob/main/LICENSE)
14
+
15
+ [Features](#-features) • [Quick Start](#-quick-start) • [How It Works](#-how-it-works) • [Configuration](#%EF%B8%8F-configuration) • [Tools Reference](#-tools-reference)
16
+
17
+ </div>
18
+
19
+ ---
20
+
21
+ ## ✨ Features
22
+
23
+ <table>
24
+ <tr>
25
+ <td width="50%">
26
+
27
+ ### 🔄 Claude Code Compatible
28
+ Shares the exact same `~/.claude/projects/<project>/memory/` directory — bidirectional sync out of the box
29
+
30
+ </td>
31
+ <td width="50%">
32
+
33
+ ### 🛠️ 5 Memory Tools
34
+ `memory_save`, `memory_delete`, `memory_list`, `memory_search`, `memory_read`
35
+
36
+ </td>
37
+ </tr>
38
+ <tr>
39
+ <td width="50%">
40
+
41
+ ### ⚡ Auto-Extraction
42
+ Drop-in `opencode` wrapper that extracts memories in the background after each session
43
+
44
+ </td>
45
+ <td width="50%">
46
+
47
+ ### 💉 System Prompt Injection
48
+ Existing memories are automatically injected into every conversation
49
+
50
+ </td>
51
+ </tr>
52
+ <tr>
53
+ <td width="50%">
54
+
55
+ ### 📁 4 Memory Types
56
+ `user`, `feedback`, `project`, `reference` — same taxonomy as Claude Code
57
+
58
+ </td>
59
+ <td width="50%">
60
+
61
+ ### 🌳 Git Worktree Aware
62
+ Worktrees of the same repo share the same memory directory
63
+
64
+ </td>
65
+ </tr>
66
+ </table>
67
+
68
+ ## 🚀 Quick Start
17
69
 
18
70
  ### 1. Install
19
71
 
@@ -21,16 +73,11 @@ OpenCode writes memories → Claude Code reads them.
21
73
  npm install -g opencode-claude-memory
22
74
  ```
23
75
 
24
- This does two things:
25
-
26
- - Registers the **plugin** (memory tools + system prompt injection)
27
- - Places an `opencode` **wrapper** in your global bin that auto-extracts memories after each session
28
-
29
- > The wrapper is a drop-in replacement — it finds the real `opencode` binary in `PATH`, runs it normally, then triggers memory extraction in the background when you exit.
76
+ This installs:
77
+ - The **plugin** — memory tools + system prompt injection
78
+ - An `opencode` **wrapper** auto-extracts memories after each session
30
79
 
31
- ### 2. Configure the plugin
32
-
33
- Add the plugin to your `opencode.json`:
80
+ ### 2. Configure
34
81
 
35
82
  ```jsonc
36
83
  // opencode.json
@@ -41,62 +88,85 @@ Add the plugin to your `opencode.json`:
41
88
 
42
89
  ### 3. Use
43
90
 
44
- Just run `opencode` as usual. The memory tools are available to the AI agent:
91
+ ```bash
92
+ opencode # just use it as usual
93
+ ```
94
+
95
+ The AI agent can now use memory tools:
45
96
 
46
97
  - **"Remember that I prefer terse responses"** → saves a `feedback` memory
47
98
  - **"What do you remember about me?"** → reads from memory
48
99
  - **"Forget the memory about my role"** → deletes a memory
49
100
 
50
- When you exit a session, memories are automatically extracted in the background.
101
+ When you exit, memories are extracted in the background — zero blocking.
51
102
 
52
- ### Uninstall
103
+ <details>
104
+ <summary>🗑️ Uninstall</summary>
53
105
 
54
106
  ```bash
55
107
  npm uninstall -g opencode-claude-memory
56
108
  ```
57
109
 
58
- This removes both the wrapper and the plugin. Your saved memories in `~/.claude/projects/` are **not** deleted.
110
+ This removes the wrapper and the plugin. Your saved memories in `~/.claude/projects/` are **not** deleted.
111
+
112
+ </details>
59
113
 
60
- ## Auto-Extraction
114
+ ## 💡 How It Works
61
115
 
62
- The wrapper:
116
+ ```mermaid
117
+ graph LR
118
+ A[You run opencode] --> B[Wrapper finds real binary]
119
+ B --> C[Runs opencode normally]
120
+ C --> D[You exit]
121
+ D --> E[Get latest session ID]
122
+ E --> F[Fork session + extract memories]
123
+ F --> G[Memories saved to ~/.claude/projects/]
124
+ ```
63
125
 
64
- 1. Finds the real `opencode` binary (skips itself in `PATH`)
65
- 2. Runs it normally with all your arguments
66
- 3. After you exit, finds the most recent session
67
- 4. Forks that session and sends a memory extraction prompt
68
- 5. The extraction runs **in the background** — you're never blocked
126
+ The wrapper is a drop-in replacement that:
69
127
 
70
- ### How it works
128
+ 1. Scans `PATH` to find the real `opencode` binary (skipping itself)
129
+ 2. Runs it with all your arguments
130
+ 3. After you exit, forks the session with a memory extraction prompt
131
+ 4. Extraction runs **in the background** — you're never blocked
71
132
 
72
- ```
73
- You run `opencode`
74
- wrapper finds real opencode binary (skipping itself in PATH)
75
- → runs real opencode with your arguments
76
- you exit
77
- → opencode session list --format json -n 1 (get last session)
78
- opencode run -s <id> --fork "<extraction prompt>" (background)
79
- memories saved to ~/.claude/projects/<project>/memory/
80
- ```
133
+ ### What "1:1 Replica" Means
134
+
135
+ Every core component is ported directly from [Claude Code's source](https://github.com/anthropics/claude-code):
136
+
137
+ | Component | Source |
138
+ |---|---|
139
+ | `sanitizePath()` + `djb2Hash()` | `utils/sessionStoragePortable.ts` |
140
+ | `findGitRoot()` + worktree resolution | `utils/git.ts` |
141
+ | Memory types & frontmatter format | `commands/memory.ts` |
142
+ | System prompt (types, when to save/skip) | `commands/memory.ts` |
143
+ | Extraction prompt (post-session) | Claude Code's memory extraction agent |
144
+
145
+ This ensures:
146
+ - `~/.claude/projects/<sanitized>/memory/` paths are **byte-identical** to Claude Code's output
147
+ - Git worktrees resolve to the same canonical root
148
+ - Memory files are interchangeable — no migration needed
149
+
150
+ ## ⚙️ Configuration
81
151
 
82
- ### Environment variables
152
+ ### Environment Variables
83
153
 
84
154
  | Variable | Default | Description |
85
155
  |---|---|---|
86
156
  | `OPENCODE_MEMORY_EXTRACT` | `1` | Set to `0` to disable auto-extraction |
87
157
  | `OPENCODE_MEMORY_FOREGROUND` | `0` | Set to `1` to run extraction in foreground (debugging) |
88
- | `OPENCODE_MEMORY_MODEL` | *(default)* | Override model for extraction (e.g., `anthropic/claude-sonnet-4-20250514`) |
158
+ | `OPENCODE_MEMORY_MODEL` | *(default)* | Override model for extraction |
89
159
  | `OPENCODE_MEMORY_AGENT` | *(default)* | Override agent for extraction |
90
160
 
91
161
  ### Logs
92
162
 
93
163
  Extraction logs are written to `$TMPDIR/opencode-memory-logs/extract-*.log`.
94
164
 
95
- ### Concurrency safety
165
+ ### Concurrency Safety
96
166
 
97
167
  A file lock prevents multiple extractions from running simultaneously on the same project. Stale locks (from crashed processes) are automatically cleaned up.
98
168
 
99
- ## Memory Format
169
+ ## 📝 Memory Format
100
170
 
101
171
  Each memory is a Markdown file with YAML frontmatter:
102
172
 
@@ -113,7 +183,7 @@ Skip post-action summaries. User reads diffs directly.
113
183
  **How to apply:** Don't summarize changes at the end of responses.
114
184
  ```
115
185
 
116
- ### Memory types
186
+ ### Memory Types
117
187
 
118
188
  | Type | Description |
119
189
  |---|---|
@@ -122,44 +192,19 @@ Skip post-action summaries. User reads diffs directly.
122
192
  | `project` | Ongoing work context not derivable from code |
123
193
  | `reference` | Pointers to external resources |
124
194
 
125
- ### Index file
195
+ <details>
196
+ <summary>📄 Index file (MEMORY.md)</summary>
126
197
 
127
- `MEMORY.md` is an index (not content storage). Each entry is one line:
198
+ `MEMORY.md` is an auto-managed index (not content storage). Each entry is one line:
128
199
 
129
200
  ```markdown
130
201
  - [User prefers terse responses](feedback_terse_responses.md) — Skip summaries, user reads diffs
131
202
  - [User is a data scientist](user_role.md) — Focus on observability/logging context
132
203
  ```
133
204
 
134
- ## Claude Code Compatibility
135
-
136
- This plugin uses the **exact same path algorithm** as Claude Code:
137
-
138
- 1. Find the canonical git root (resolves worktrees to their main repo)
139
- 2. Sanitize the path with `sanitizePath()` (Claude Code's algorithm, including `djb2Hash` for long paths)
140
- 3. Store in `~/.claude/projects/<sanitized>/memory/`
141
-
142
- This means:
143
- - Git worktrees of the same repo share the same memory directory
144
- - The sanitized path matches Claude Code's output exactly
145
- - Memory files use the same frontmatter format and type taxonomy
146
-
147
- ## File Structure
148
-
149
- ```
150
- opencode-memory/
151
- ├── bin/
152
- │ └── opencode # Drop-in wrapper (finds real binary, adds memory extraction)
153
- ├── src/
154
- │ ├── index.ts # Plugin entry point (tools + hooks)
155
- │ ├── memory.ts # Memory CRUD operations
156
- │ ├── paths.ts # Claude-compatible path resolution
157
- │ └── prompt.ts # System prompt injection
158
- ├── package.json
159
- └── tsconfig.json
160
- ```
205
+ </details>
161
206
 
162
- ## Tools Reference
207
+ ## 🔧 Tools Reference
163
208
 
164
209
  ### `memory_save`
165
210
 
@@ -167,11 +212,11 @@ Save or update a memory.
167
212
 
168
213
  | Parameter | Type | Required | Description |
169
214
  |---|---|---|---|
170
- | `file_name` | string | yes | File name slug (e.g., `user_role`) |
171
- | `name` | string | yes | Short title |
172
- | `description` | string | yes | One-line description for relevance matching |
173
- | `type` | enum | yes | `user`, `feedback`, `project`, or `reference` |
174
- | `content` | string | yes | Memory content |
215
+ | `file_name` | string | | File name slug (e.g., `user_role`) |
216
+ | `name` | string | | Short title |
217
+ | `description` | string | | One-line description for relevance matching |
218
+ | `type` | enum | | `user`, `feedback`, `project`, or `reference` |
219
+ | `content` | string | | Memory content |
175
220
 
176
221
  ### `memory_delete`
177
222
 
@@ -189,6 +234,6 @@ Search memories by keyword across name, description, and content.
189
234
 
190
235
  Read the full content of a specific memory file.
191
236
 
192
- ## License
237
+ ## 📄 License
193
238
 
194
- MIT
239
+ [MIT](LICENSE) © [kuitos](https://github.com/kuitos)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-claude-memory",
3
- "version": "0.1.0",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "description": "Cross-session memory plugin for OpenCode — Claude Code compatible, persistent, file-based memory",
6
6
  "main": "src/index.ts",