claude-smart 0.1.2 → 0.1.3
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/README.md +51 -186
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="assets/claude-smart-icon.png" alt="claude-smart" width="140">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
1
5
|
<h1 align="center">
|
|
2
|
-
<br>
|
|
3
6
|
claude-smart
|
|
4
|
-
<br>
|
|
5
7
|
</h1>
|
|
6
8
|
|
|
7
9
|
<h4 align="center">Self-improving <a href="https://claude.com/claude-code" target="_blank">Claude Code</a> plugin — learns from your corrections, not just remembers them.</h4>
|
|
@@ -16,7 +18,7 @@
|
|
|
16
18
|
<a href="pyproject.toml">
|
|
17
19
|
<img src="https://img.shields.io/badge/python-%3E%3D3.12-brightgreen.svg" alt="Python">
|
|
18
20
|
</a>
|
|
19
|
-
<a href="#
|
|
21
|
+
<a href="#quick-start">
|
|
20
22
|
<img src="https://img.shields.io/badge/llm-claude%20code%20cli-purple.svg" alt="LLM">
|
|
21
23
|
</a>
|
|
22
24
|
</p>
|
|
@@ -24,8 +26,8 @@
|
|
|
24
26
|
<p align="center">
|
|
25
27
|
<a href="#quick-start">Quick Start</a> •
|
|
26
28
|
<a href="#how-it-works">How It Works</a> •
|
|
27
|
-
<a href="#installation">Installation</a> •
|
|
28
29
|
<a href="#slash-commands">Slash Commands</a> •
|
|
30
|
+
<a href="#dashboard">Dashboard</a> •
|
|
29
31
|
<a href="#configuration">Configuration</a> •
|
|
30
32
|
<a href="#troubleshooting">Troubleshooting</a> •
|
|
31
33
|
<a href="#license">License</a>
|
|
@@ -39,45 +41,65 @@
|
|
|
39
41
|
|
|
40
42
|
## Why Learning, Not Memory
|
|
41
43
|
|
|
42
|
-
Plain memory solutions
|
|
43
|
-
|
|
44
|
-
- **It grows with every session.** More memory means more tokens, more context dilution, and diminishing returns as Claude has to re-read a history it can't fully use.
|
|
45
|
-
- **It doesn't change behavior.** If you corrected Claude yesterday about a library choice, a test framework, a deployment region — a memory system *remembers the correction happened*, but Claude may still make the same default choice today because nothing updated its decision-making.
|
|
44
|
+
Plain memory solutions re-inject transcripts or summaries from prior sessions. That preserves continuity but has limits:
|
|
46
45
|
|
|
47
|
-
|
|
46
|
+
- **Actionable, not just informative.** Memory logs *what happened*; learning produces *rules to follow* that change the next decision.
|
|
47
|
+
> *e.g.* you told Claude to stop running `npm test` without `--run` because it hangs on watch mode. **Memory** recalls "user was annoyed about npm test hanging". **Learning** writes the rule *"always pass `--run` to `npm test` in this repo — default watch mode blocks CI"* and applies it next session.
|
|
48
|
+
- **Preferences, not events.** Memory records literal facts; learning abstracts the *why* into rules that generalize.
|
|
49
|
+
> *e.g.* you reject Jest in favor of Vitest once. **Memory** stores that single choice. **Learning** derives *"prefer ESM-native test runners for this TypeScript monorepo"* — which also covers the next framework decision (e.g. picking `tsx` over `ts-node`) without waiting for the same correction to repeat.
|
|
50
|
+
- **Carries across sessions and workspaces.** Playbooks are keyed to the project and surface in every future session against that repo.
|
|
51
|
+
- **Compact.** Distilled, deduplicated rules stay in dozens of tokens — not thousands — even as the project grows.
|
|
48
52
|
|
|
49
|
-
-
|
|
50
|
-
- **Project playbook** — cross-session behavioral rules keyed to your project, with an explicit `trigger` (when the rule applies) and `rationale` (why). Rules are deduplicated, updated, and archived as they evolve.
|
|
51
|
-
|
|
52
|
-
The result is a compact, always-up-to-date set of instructions Claude reads at the start of every session — measured in *dozens* of tokens rather than thousands, and actually capable of changing behavior.
|
|
53
|
+
claude-smart's approach: **extract, don't accumulate**. Corrections and successful patterns are distilled into two artifacts — a session-scoped **user profile** and a cross-session **project playbook** (each rule with explicit `trigger` and `rationale`, deduplicated and archived as they evolve) — and reinjected at the start of every session.
|
|
53
54
|
|
|
54
55
|
---
|
|
55
56
|
|
|
56
57
|
## Quick Start
|
|
57
58
|
|
|
58
59
|
```bash
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
npx claude-smart install # or: uvx claude-smart install
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Or run the equivalent marketplace commands directly inside Claude Code:
|
|
61
64
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
```text
|
|
66
|
+
/plugin marketplace add ReflexioAI/claude-smart
|
|
67
|
+
/plugin install claude-smart@reflexioai
|
|
65
68
|
```
|
|
66
69
|
|
|
67
|
-
|
|
70
|
+
Then restart Claude Code.
|
|
71
|
+
|
|
72
|
+
To uninstall: `/plugin uninstall claude-smart@reflexioai`.
|
|
73
|
+
|
|
74
|
+
Developing the plugin itself? See [DEVELOPER.md](./DEVELOPER.md#developing-locally).
|
|
68
75
|
|
|
69
76
|
---
|
|
70
77
|
|
|
71
78
|
## Key Features
|
|
72
79
|
|
|
73
80
|
- 🧠 **Learn, don't just remember** — Corrections become structured, deduplicated rules, not transcript replays.
|
|
81
|
+
- ⚡ **Fully automatic learning** — Every user turn, tool call, and assistant response is captured via lifecycle hooks and extracted into rules without you running anything.
|
|
74
82
|
- 🎯 **Two-tier scope** — Per-session profiles for the current conversation; cross-session playbooks for the whole project.
|
|
75
|
-
- 🔌 **Fully local — no external API
|
|
83
|
+
- 🔌 **Fully local — no external API call** — semantic search runs on an in-process ONNX embedder (all-MiniLM-L6-v2), and all data (profiles, playbooks, interaction buffers) is stored locally on your machine (`~/.reflexio/` and `~/.claude-smart/`). The whole stack works offline.
|
|
76
84
|
- 🔎 **Hybrid search** — Playbooks and profiles are indexed with vector + BM25 search for fast, robust retrieval.
|
|
77
|
-
- 📥 **Automatic hook ingestion** — `SessionStart`, `UserPromptSubmit`, `PostToolUse`, `Stop`, `SessionEnd` all wired up; you don't run anything manually.
|
|
78
|
-
- 🏷️ **Correction-aware** — Corrective phrasings (`"no, don't"`, `"actually"`, `"stop"`, `"wrong"`) are detected and weighted during extraction.
|
|
79
85
|
- 🧪 **Offline resilience** — If the reflexio backend is down, hooks buffer to disk; the next successful publish drains them.
|
|
80
|
-
- 🧰 **
|
|
86
|
+
- 🧰 **Manual correction tag** — `/claude-smart:tag` flags the last turn as a correction so the extractor weights it heavily.
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Slash Commands
|
|
91
|
+
|
|
92
|
+
| Command | What it does |
|
|
93
|
+
| --- | --- |
|
|
94
|
+
| `/show` | Print the current project playbook plus the current session's user profiles (same markdown that `SessionStart` injects). Use it to audit what rules and preferences Claude is being told to follow. |
|
|
95
|
+
| `/learn` | Force reflexio to run extraction *now* on the current session's unpublished interactions. Without this, extraction runs at the end of the session or on reflexio's batch interval. |
|
|
96
|
+
| `/tag [note]` | Tag the most recent turn as a correction, for cases the automatic heuristic missed. The note becomes the correction description the extractor sees. |
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Dashboard
|
|
101
|
+
|
|
102
|
+
A Next.js web UI lives in [`dashboard/`](dashboard/) for browsing session buffers, inspecting user profiles, and editing project playbooks. It auto-starts alongside the backend — just open **http://localhost:3001**.
|
|
81
103
|
|
|
82
104
|
---
|
|
83
105
|
|
|
@@ -94,7 +116,6 @@ Restart Claude Code. The first time you correct it on something project-specific
|
|
|
94
116
|
2. **Local state buffer** — JSONL per session at `~/.claude-smart/sessions/{session_id}.jsonl`. Offline-safe.
|
|
95
117
|
3. **Reflexio backend** (submodule at `reflexio/`) — SQLite storage, hybrid search, profile/playbook extraction, dedup, status lifecycle (`CURRENT` → `ARCHIVED`). Runs on `localhost:8081`.
|
|
96
118
|
4. **Claude Code LLM provider** — a LiteLLM custom provider registered inside reflexio. Every generation call (extraction, update, dedup, evaluation) subprocesses `claude -p --output-format json`, so no OpenAI/Anthropic key is needed for the learning loop.
|
|
97
|
-
5. **Three slash commands** — `/show`, `/learn`, `/tag`.
|
|
98
119
|
|
|
99
120
|
**Data flow:**
|
|
100
121
|
|
|
@@ -127,116 +148,20 @@ Cross-session playbook retrieval uses `search_user_playbooks(agent_version=proje
|
|
|
127
148
|
|
|
128
149
|
---
|
|
129
150
|
|
|
130
|
-
## Installation
|
|
131
|
-
|
|
132
|
-
### Prerequisites
|
|
133
|
-
|
|
134
|
-
| Tool | Purpose |
|
|
135
|
-
| --- | --- |
|
|
136
|
-
| [Claude Code](https://claude.com/claude-code) | Host CLI — also the LLM backend for extraction |
|
|
137
|
-
| [uv](https://docs.astral.sh/uv/) | Python 3.12+ package manager — runs the reflexio backend |
|
|
138
|
-
| `git` | The install flow clones the plugin into Claude Code's plugin cache |
|
|
139
|
-
|
|
140
|
-
> **No external API keys needed.** Generation runs through your local `claude` CLI (via a LiteLLM custom provider). Embeddings run through an in-process ONNX model (`all-MiniLM-L6-v2`, bundled by `chromadb`). Both are turned on by default after install; reflexio refuses to fall back to paid APIs.
|
|
141
|
-
|
|
142
|
-
### Step 1 — Install the plugin
|
|
143
|
-
|
|
144
|
-
Pick whichever is handier — both published packages do the exact same thing:
|
|
145
|
-
|
|
146
|
-
```bash
|
|
147
|
-
# npm wrapper
|
|
148
|
-
npx claude-smart install
|
|
149
|
-
|
|
150
|
-
# Python wrapper
|
|
151
|
-
uvx claude-smart install
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
Either command:
|
|
155
|
-
|
|
156
|
-
1. Registers `ReflexioAI/claude-smart` as a Claude Code marketplace, clones it to `~/.claude/plugins/marketplaces/reflexioai/`, and enables the plugin.
|
|
157
|
-
2. Appends `CLAUDE_SMART_USE_LOCAL_CLI=1` and `CLAUDE_SMART_USE_LOCAL_EMBEDDING=1` to `~/.reflexio/.env` (idempotent — safe to re-run).
|
|
158
|
-
|
|
159
|
-
On the first Claude Code session, the plugin's `Setup` hook runs `plugin/scripts/smart-install.sh` once — that initializes the reflexio submodule and runs `uv sync` inside the plugin directory. You don't have to do this manually.
|
|
160
|
-
|
|
161
|
-
### Step 2 — Start the reflexio backend
|
|
162
|
-
|
|
163
|
-
```bash
|
|
164
|
-
cd ~/.claude/plugins/marketplaces/reflexioai
|
|
165
|
-
uv run reflexio services start --only backend --no-reload
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
Expected log lines:
|
|
169
|
-
|
|
170
|
-
```
|
|
171
|
-
Registered claude-code LiteLLM provider (cli=/path/to/claude)
|
|
172
|
-
Local embedding provider enabled (model=local/minilm-l6-v2)
|
|
173
|
-
Auto-detected LLM providers (priority order): ['claude-code', 'local']
|
|
174
|
-
Primary provider for generation: claude-code
|
|
175
|
-
Embedding provider: local
|
|
176
|
-
Application startup complete.
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
Health check:
|
|
180
|
-
|
|
181
|
-
```bash
|
|
182
|
-
curl http://localhost:8081/health
|
|
183
|
-
# {"status":"healthy"}
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
Leave this running in a separate terminal. Stop it with:
|
|
187
|
-
|
|
188
|
-
```bash
|
|
189
|
-
uv run reflexio services stop
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
On first use the embedder downloads the ~80 MB ONNX model once and caches it at `~/.cache/chroma/onnx_models/`. Subsequent starts reuse the cache and stay offline.
|
|
193
|
-
|
|
194
|
-
### Step 3 — Sanity check
|
|
195
|
-
|
|
196
|
-
Restart Claude Code. In any session:
|
|
197
|
-
|
|
198
|
-
```
|
|
199
|
-
/show
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
On a fresh project: `_No playbook or profiles yet for project `<name>`._` — expected. Have a conversation, include at least one genuine correction (`"no, don't use X — use Y"`), then run `/learn` to force extraction. After ~20–30 seconds, `/show` will surface the new rule.
|
|
203
|
-
|
|
204
|
-
### Uninstall
|
|
205
|
-
|
|
206
|
-
```bash
|
|
207
|
-
claude plugin uninstall claude-smart@reflexioai
|
|
208
|
-
|
|
209
|
-
# Optional — wipe learned data and per-session buffers
|
|
210
|
-
rm -rf ~/.reflexio/data/ ~/.claude-smart/sessions/
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
### Developing claude-smart itself
|
|
214
|
-
|
|
215
|
-
If you want to iterate on the plugin code (hooks, Python package, reflexio patch, install CLIs), don't install from npm/PyPI — clone the repo and point Claude Code at your working copy. See [DEVELOPER.md](./DEVELOPER.md#developing-locally) for the step-by-step.
|
|
216
|
-
|
|
217
|
-
---
|
|
218
|
-
|
|
219
|
-
## Slash Commands
|
|
220
|
-
|
|
221
|
-
| Command | What it does |
|
|
222
|
-
| --- | --- |
|
|
223
|
-
| `/show` | Print the current project playbook plus the current session's user profiles (same markdown that `SessionStart` injects). Use it to audit what rules and preferences Claude is being told to follow. |
|
|
224
|
-
| `/learn` | Force reflexio to run extraction *now* on the current session's unpublished interactions. Without this, extraction runs at the end of the session or on reflexio's batch interval. |
|
|
225
|
-
| `/tag [note]` | Tag the most recent turn as a correction, for cases the automatic heuristic missed. The note becomes the correction description the extractor sees. |
|
|
226
|
-
|
|
227
|
-
---
|
|
228
|
-
|
|
229
151
|
## Configuration
|
|
230
152
|
|
|
231
153
|
### Environment variables
|
|
232
154
|
|
|
233
155
|
| Variable | Default | Purpose |
|
|
234
156
|
| --- | --- | --- |
|
|
235
|
-
| `CLAUDE_SMART_USE_LOCAL_CLI` | `0`
|
|
236
|
-
| `CLAUDE_SMART_USE_LOCAL_EMBEDDING` | `0`
|
|
157
|
+
| `CLAUDE_SMART_USE_LOCAL_CLI` | `0` (installer sets `1`) | Route generation through the local `claude` CLI. Written to `~/.reflexio/.env` by `claude-smart install`. |
|
|
158
|
+
| `CLAUDE_SMART_USE_LOCAL_EMBEDDING` | `0` (installer sets `1`) | Use the in-process ONNX embedder (requires `chromadb`). Written to `~/.reflexio/.env` by `claude-smart install`. |
|
|
237
159
|
| `CLAUDE_SMART_CLI_PATH` | `shutil.which("claude")` | Override the path to the `claude` binary. |
|
|
238
160
|
| `CLAUDE_SMART_CLI_TIMEOUT` | `120` | Per-call subprocess timeout (seconds). Raise for slow prompts. |
|
|
239
161
|
| `CLAUDE_SMART_STATE_DIR` | `~/.claude-smart/sessions/` | Where the per-session JSONL buffer lives. |
|
|
162
|
+
| `CLAUDE_SMART_BACKEND_AUTOSTART` | `1` | Set to `0` to stop the SessionStart hook from spawning the reflexio backend on `localhost:8081`. |
|
|
163
|
+
| `CLAUDE_SMART_DASHBOARD_AUTOSTART` | `1` | Set to `0` to stop the SessionStart hook from spawning the Next.js dashboard on `localhost:3001`. |
|
|
164
|
+
| `CLAUDE_SMART_BACKEND_STOP_ON_END` | `0` | Set to `1` to tear down the backend at `SessionEnd` instead of leaving it long-lived. |
|
|
240
165
|
| `REFLEXIO_URL` | `http://localhost:8081/` | Point the plugin at a non-local reflexio backend. |
|
|
241
166
|
|
|
242
167
|
### Where data lives
|
|
@@ -261,18 +186,6 @@ If you still want to use a cloud embedding provider (OpenAI, Gemini, etc.), omit
|
|
|
261
186
|
|
|
262
187
|
---
|
|
263
188
|
|
|
264
|
-
## How the Claude Code Provider Works
|
|
265
|
-
|
|
266
|
-
claude-smart ships a small patch to reflexio (`reflexio/server/llm/providers/claude_code_provider.py`) that registers a LiteLLM `CustomLLM` named `claude-code`. Every time reflexio wants to generate, evaluate, or dedup, it ends up in `litellm.completion(model="claude-code/default", ...)` — which routes to our handler. The handler:
|
|
267
|
-
|
|
268
|
-
1. Splits LiteLLM's messages into `(system_prompt, dialogue)`.
|
|
269
|
-
2. Subprocesses `claude -p --output-format json --append-system-prompt "<system>"` with the dialogue on stdin.
|
|
270
|
-
3. Parses the JSON stdout into a LiteLLM `ModelResponse` with populated usage tokens.
|
|
271
|
-
|
|
272
|
-
Registration is opt-in (`CLAUDE_SMART_USE_LOCAL_CLI=1`) and idempotent, so enabling it does not affect users who still want OpenAI/Anthropic — reflexio's normal provider-priority chain stays intact.
|
|
273
|
-
|
|
274
|
-
---
|
|
275
|
-
|
|
276
189
|
## Troubleshooting
|
|
277
190
|
|
|
278
191
|
**SessionStart injects nothing after a correction.**
|
|
@@ -298,53 +211,6 @@ rm -rf ~/.reflexio/data/ # reflexio SQLite store
|
|
|
298
211
|
|
|
299
212
|
---
|
|
300
213
|
|
|
301
|
-
## Dashboard (web UI)
|
|
302
|
-
|
|
303
|
-
A Next.js management UI lives in [`dashboard/`](dashboard/). Use it to browse
|
|
304
|
-
local session buffers, inspect extracted user profiles, edit and archive
|
|
305
|
-
project playbooks, and tweak the claude-smart environment. It connects to the
|
|
306
|
-
same reflexio backend the plugin uses, so run that first.
|
|
307
|
-
|
|
308
|
-
```bash
|
|
309
|
-
# 1. reflexio backend on :8081 (see Step 2 above)
|
|
310
|
-
uv run reflexio services start --only backend --no-reload
|
|
311
|
-
|
|
312
|
-
# 2. install and run the dashboard
|
|
313
|
-
cd dashboard
|
|
314
|
-
npm install
|
|
315
|
-
npm run dev # http://localhost:3001
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
The dashboard reads `~/.claude-smart/sessions/*.jsonl` directly (server-side)
|
|
319
|
-
for in-flight session transcripts and proxies everything else through reflexio.
|
|
320
|
-
All state lives where the CLI already keeps it — the dashboard does not
|
|
321
|
-
introduce a second source of truth.
|
|
322
|
-
|
|
323
|
-
---
|
|
324
|
-
|
|
325
|
-
## Development
|
|
326
|
-
|
|
327
|
-
Run the test suite:
|
|
328
|
-
|
|
329
|
-
```bash
|
|
330
|
-
# reflexio patch unit tests
|
|
331
|
-
cd reflexio
|
|
332
|
-
uv run pytest tests/server/llm/ -q -o 'addopts='
|
|
333
|
-
|
|
334
|
-
# claude-smart package tests
|
|
335
|
-
cd ..
|
|
336
|
-
uv run pytest tests/ -q
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
Exercise a hook handler directly (useful for debugging without a live Claude Code session):
|
|
340
|
-
|
|
341
|
-
```bash
|
|
342
|
-
echo '{"session_id":"dev-1","source":"startup","cwd":"'"$PWD"'"}' \
|
|
343
|
-
| uv run python -m claude_smart.hook session-start
|
|
344
|
-
```
|
|
345
|
-
|
|
346
|
-
---
|
|
347
|
-
|
|
348
214
|
## License
|
|
349
215
|
|
|
350
216
|
This project is licensed under the **Apache License 2.0**. The bundled `reflexio/` submodule is also Apache 2.0. Claude Code is Anthropic's and not covered by this license.
|
|
@@ -355,8 +221,7 @@ See the [LICENSE](LICENSE) file for details.
|
|
|
355
221
|
|
|
356
222
|
## Support
|
|
357
223
|
|
|
358
|
-
- **Issues**: open one on GitHub describing the symptom and include the reflexio
|
|
359
|
-
- **Architecture notes**: see the plan file in `.claude/plans/` (if present), which walks through each design decision and the rationale.
|
|
224
|
+
- **Issues**: open one on GitHub describing the symptom and include the reflexio backend log (`~/.claude-smart/backend.log`) and the relevant lines of `~/.claude-smart/sessions/{session_id}.jsonl`.
|
|
360
225
|
|
|
361
226
|
---
|
|
362
227
|
|