claude-smart 0.1.1 → 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 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>
@@ -11,12 +13,12 @@
11
13
  <img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" alt="License">
12
14
  </a>
13
15
  <a href="pyproject.toml">
14
- <img src="https://img.shields.io/badge/version-0.1.0-green.svg" alt="Version">
16
+ <img src="https://img.shields.io/badge/version-0.1.2-green.svg" alt="Version">
15
17
  </a>
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="#installation">
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,67 +41,65 @@
39
41
 
40
42
  ## Why Learning, Not Memory
41
43
 
42
- Plain memory solutions preserve *what happened* — they re-inject transcripts, summaries, or observations from prior sessions. That works for continuity, but it has two real limits:
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.
46
-
47
- claude-smart takes a different approach: **extract, don't accumulate**. Each session's corrections and successful patterns are distilled by an LLM into two small, structured artifacts:
44
+ Plain memory solutions re-inject transcripts or summaries from prior sessions. That preserves continuity but has limits:
48
45
 
49
- - **User profile** short, session-scoped preferences Claude should respect right now.
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.
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.
51
52
 
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
- # 1. Clone with the reflexio backend submodule
60
- git clone --recurse-submodules https://github.com/ReflexioAI/claude-smart.git
61
- cd claude-smart
62
-
63
- # 2. Install dependencies (creates a uv-managed venv, pulls reflexio as a path dep)
64
- uv sync
65
-
66
- # 3. Turn on the local providers inside reflexio — no API key required at all
67
- mkdir -p ~/.reflexio
68
- grep -q '^CLAUDE_SMART_USE_LOCAL_CLI=' ~/.reflexio/.env 2>/dev/null \
69
- || echo 'CLAUDE_SMART_USE_LOCAL_CLI=1' >> ~/.reflexio/.env
70
- grep -q '^CLAUDE_SMART_USE_LOCAL_EMBEDDING=' ~/.reflexio/.env 2>/dev/null \
71
- || echo 'CLAUDE_SMART_USE_LOCAL_EMBEDDING=1' >> ~/.reflexio/.env
72
-
73
- # 4. Start the local reflexio backend (storage + search + extraction orchestrator)
74
- uv run reflexio services start --only backend --no-reload
75
-
76
- # 5. Install the plugin into Claude Code (project-level)
77
- mkdir -p .claude && cat > .claude/settings.local.json <<'JSON'
78
- {
79
- "extraKnownMarketplaces": {
80
- "claude-smart-local": {
81
- "source": { "source": "directory", "path": "." }
82
- }
83
- },
84
- "enabledPlugins": { "claude-smart@claude-smart-local": true }
85
- }
86
- JSON
60
+ npx claude-smart install # or: uvx claude-smart install
87
61
  ```
88
62
 
89
- Restart Claude Code in this workspace. The first time you correct Claude on something project-specific (*"no, don't use pytest-asyncio — use anyio with trio"*), a playbook rule will be extracted. Every subsequent session in the project starts with that rule injected — automatically, without you asking.
63
+ Or run the equivalent marketplace commands directly inside Claude Code:
64
+
65
+ ```text
66
+ /plugin marketplace add ReflexioAI/claude-smart
67
+ /plugin install claude-smart@reflexioai
68
+ ```
69
+
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).
90
75
 
91
76
  ---
92
77
 
93
78
  ## Key Features
94
79
 
95
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.
96
82
  - 🎯 **Two-tier scope** — Per-session profiles for the current conversation; cross-session playbooks for the whole project.
97
- - 🔌 **Fully local — no external API keys needed** — Generation runs through your local `claude` CLI; semantic search runs on an in-process ONNX embedder (all-MiniLM-L6-v2). The whole stack works offline.
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.
98
84
  - 🔎 **Hybrid search** — Playbooks and profiles are indexed with vector + BM25 search for fast, robust retrieval.
99
- - 📥 **Automatic hook ingestion** — `SessionStart`, `UserPromptSubmit`, `PostToolUse`, `Stop`, `SessionEnd` all wired up; you don't run anything manually.
100
- - 🏷️ **Correction-aware** — Corrective phrasings (`"no, don't"`, `"actually"`, `"stop"`, `"wrong"`) are detected and weighted during extraction.
101
85
  - 🧪 **Offline resilience** — If the reflexio backend is down, hooks buffer to disk; the next successful publish drains them.
102
- - 🧰 **Three slash commands** — `/show`, `/learn`, `/tag` for on-demand control.
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**.
103
103
 
104
104
  ---
105
105
 
@@ -116,7 +116,6 @@ Restart Claude Code in this workspace. The first time you correct Claude on some
116
116
  2. **Local state buffer** — JSONL per session at `~/.claude-smart/sessions/{session_id}.jsonl`. Offline-safe.
117
117
  3. **Reflexio backend** (submodule at `reflexio/`) — SQLite storage, hybrid search, profile/playbook extraction, dedup, status lifecycle (`CURRENT` → `ARCHIVED`). Runs on `localhost:8081`.
118
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.
119
- 5. **Three slash commands** — `/show`, `/learn`, `/tag`.
120
119
 
121
120
  **Data flow:**
122
121
 
@@ -149,167 +148,20 @@ Cross-session playbook retrieval uses `search_user_playbooks(agent_version=proje
149
148
 
150
149
  ---
151
150
 
152
- ## Installation
153
-
154
- ### One-command install
155
-
156
- If you just want the plugin wired into Claude Code (marketplace added, plugin installed, `~/.reflexio/.env` seeded with the local-provider flags), run **one** of:
157
-
158
- ```bash
159
- # uvx — pulls the Python package straight from git, no clone required
160
- uvx --from git+https://github.com/ReflexioAI/claude-smart claude-smart install
161
-
162
- # npx — same thing via the published npm wrapper
163
- npx claude-smart install
164
- ```
165
-
166
- Both do the same three things:
167
-
168
- 1. `claude plugin marketplace add ReflexioAI/claude-smart`
169
- 2. `claude plugin install claude-smart@yilu`
170
- 3. Append `CLAUDE_SMART_USE_LOCAL_CLI=1` and `CLAUDE_SMART_USE_LOCAL_EMBEDDING=1` to `~/.reflexio/.env` (idempotent).
171
-
172
- You still need to start the reflexio backend yourself the first time (`uv run reflexio services start --only backend --no-reload` from a clone of this repo). Everything else — submodule init, `uv sync` — runs inside Claude Code's `Setup` hook on first session.
173
-
174
- For a manual, step-by-step walkthrough, see below.
175
-
176
- ### Prerequisites
177
-
178
- | Tool | Purpose |
179
- | --- | --- |
180
- | [Claude Code](https://claude.com/claude-code) | The host CLI — also used as the LLM backend for extraction |
181
- | [uv](https://docs.astral.sh/uv/) | Python package manager (Python 3.12+) |
182
- | `git` | Needed to clone with submodules and to derive the project id |
183
-
184
- > **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 opt-in; when enabled, reflexio refuses to fall back to paid APIs.
185
-
186
- ### Step 1 — Clone the repository (with the reflexio submodule)
187
-
188
- ```bash
189
- git clone --recurse-submodules https://github.com/ReflexioAI/claude-smart.git
190
- cd claude-smart
191
-
192
- # If you forgot --recurse-submodules
193
- git submodule update --init --recursive
194
- ```
195
-
196
- ### Step 2 — Install Python dependencies
197
-
198
- ```bash
199
- uv sync
200
- ```
201
-
202
- This creates `.venv/`, pulls `reflexio-ai` as a path dependency from the `reflexio/` submodule, and registers the `claude-smart` and `claude-smart-hook` console scripts.
203
-
204
- ### Step 3 — Enable the local providers in reflexio
205
-
206
- Two env flags turn on the local generation backend (Claude Code CLI) and the local embedder (in-process ONNX). Both live in `~/.reflexio/.env`:
207
-
208
- ```bash
209
- mkdir -p ~/.reflexio
210
- grep -q '^CLAUDE_SMART_USE_LOCAL_CLI=' ~/.reflexio/.env 2>/dev/null \
211
- || echo 'CLAUDE_SMART_USE_LOCAL_CLI=1' >> ~/.reflexio/.env
212
- grep -q '^CLAUDE_SMART_USE_LOCAL_EMBEDDING=' ~/.reflexio/.env 2>/dev/null \
213
- || echo 'CLAUDE_SMART_USE_LOCAL_EMBEDDING=1' >> ~/.reflexio/.env
214
- ```
215
-
216
- 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.
217
-
218
- ### Step 4 — Start the reflexio backend
219
-
220
- Run this from the **claude-smart repo root** (not the `reflexio/` subdir) so that `uv run` uses the claude-smart venv — which already has `chromadb` installed for the local embedder and `reflexio-ai` available as a path dep with the `reflexio` CLI script registered:
221
-
222
- ```bash
223
- uv run reflexio services start --only backend --no-reload
224
- ```
225
-
226
- You should see a log line like:
227
-
228
- ```
229
- Registered claude-code LiteLLM provider (cli=/path/to/claude)
230
- Local embedding provider enabled (model=local/minilm-l6-v2)
231
- Auto-detected LLM providers (priority order): ['claude-code', 'local']
232
- Primary provider for generation: claude-code
233
- Embedding provider: local
234
- Application startup complete.
235
- ```
236
-
237
- Health check:
238
-
239
- ```bash
240
- curl http://localhost:8081/health
241
- # {"status":"healthy"}
242
- ```
243
-
244
- Leave this running in a separate terminal. Stop it later with:
245
-
246
- ```bash
247
- uv run reflexio services stop
248
- ```
249
-
250
- ### Step 5 — Install the plugin into Claude Code
251
-
252
- **Project-level (recommended while you evaluate):**
253
-
254
- ```bash
255
- mkdir -p .claude
256
- cat > .claude/settings.local.json <<JSON
257
- {
258
- "extraKnownMarketplaces": {
259
- "claude-smart-local": {
260
- "source": { "source": "directory", "path": "$PWD" }
261
- }
262
- },
263
- "enabledPlugins": { "claude-smart@claude-smart-local": true }
264
- }
265
- JSON
266
- ```
267
-
268
- **User-level (all projects):**
269
-
270
- Put the same JSON into `~/.claude/settings.json`, using an absolute path for the marketplace `path`.
271
-
272
- Restart Claude Code. On the next session start you should see reflexio logs show a `search_user_playbooks` call — that's the SessionStart hook fetching the (currently empty) playbook.
273
-
274
- ### Step 6 — Sanity check
275
-
276
- Inside Claude Code:
277
-
278
- ```
279
- /show
280
- ```
281
-
282
- On a fresh project you'll see `_No playbook or profiles yet for project `<name>`._` — correct. Have a conversation, include at least one genuine correction (`"no, don't use X — use Y"`), then:
283
-
284
- ```
285
- /learn
286
- ```
287
-
288
- That forces immediate extraction. Run `/show` again after ~20–30 seconds; the extracted rule should appear.
289
-
290
- ---
291
-
292
- ## Slash Commands
293
-
294
- | Command | What it does |
295
- | --- | --- |
296
- | `/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. |
297
- | `/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. |
298
- | `/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. |
299
-
300
- ---
301
-
302
151
  ## Configuration
303
152
 
304
153
  ### Environment variables
305
154
 
306
155
  | Variable | Default | Purpose |
307
156
  | --- | --- | --- |
308
- | `CLAUDE_SMART_USE_LOCAL_CLI` | `0` | Set to `1` in `~/.reflexio/.env` to route generation through the local `claude` CLI. |
309
- | `CLAUDE_SMART_USE_LOCAL_EMBEDDING` | `0` | Set to `1` to use the in-process ONNX embedder (requires `chromadb`). |
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`. |
310
159
  | `CLAUDE_SMART_CLI_PATH` | `shutil.which("claude")` | Override the path to the `claude` binary. |
311
160
  | `CLAUDE_SMART_CLI_TIMEOUT` | `120` | Per-call subprocess timeout (seconds). Raise for slow prompts. |
312
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. |
313
165
  | `REFLEXIO_URL` | `http://localhost:8081/` | Point the plugin at a non-local reflexio backend. |
314
166
 
315
167
  ### Where data lives
@@ -334,18 +186,6 @@ If you still want to use a cloud embedding provider (OpenAI, Gemini, etc.), omit
334
186
 
335
187
  ---
336
188
 
337
- ## How the Claude Code Provider Works
338
-
339
- 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:
340
-
341
- 1. Splits LiteLLM's messages into `(system_prompt, dialogue)`.
342
- 2. Subprocesses `claude -p --output-format json --append-system-prompt "<system>"` with the dialogue on stdin.
343
- 3. Parses the JSON stdout into a LiteLLM `ModelResponse` with populated usage tokens.
344
-
345
- 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.
346
-
347
- ---
348
-
349
189
  ## Troubleshooting
350
190
 
351
191
  **SessionStart injects nothing after a correction.**
@@ -371,53 +211,6 @@ rm -rf ~/.reflexio/data/ # reflexio SQLite store
371
211
 
372
212
  ---
373
213
 
374
- ## Dashboard (web UI)
375
-
376
- A Next.js management UI lives in [`dashboard/`](dashboard/). Use it to browse
377
- local session buffers, inspect extracted user profiles, edit and archive
378
- project playbooks, and tweak the claude-smart environment. It connects to the
379
- same reflexio backend the plugin uses, so run that first.
380
-
381
- ```bash
382
- # 1. reflexio backend on :8081 (see Step 4 above)
383
- uv run reflexio services start --only backend --no-reload
384
-
385
- # 2. install and run the dashboard
386
- cd dashboard
387
- npm install
388
- npm run dev # http://localhost:3001
389
- ```
390
-
391
- The dashboard reads `~/.claude-smart/sessions/*.jsonl` directly (server-side)
392
- for in-flight session transcripts and proxies everything else through reflexio.
393
- All state lives where the CLI already keeps it — the dashboard does not
394
- introduce a second source of truth.
395
-
396
- ---
397
-
398
- ## Development
399
-
400
- Run the test suite:
401
-
402
- ```bash
403
- # reflexio patch unit tests
404
- cd reflexio
405
- uv run pytest tests/server/llm/ -q -o 'addopts='
406
-
407
- # claude-smart package tests
408
- cd ..
409
- uv run pytest tests/ -q
410
- ```
411
-
412
- Exercise a hook handler directly (useful for debugging without a live Claude Code session):
413
-
414
- ```bash
415
- echo '{"session_id":"dev-1","source":"startup","cwd":"'"$PWD"'"}' \
416
- | uv run python -m claude_smart.hook session-start
417
- ```
418
-
419
- ---
420
-
421
214
  ## License
422
215
 
423
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.
@@ -428,8 +221,7 @@ See the [LICENSE](LICENSE) file for details.
428
221
 
429
222
  ## Support
430
223
 
431
- - **Issues**: open one on GitHub describing the symptom and include the reflexio startup log (stdout of `uv run reflexio services start`) and the relevant lines of `~/.claude-smart/sessions/{session_id}.jsonl`.
432
- - **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`.
433
225
 
434
226
  ---
435
227
 
@@ -15,7 +15,7 @@ const { homedir } = require("os");
15
15
  const { dirname, join } = require("path");
16
16
 
17
17
  const DEFAULT_MARKETPLACE_SOURCE = "ReflexioAI/claude-smart";
18
- const PLUGIN_SPEC = "claude-smart@yilu";
18
+ const PLUGIN_SPEC = "claude-smart@reflexioai";
19
19
  const REFLEXIO_ENV_PATH = join(homedir(), ".reflexio", ".env");
20
20
 
21
21
  function hasClaudeCli() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-smart",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Self-improving Claude Code plugin — learns from corrections via reflexio",
5
5
  "keywords": [
6
6
  "claude",