claude-smart
Turns corrections into Preferences, Project-specific skills, and Shared skills for Claude Code, Codex, and OpenCode.
Safety scan
A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.
Check it deeper on your machine
It has changed since its scan on 11 Nov 2026.
As a Claude Code plugin, install it and then ask Claude Code:
/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/ReflexioAI/claude-smart with scanskillsafety
Or from a terminal, clone it and run it:
git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/ReflexioAI/claude-smart'
It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.
Badge for your README
Markdown
[](/listings/reflexioai-claude-smart)HTML
<a href="/listings/reflexioai-claude-smart"><img src="/api/listings/reflexioai-claude-smart/badge.svg" alt="findsafeskills safety rating" /></a>Install
Install instructions from the README
As written by the repo's author. findsafeskills has not verified these steps.
Requires Node.js 20+ (for `npx`) and the host CLI you're installing into (`claude`, `codex`, or `opencode`) on `PATH`.
Claude Code
npx claude-smart install
Then restart Claude Code.
Codex
npx claude-smart install --host codex
Then fully quit and reopen Codex so hooks reload.
OpenCode
npx claude-smart install --host opencode
Then restart OpenCode in your project so it loads the plugin from `opencode.json`. Add `--global` to install for all OpenCode projects on this machine instead.
Uninstall
npx claude-smart uninstall # Claude Code npx claude-smart uninstall --host codex # Codex npx claude-smart uninstall --host opencode # OpenCode
Restart the host afterward. Learned data under `~/.reflexio/` and `~/.claude-smart/` is preserved and shared across hosts, so you can uninstall or switch hosts without losing skills or preferences.
For per-host details — what the installers and uninstallers touch, OpenCode config resolution and model/env overrides, and Windows notes — see [Host install notes](./DEVELOPER.md#host-install-notes) in DEVELOPER.md. Developing the plugin itself? See [Developing locally](./DEVELOPER.md#developing-locally).
> **Not supported:** Claude Code Cowork, claude.ai/code web, or remote Codex environments without local plugin hooks — they run outside your local machine, so the local backend/dashboard and `~/.reflexio/` aren't reachable.
---
What was scanned
The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.
README.md · README · 497 lines
View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)
This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.
- <p align="center">
- <img src="assets/claude-smart-icon.png" alt="claude-smart" width="140">
- </p>
- <h1 align="center">
- claude-smart
- </h1>
- <h4 align="center">A self-improvement plugin for <a href="https://claude.com/claude-code" target="_blank">Claude Code</a>, Codex, and OpenCode that turns interactions into durable skills they follow in future sessions.</h4>
- <p align="center">
- <a href="LICENSE">
- <img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" alt="License">
- </a>
- <a href="plugin/pyproject.toml">
- <img src="https://img.shields.io/badge/version-0.3.17-green.svg" alt="Version">
- </a>
- <a href="plugin/pyproject.toml">
- <img src="https://img.shields.io/badge/python-%3E%3D3.12-brightgreen.svg" alt="Python">
- </a>
- <a href="package.json">
- <img src="https://img.shields.io/badge/node-%3E%3D20-brightgreen.svg" alt="Node">
- </a>
- <a href="#quick-start">
- <img src="https://img.shields.io/badge/hosts-Claude%20Code%20%2B%20Codex%20%2B%20OpenCode-purple.svg" alt="Hosts">
- </a>
- <a href="https://discord.gg/7fnCxahase">
- <img src="https://img.shields.io/badge/Discord-Join%20community-5865F2?logo=discord&logoColor=white" alt="Discord">
- </a>
- <a href="https://github.com/ReflexioAI/reflexio">
- <img src="https://img.shields.io/github/stars/ReflexioAI/reflexio?style=flat&logo=github&label=Star%20reflexio&color=yellow&cacheSeconds=3600" alt="Star reflexio on GitHub">
- </a>
- </p>
- <p align="center">
- <a href="#quick-start">Quick Start</a> •
- <a href="#how-it-works">How It Works</a> •
- <a href="#commands">Commands</a> •
- <a href="#dashboard">Dashboard</a> •
- <a href="#configuration">Configuration</a> •
- <a href="TROUBLESHOOTING.md">Troubleshooting</a> •
- <a href="#license">License</a>
- </p>
- <p align="center">
- claude-smart learns from your corrections <i>and</i> from what's already working — so the assistant stops repeating mistakes and reuses proven paths. Project-specific skills capture repo-local rules, and shared skills roll up durable patterns for reuse across projects.
- </p>
- <p align="center">
- <b>vs <code>claude-mem</code>:</b> ~3× better at turning your corrections into rules Claude follows, ~50% more of your guidance is retained. <a href="EXPERIMENT.md"><b>Read the benchmark →</b></a>
- </p>
- <p align="center">
- ⭐ Built on the open-source <a href="https://github.com/ReflexioAI/reflexio"><b>reflexio</b></a> engine — if claude-smart helps you, <a href="https://github.com/ReflexioAI/reflexio"><b>star reflexio on GitHub</b></a>.
- </p>
- ---
- ## Quick Start
- Requires Node.js 20+ (for `npx`) and the host CLI you're installing into (`claude`, `codex`, or `opencode`) on `PATH`.
- ### Guided installation
- ```bash
- npx claude-smart install
- ```
- Choose one or more detected coding agents with the arrow keys and Space, then
- press Enter. Single-choice settings use the arrow keys and Enter. Esc or Ctrl+C
- cancels before configuration is saved.
- The guide asks where to store and process your data:
- - **Local Reflexio:** starts a background backend on this machine. Choose which
- available agent CLI powers background learning; it can analyze interactions
- from every installed integration.
- - **Managed Reflexio:** enter an HTTPS endpoint and a hidden API key. No local
- backend starts; memory storage and background learning run in Reflexio cloud.
- The local dashboard connects to that cloud backend by default.
- In local mode, Claude Code learning defaults to the `sonnet` alias, which Claude
- Code resolves independently of the coding model. Codex and OpenCode keep their
- provider-configured defaults. An explicit supported model ID overrides these
- choices. For unattended installs, use
- `--model <model-id>` with `--provider`. The chosen model is applied to extraction
- and optimizer calls. Managed mode reports the server-configured model when
- available, otherwise explicitly reports that its default model is not exposed.
- After install, update, or setup, the summary includes the Claude-smart version,
- learning provider, provider CLI version when available, and model selection.
- Configured aliases/defaults are distinguished from a reported model version;
- unknown versions are shown as “not reported.” Run `npx claude-smart setup` to
- change the learning settings.
- When local learning is already configured, **Keep current learning configuration**
- is selected by default. It preserves cloud generation, custom executables and the
- current native model; selecting a native provider entry explicitly changes that
- setup and opens its model choices. Supported caller overrides still apply, and
- `--provider` explicitly replaces a cloud/custom configuration with that native
- provider. Installing a different coding integration does not select its model.
- The dashboard's **Data source** dropdown selects Local or Managed Reflexio.
- It defaults to the saved runtime mode. Its endpoint, overview totals, preferences,
- skills, and backend sessions follow the selected source; viewing another source
- does not change learning/storage settings. The header shows the selected endpoint
- as a read-only connection label, with an **Open cloud dashboard** link in Managed
- mode. Change connection settings in **Configure**. Overview metrics use backend summary
- counts for the last 30 days, rather than list limits. Connection failures are
- shown explicitly. Older skill citations without a project/shared identity remain
- visible under Legacy skill usage; exact per-skill counts use identified citations.
- A backend must be configured and reachable to view its data.
- The dashboard follows the managed Reflexio workspace style: neutral light/dark
- surfaces, green accents, flat metric bands, and consistent page spacing. The
- theme switch applies across dashboard, sessions, preferences, skills, and settings.
- Previously configured connections are retained privately when changing modes.
- The dashboard currently trusts local OS users: other accounts on a shared machine
- can access its configured backend connections. Per-user dashboard authentication
- requires a separate change.
- **This device** lists local session buffers and hook activity separately. Those
- counts can differ between machines connected to the same managed account.
- Review the configuration before installation starts. Saved settings and installed
- agents are preselected on subsequent runs. Preparation and service startup show
- phase and elapsed progress; detailed logs live in `~/.claude-smart/install-logs/`.
- If an integration fails, the others still install and the summary reports each result.
- Runtime environments remain separate so an agent's rollback cannot break another.
- ### Explicit installation
- For an unattended first install, specify the backend. Multiple agents can be
- installed in one command:
- ```bash
- npx claude-smart install --host claude-code,codex --backend local --provider codex
- npx claude-smart install --host opencode --backend local --provider opencode --global
- ```
- For managed mode, supply the API key through a named environment variable rather
- than a command-line argument:
- ```bash
- npx claude-smart install --host claude-code,codex --backend managed \
- --url https://www.reflexio.ai/ --api-key-env REFLEXIO_API_KEY
- ```
- Existing `--host codex` and `--host opencode` commands still work. Without a terminal,
- saved backend/provider settings are reused; a fresh install requires `--backend`.
- Use `--yes` to skip interactive questions when all required settings are supplied
- or saved. For multiple local agents, specify `--provider` unless one is already saved.
- Use `--read-only` to retrieve memories without publishing interactions, or `--learn`
- to resume learning. The interactive guide offers both modes for either backend.
- Setup reads legacy duplicate settings with the same field rules as the runtime:
- shared connection/learning fields use the last assignment (including empty), while
- caller-overridable execution flags use the first nonempty saved assignment.
- Legacy connection fallback treats the endpoint and API key as a pair. If the
- current settings contain either assignment, even empty, setup does not borrow
- the other from `~/.reflexio/.env`. An incomplete managed connection needs its own
- key. Legacy read-only and other runtime preferences still migrate independently.
- Setup, Codex hooks, the dashboard, and the shell/Python readers all accept plain
- assignments and `export` followed by spaces or tabs.
- Explicit caller and setup choices retain their existing precedence. Reading or
- cancelling setup does not rewrite the file or prepare a settings publisher.
- Legacy migration preserves the selected original value text, including Windows
- path quoting; only the assignment prefix is normalized.
- Confirmation uses the same native lock and private atomic settings owner as the
- dashboard and dependency repair. One captured preview drives the save; concurrent
- edits require a fresh preview. Setup prepares a small temporary Python writer from
- locked dependencies before changing settings. A preparation failure leaves settings
- unchanged. Confirmed settings remain available if a later integration install fails.
- Publisher child processes, including UV installation, have a two-minute deadline.
- On timeout, setup stops their owned process trees.
- If publication cannot be confirmed, setup stops before installing integrations;
- reload settings before retrying.
- Migration completion is recorded as a fixed first-line comment in that same atomic
- settings write, after an optional UTF-8 BOM. Matching text inside a value is not
- migration metadata. Existing
- migration sidecars are still recognized without rewriting them. Later setup runs
- do not reimport deleted legacy preferences after migration has completed.
- The confirmed guide owns connection, learning, sharing, and read-only choices.
- Host workers consume those saved choices; installing or removing another agent
- does not rewrite a shared learning host. Each prepared runtime uses the same
- Python repair owner to supply only missing local defaults, with native locking
- and private atomic publication. Existing values, including zero and explicit
- empty values, are preserved. Ordinary standalone self-repair remains supported.
- Dashboard saves use the prepared Python settings owner too. They share the
- repair lock and publish privately with one atomic file replacement. An explicit
- empty value stays present; omitted settings stay unchanged. If relevant settings
- change while a save is being prepared, reload and retry rather than overwriting
- the newer choices. A busy repair also leaves the file unchanged. Saving requires
- the dashboard's prepared sibling `.venv`; run `npx claude-smart update` if that
- runtime needs repair. Existing unrelated assignments and comments are retained.
- Literal values use quotes only when needed to preserve the same value across
- the readers; backslashes are never rewritten as escapes. Expansion, line/control
- separators and quote combinations without a shared literal form are refused
- before publication.
- Legacy saved HOST fallback is preserved as explicit learning intent at confirmation,
- also when switching to managed storage with a native optimizer. Existing HOST
- text remains available to the pinned SDK; this does not retire its compatibility
- input or grant a new optimizer capability. A private worker without confirmed
- connection settings refuses with the public setup command. Confirmation saves a
- validated local endpoint in its normalized loopback spelling, so accepted numeric
- or uppercase hostnames retain local mode. Reading an existing file does not
- normalize it. Uninstall still completes with broken settings and skips speculative
- shared-service refresh.
- ### Activate each integration
- Run `/reload-plugins` in your existing Claude Code session, or use the update in your next session.
- Start a new Codex session to load the update; you can finish your existing session first. If hook trust needs review, use `/hooks`.
- Then restart OpenCode in your project so it loads the plugin. The installer writes a loader into the selected scope's `plugins` directory — the project's `.opencode/plugins/` for a project install — and both OpenCode lines load the plugin from there: OpenCode 1.x auto-loads the plugins directory, and OpenCode V2 rejects the old `file://` config-entry shape. Any legacy `opencode.json` entry is removed so the package loads exactly once. `--global` installs for all OpenCode projects on this machine instead, writing the loader under your user config directory.
- Install and update use the same tracked service lifecycle for every coding agent.
- Validation of the platform, settings, and OpenCode loader/config happens before
- services stop. If preparation fails before commit, the previous packages and
- install metadata are restored before restarting only services that were running.
- If an installed service reports that stopping failed, installation aborts before
- replacing its runtime. Resolve the shutdown failure and retry; only services
- whose stop succeeded are eligible for automatic restart.
- A failed first install leaves no candidate runtime selected. Incomplete recovery
- keeps backups and warns rather than starting an unverified runtime.
- Codex stages its marketplace under `CODEX_HOME/claude-smart/marketplace` (default
- `~/.codex/claude-smart/marketplace`), separate from Claude's legacy marketplace.
- Installing or removing Codex leaves that legacy runtime intact.
- Codex commits its prepared runtime and hook cache before asking Codex to trust the
- hooks. A later trust failure keeps that new runtime; follow the reported `/hooks`
- recovery instructions. Registration, account configuration, and trust changes are
- not an all-or-nothing transaction.
- ### Check an update
- ```bash
- npx claude-smart status
- npx claude-smart status --host codex
- ```
- Shows the installed version and the version each recent session last used in a hook. Historical observations do not confirm that a session is still active. Codex uses `CODEX_HOME` when set; run installation and status with the same account home as your session. `status --host codex` also warns when a claude-smart hook is disabled in Codex's `config.toml` and says how to re-enable it; it never edits that file.
- ### Uninstall
- ```bash
- npx claude-smart uninstall # Choose integrations interactively
- npx claude-smart uninstall --host claude-code,codex # Remove multiple integrations
- npx claude-smart uninstall --host claude-code # Claude Code
- npx claude-smart uninstall --host codex # Codex
- npx claude-smart uninstall --host opencode # OpenCode
- ```
- Afterward, use `/reload-plugins` in Claude Code, start a new Codex session, or restart OpenCode. Learned data under `~/.reflexio/` and `~/.claude-smart/` is preserved and shared across hosts, so you can uninstall or switch hosts without losing skills or preferences.
- Uninstall keeps saved configuration and the chosen background learning provider.
- Removing an integration does not uninstall its agent CLI. Remaining integrations
- can continue using the same learning provider. OpenCode removal applies to the
- current project config, or its global config with `--global`.
- If removing an integration breaks the shared command link, it is repaired from
- the remaining runtimes, including registered Claude Code caches and local source
- installs. A declared local source takes precedence over its older cache path;
- discovery does not modify or delete that source.
- For per-host details — what the installers and uninstallers touch, OpenCode config resolution and model/env overrides, and Windows notes — see [Host install notes](./DEVELOPER.md#host-install-notes) in DEVELOPER.md. Developing the plugin itself? See [Developing locally](./DEVELOPER.md#developing-locally).
- > **Not supported:** Claude Code Cowork, claude.ai/code web, or remote Codex environments without local plugin hooks — they run outside your local machine, so the local backend/dashboard and `~/.reflexio/` aren't reachable.
- ---
- ## Why Learning, Not Memory
- Most memory tools just record. Claude remembers what happened, but doesn't change what it does next.
- `claude-smart` focuses on learning instead.
- Four things this changes:
- - 💡 **Stop repeating the same mistakes:** Produces actionable skills Claude can follow next time; memory only records what happened.
- > *Example:* a deploy fails after Claude bumps `prisma` from 5.x to 6.0; you tell it to roll back because 6.0 breaks nested writes in your order flow.<br>
- > **Memory:** “deploy broke after prisma bump; user rolled back”<br>
- > **Learning:** “treat major-version bumps of ORMs/DB drivers as breaking — verify with integration tests, not just unit tests”
- - 🚀 **Start from the optimized path:** Records and optimizes the steps that worked so Claude can reuse them, instead of re-exploring each session.
- > *Example:* Claude spends several iterations trying to start the local dev environment before discovering that this repo requires `pnpm dev:all` instead of the usual `npm run dev`.<br>
- > **Memory:** “user mentioned that `npm run dev` did not work”<br>
- > **Learning:** “for this repo, always use `pnpm dev:all` to start the full local stack — `npm run dev` only starts the frontend and causes missing service errors”
- Instead of re-exploring, Claude Code starts from the proven path—reducing planning steps, latency, and token usage.
- - 🌐 **Project-specific and shared skills:** Session memory disappears with the conversation. Project-specific skills preserve repo-local rules, while shared skills roll up patterns that should transfer across projects. Preferences stay scoped to the current project so per-repo preferences don't leak across projects.
- - 🪶 **Better context without prompt bloat:** Distilled, deduplicated skills stay in dozens of tokens—not thousands—even as the project grows.
- ---
- ## Demo
- https://github.com/user-attachments/assets/ed84d73a-d5b7-4a0d-ab2c-f2c060c3f276
- ---
- ## Key Features
- - 🧠 **Learn, don't just remember** — Corrections become structured, deduplicated rules, not transcript replays.
- - ⚡ **Fully automatic learning** — Every user turn, tool call, and assistant response is captured via lifecycle hooks and extracted into rules without you running anything.
- - 📈 **Continuously self-tuning, not just append-on-conflict** — Existing rules are continuously refined, not just appended to. Wording gets clearer, *when-to-apply* triggers tighten or broaden as evidence accumulates, near-duplicates merge, stale rules are superseded, and dead ones are archived. The library gets sharper, not just bigger.
- > *e.g.* correct the same `npm test --run` gotcha twice → consolidated into one rule. New evidence shows it applies to `vitest` too → scope broadened. Switch policy to `pnpm test` → old rule archived, new one supersedes it.
- - 🔌 **Local or managed storage** — in local mode, semantic search runs on an in-process ONNX embedder (all-MiniLM-L6-v2) and memories stay on this machine. Managed mode stores and processes memories on the configured cloud backend; device interaction buffers remain local.
- - 🔎 **Hybrid search** — Skills and preferences are indexed with vector + BM25 search for fast, robust retrieval.
- - 🧪 **Offline resilience** — If the reflexio backend is down, hooks buffer to disk; the next successful publish drains them.
- - 🧰 **Manual correction marker** — `/claude-smart:learn` in Claude Code, or `bash ~/.reflexio/plugin-root/scripts/cli.sh learn` in Codex, flags the last turn as a correction so the extractor weights it heavily.
- ---
- ## Dashboard
- A web UI for browsing session histories, inspecting preferences, and editing project-specific and shared skills. The local backend binds to `127.0.0.1:8071` by default. The dashboard auto-starts in both local and managed mode at **http://localhost:3001**. Its data-source selector defaults to your saved runtime mode; managed mode reads cloud totals without starting a local backend. Or run `/claude-smart:dashboard` in Claude Code to open it in your browser. In Codex, run `bash ~/.reflexio/plugin-root/scripts/dashboard-open.sh`.
- <p align="center">
- <img src="assets/preferences_dashboard.png" alt="Preferences dashboard" width="49%">
- <img src="assets/skills_dashboard.png" alt="Skills dashboard" width="49%">
- </p>
- ---
- ## How It Works
- claude-smart builds three artifacts as you work and injects the relevant ones into Claude Code, Codex, or OpenCode:
- - **Preferences** (project-scoped) — how you work in this specific repo (stack, role, small quirks). *e.g.* "uses pnpm, not npm"; "prefers terse answers"; "backend engineer — explain frontend with backend analogues."
- - **Project-specific skills** — durable rules with triggers and rationales learned from corrections in a project. *e.g.* "always pass `--run` to `npm test` — watch mode hangs CI."
- - **Shared skills** — optimized rollups of project-specific skills that should transfer across projects. *e.g.* "use real Postgres for integration tests — mocks once hid a broken migration."
- Skills clean themselves up: correct the same thing twice and they merge; change your mind and the old one is archived.
- Under the hood: hooks watch your turns, tool calls, and assistant replies, auto-flagging corrections (or anything you flag with `/claude-smart:learn`). At session end (or on `/claude-smart:learn`), [reflexio](https://github.com/ReflexioAI/reflexio) — the self-improving engine that powers claude-smart — extracts preferences and project-specific skills, then rolls durable patterns into shared skills. On each new user prompt, claude-smart searches for matching context and injects only the relevant hits, as a short index: one line per hit saying when it applies. The agent loads the full text of any hit that applies with `bash ~/.reflexio/plugin-root/scripts/cli.sh load --session <session-id> <id> [<id> ...]` (the injected header gives the exact command). Run `/claude-smart:show` or the equivalent CLI command to audit the current learned state. Everything runs on your machine.
- **Citations.** At the end of a reply, the assistant may append a short marker:
- ```
- ✨ claude-smart rule applied: [git safety](http://localhost:3001/rules/s1-123) | [brief answer preference](http://localhost:3001/rules/p1-pref) · [⚡Reflexio](https://github.com/ReflexioAI/reflexio)
- ```
- That signals a preference or skill materially shaped the reply.
- Open the session's detail page in the [dashboard](http://localhost:3001) to see the exact cited item.
- See [ARCHITECTURE.md](./ARCHITECTURE.md) for hooks, data flow, and reflexio details.
- ---
- ## Commands
- Claude Code installs these as plugin slash commands. Codex does not currently
- support plugin-provided slash commands, so claude-smart ships a Codex skill that
- maps requests like "claude-smart show" or "run claude-smart learn" to the
- equivalent action.
- | Claude Code | Codex request | What it does |
- | --- | --- | --- |
- | `/claude-smart:dashboard` | `open claude-smart dashboard` | Open the dashboard in your browser, auto-starting the reflexio backend and dashboard services if they aren't already running. |
- | `/claude-smart:show` | `claude-smart show` | Print current project-specific skills, shared skills, and the current project's preferences so you can audit learned state manually. |
- | `/claude-smart:learn [note]` | `claude-smart learn with note "optional note"` | Flag the most recent turn as a correction (for cases the automatic heuristic missed) and force reflexio to run extraction *now* on the session's unpublished interactions. The optional note becomes the correction description the extractor sees. |
- | `/claude-smart:restart` | `restart claude-smart` | Restart the reflexio backend and dashboard to pick up new changes (e.g. after upgrading the plugin or editing local reflexio code). |
- | `/claude-smart:clear-all` | `clear all claude-smart learnings` | **Destructive.** Delete *all* reflexio interactions, preferences, and skills. Use when you want to wipe learned state and start fresh. |
- ---
- ## Configuration
- Advanced users can tune claude-smart via environment variables — see [DEVELOPER.md](./DEVELOPER.md#environment-variables) for the full list.
- ### Where data lives
- | Path | What |
- | --- | --- |
- | `~/.reflexio/data/reflexio.db` | Source of truth for learned preferences, skills, interactions, full-text indexes, and embedding tables (plus `.db-shm` / `.db-wal` WAL sidecars). Inspect with `sqlite3`. |
- | `~/.claude-smart/.env` | claude-smart config read by the hooks, backend, installer, and `npx claude-smart setup` — connection and learning policy (`REFLEXIO_URL` / `REFLEXIO_API_KEY`, `CLAUDE_SMART_LEARNING_PROVIDER` / `CLAUDE_SMART_LEARNING_MODEL`), plus execution overrides. Existing `CLAUDE_SMART_HOST` rows remain legacy fallback; installers no longer default or rewrite them. |
- | `~/.claude-smart/claude-code/claude-smart/` | Claude Code's stable local copy of the active npm package, registered as the `reflexioai` marketplace. Claude Code runs the plugin in place from its `plugin/` dir. |
- | `.claude/settings.local.json` or `~/.claude/settings.json` | Claude Code hook environment, such as `CLAUDE_SMART_CITATIONS`; use project-local settings for one repo or user settings for all projects. |
- | `~/.codex/config.toml` | Codex plugin state, hook feature flags, and per-hook trust entries after `claude-smart install --host codex`. |
- | `~/.codex/plugins/cache/reflexioai/claude-smart/<version>/` | Codex's cached install of the `claude-smart` plugin from the `ReflexioAI` marketplace. |
- | `~/.codex/claude-smart/runtime/plugin/` | Codex's prepared Python environment and dashboard. Hooks in the cache execute this runtime; generated dependencies stay outside the validated plugin package. Both Codex paths use `CODEX_HOME` when set. |
- | `opencode.json` / `opencode.jsonc`, or existing `.opencode/opencode.json*` | OpenCode local plugin config patched by `claude-smart install --host opencode`; the installer updates only the claude-smart entry in OpenCode's plugin list. |
- | `~/.claude-smart/opencode/claude-smart/` | OpenCode's stable local copy of the active npm package. OpenCode config points here with `file://` so restarts do not re-resolve `claude-smart` from npm. |
- | `~/.reflexio/plugin-root` | Self-healed symlink to the active plugin dir (managed by `ensure-plugin-root.sh` — written on install, refreshed each `SessionStart`). Claude Code slash commands and Codex shell-command helpers resolve through it, so don't delete it; if you do, the next session will recreate it. |
- | `~/.claude-smart/sessions/{session_id}.jsonl` | Private per-session buffer: turns, tools, frozen requests and publication watermarks. Unacknowledged data remains here; deleting the buffer can lose pending interactions. |
- | `~/.claude-smart/publish-outbox/` | Private Codex publication intents and shared worker locks. Contains destination fingerprints and completed-turn bounds; interaction content stays in session buffers. |
- | `~/.claude-smart/node/current/` | Private Node.js/npm runtime used by hooks and the dashboard after install. |
- | `~/.cache/chroma/onnx_models/all-MiniLM-L6-v2/` | Cached ONNX weights (~86 MB, downloaded once). Delete to force a re-download. |
- Backends that require publication admission select their database in the same
- atomic operation as a saved-configuration upgrade. If legacy work must drain,
- refusal preserves the original configuration so the old writer can still open
- it. Complete that work with the matching old backend before retrying; startup
- does not discard history, switch to an empty database, or acknowledge charges.
- Upgrading from `CLAUDE_SMART_USE_LOCAL_EMBEDDING` requires removing the retired
- assignment after preserving the effective model, endpoint and timeout policy.
- See the [embedding upgrade guide](https://github.com/ReflexioAI/claude-smart/blob/main/DEVELOPER.md#upgrade-from-the-old-embedding-flag), including the case where an old local default shadowed a written `off`.
- For troubleshooting, see [TROUBLESHOOTING.md](./TROUBLESHOOTING.md).
- ---
- ## Powered by Reflexio
- claude-smart is powered by [**Reflexio**](https://github.com/ReflexioAI/reflexio) ([reflexio.ai](https://reflexio.ai)) — the open-source self-improving engine that turns interactions into durable, reusable skills. If claude-smart is useful to you, **[⭐ star reflexio on GitHub](https://github.com/ReflexioAI/reflexio)**.
- ---
- ## License
- This project is licensed under the **Apache License 2.0**. Reflexio is a separate Apache 2.0 project consumed as the `reflexio-ai` Python package. Claude Code is Anthropic's and not covered by this license.
- See the [LICENSE](LICENSE) file for details.
- ---
- ## Support
- - **Discord**: join the community at [discord.gg/7fnCxahase](https://discord.gg/7fnCxahase).
- - **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`.
- ---
- **Powered by** [Reflexio](https://github.com/ReflexioAI/reflexio) · **Runs on** [Claude Code](https://claude.com/claude-code), Codex, and OpenCode · **Written in** Python 3.12+
- Search hooks reserve a durable request identity in the session buffer before
- retrieval. The corresponding response is published with that same identity;
- retries keep it, and searches after a frozen publish belong to a later response.
- Older buffered publishes keep their existing retry IDs. Cancelled turns do not
- attach their retrieved-playbook references to a later prompt's answer. Search
- alone does not supply a conversation or an outcome for offline tuning: the
- response still needs to be published. Buffer writes and identity reservations
- share a cross-process file lock on Linux, macOS, and native Windows.
- ### Short sessions and completion
- Automatic session completion keeps Reflexio's usefulness judge enabled. Claude
- Code's SessionEnd publishes an unsaved tail, then sends a completion hint even if
- Stop already saved every message. Acceptance does not mean extraction has finished.
- Explicit `/learn` remains a manual force operation.
- With the updated Reflexio backend, publish-only integrations (including Codex,
- OpenCode, and direct clients) evaluate short sessions after six hours without a new
- publication in the same session. The operator can configure
- `extraction_idle_timeout_seconds` (`21600` by default, `0` disables for new
- publications). This fallback is a low-urgency policy, not proof a session ended.
- Normal full-window and stride extraction still runs promptly. A negative judge
- result produces no learning and is recorded as examined.
- Optimizer policy is also owned by the Reflexio server. SessionStart no longer
- turns optimization on or rewrites its budgets, adoption permissions or assistant
- backend. Existing server settings are preserved; fresh servers keep their own
- (disabled) optimizer default until explicitly configured. The old
- `CLAUDE_SMART_ENABLE_OPTIMIZER` hook flag is no longer read. Removing or setting
- that flag does not disable an optimizer already enabled on the server; change
- `playbook_optimizer_config` on the server to do that.
- The separately installed `claude-smart-optimizer-assistant` helper remains
- available for explicitly configured local optimization. See the
- [backend binding notes](./DEVELOPER.md#optimizer-backend-binding) before assigning
- an executable path, especially when the server is remote.
- Extraction cadence is owned by the Reflexio server: configure `window_size` and
- `stride_size` there. Starting a client session preserves those settings. The
- former hook overrides `CLAUDE_SMART_WINDOW_SIZE` and `CLAUDE_SMART_STRIDE_SIZE`
- are no longer read; remove them from launchers and set the server configuration
- explicitly when a benchmark needs a different cadence. Existing persisted values
- are preserved; fresh servers use their own defaults.
- Managed mode requires a server update; changing the plugin alone cannot update a
- cloud server. An older server retains saved messages and logs that completion is
- unsupported; the plugin does not republish or force extraction. Idle fallback
- starts with new publications after backend upgrade; old saved sessions can be
- explicitly finalized on the updated backend.
- ### Publish-time playbook evidence
- User-playbook search receipts travel with the injected learning references in the
- on-disk buffer and are sent unchanged on publish. Distinct receipts for one
- playbook are retained, so a later revision cannot overwrite an earlier injection.
- Reflexio stores exposure evidence with the interaction rather than writing it on
- search. ID-only references remain supported but have unverified served versions.
- Update the SDK/server together to receive this metadata; older search response
- models may omit receipts. The server stores only a receipt digest in the
- interaction, and client recovery uses it to compare the original submission.
- Normal installs require `reflexio-ai>=0.2.32`; `plugin/uv.lock` resolves the
- published SDK from PyPI. Keep the SDK/server upgrade coordinated: older SDK
- response models can omit receipts, and older servers retain their existing
- exposure behavior. ID-only publication remains compatible.
plugin/scripts/smart-install.sh · Bundled script · 734 lines · 1 finding marked
- #!/usr/bin/env bash
- # Prepare the plugin Python runtime, repair only missing local defaults,
- # then verify and start the selected services. Connection selection belongs
- # to the npm installer; dependency repair never retargets saved endpoints.
- #
- # On failure, writes the reason to ~/.claude-smart/install-failed so
- # hook_entry.sh can short-circuit and surface a user-visible message
- # instead of silently no-op'ing every session.
- set -eu
- HERE="$(cd "$(dirname "$0")" && pwd)"
- # shellcheck source=_lib.sh
- . "$HERE/_lib.sh"
- claude_smart_source_login_path
- claude_smart_prepend_astral_bins
- claude_smart_prepend_node_bins
- PLUGIN_ROOT="$(cd "$HERE/.." && pwd)"
- claude_smart_reexec_stable_plugin_root_if_needed "$PLUGIN_ROOT" "smart-install.sh" "$@"
- REPO_ROOT="$(cd "$HERE/../.." && pwd)"
- MARKER_DIR="$HOME/.claude-smart"
- FAILURE_MARKER="$MARKER_DIR/install-failed"
- SUCCESS_MARKER="$MARKER_DIR/install-complete"
- INSTALL_LOCK="$MARKER_DIR/install.lock"
- INSTALL_REAP_LOCK="$MARKER_DIR/install.lock.reap"
- mkdir -p "$MARKER_DIR"
- remove_stale_install_lock() {
- local expected current
- expected="$1"
- if ! mkdir "$INSTALL_REAP_LOCK" 2>/dev/null; then
- sleep 1
- return 0
- fi
- current="$(cat "$INSTALL_LOCK" 2>/dev/null || true)"
- if [ "$current" = "$expected" ]; then
- rm -f "$INSTALL_LOCK"
- fi
- rmdir "$INSTALL_REAP_LOCK" 2>/dev/null || true
- }
- acquire_install_lock() {
- local lock_pid
- if command -v flock >/dev/null 2>&1; then
- exec 9>"$INSTALL_LOCK"
- if ! flock 9; then
- echo "[claude-smart] install lock failed; continuing without serialization" >&2
- claude_smart_emit_continue
- exit 0
- fi
- return 0
- fi
- while ! ( set -C; printf '%s\n' "$$" > "$INSTALL_LOCK" ) 2>/dev/null; do
- lock_pid="$(cat "$INSTALL_LOCK" 2>/dev/null || true)"
- case "$lock_pid" in
- ''|*[!0-9]*)
- remove_stale_install_lock "$lock_pid"
- ;;
- *)
- if kill -0 "$lock_pid" 2>/dev/null; then
- sleep 1
- else
- remove_stale_install_lock "$lock_pid"
- fi
- ;;
- esac
- done
- trap '[ "$(cat "$INSTALL_LOCK" 2>/dev/null || true)" = "$$" ] && rm -f "$INSTALL_LOCK" || true' EXIT
- }
- # Serialize concurrent installer runs (SessionStart hook + slash-command
- # self-heal can both invoke this script). Wait for the active installer
- # rather than returning early, otherwise callers can re-check uv before
- # the first install has finished and report a false missing-dependency error.
- acquire_install_lock
- rm -f "$FAILURE_MARKER"
- write_failure() {
- local reason fp_hash
- reason="$1"
- fp_hash="$(claude_smart_install_fingerprint_hash "$PLUGIN_ROOT" "$HERE" 2>/dev/null || true)"
- # bin/claude-smart.js reads this marker too: first line is the user-facing
- # failure reason, and fingerprint=... marks which install attempt produced it.
- {
- printf '%s\n' "$reason"
- if [ -n "$fp_hash" ]; then
- printf 'fingerprint=%s\n' "$fp_hash"
- fi
- } > "$FAILURE_MARKER"
- rm -f "$SUCCESS_MARKER"
- echo "[claude-smart] install failed: $reason" >&2
- claude_smart_emit_continue
- exit 0
- }
- verify_windows_local_embedding_runtime() {
- claude_smart_is_windows || return 0
- local ownership
- if claude_smart_reflexio_url_is_remote || claude_smart_reflexio_url_is_custom_local; then
- return 0
- fi
- claude_smart_prepare_backend_import_context "$PLUGIN_ROOT"
- if ! ownership="$(cd "$PLUGIN_ROOT" && PYTHONPATH="$backend_pythonpath" \
- REFLEXIO_ENV_FILE="$HOME/.claude-smart/.env" \
- "$backend_python" "$HERE/backend-inference-owner.py")"; then
- write_failure "Unable to determine inference ownership; resolve the SDK startup error before retrying."
- fi
- ownership="${ownership%$'\r'}"
- case "$ownership" in
- attached) return 0 ;;
- colocated) ;;
- *) write_failure "Invalid inference ownership result; repair the selected runtime before retrying." ;;
- esac
- if claude_smart_python_imports "$PLUGIN_ROOT" onnxruntime; then
- return 0
- fi
- write_failure "Windows local embedding requires Microsoft Visual C++ Redistributable for onnxruntime; install the x64 redistributable from https://aka.ms/vs/17/release/vc_redist.x64.exe and rerun claude-smart install."
- Dismissed after review: Links to a Windows program from code, which is how droppers fetch their payload
- Line 122 on GitHub
- }
- if [ "${1:-}" = "verify-windows-embedding" ]; then
- # Node bootstrap runs this after uv sync so install-failed markers stay
- # consistent with the shell installer path.
- claude_smart_source_reflexio_env
- verify_windows_local_embedding_runtime
- exit 0
- fi
- install_fingerprint() {
- claude_smart_install_fingerprint "$PLUGIN_ROOT" "$HERE"
- }
- install_complete() {
- [ -f "$SUCCESS_MARKER" ] || return 1
- [ "$(cat "$SUCCESS_MARKER" 2>/dev/null || true)" = "$(install_fingerprint)" ] || return 1
- command -v uv >/dev/null 2>&1 || return 1
- [ -d "$PLUGIN_ROOT/.venv" ] || return 1
- claude_smart_python_imports "$PLUGIN_ROOT" claude_smart.hook || return 1
- if ! claude_smart_reflexio_url_is_remote; then
- [ -f "$HOME/.claude-smart/.env" ] || return 1
- grep -qE '^[[:space:]]*(export[[:space:]]+)?CLAUDE_SMART_USE_LOCAL_CLI[[:space:]]*=' "$HOME/.claude-smart/.env" || return 1
- grep -qE '^[[:space:]]*(export[[:space:]]+)?CLAUDE_SMART_READ_ONLY[[:space:]]*=' "$HOME/.claude-smart/.env" || return 1
- grep -qE '^[[:space:]]*(export[[:space:]]+)?REFLEXIO_ROW_LIMIT_INTERACTIONS[[:space:]]*=' "$HOME/.claude-smart/.env" || return 1
- fi
- if [ -d "$PLUGIN_ROOT/dashboard" ]; then
- [ -d "$PLUGIN_ROOT/dashboard/.next" ] || [ -f "$MARKER_DIR/dashboard-build.pid" ] || [ -f "$(claude_smart_dashboard_unavailable_marker)" ] || return 1
- fi
- return 0
- }
- # The npx installer sets CLAUDE_SMART_DEFER_SERVICES=1 while it prepares a
- # copy it may still roll back; it starts the backend and the dashboard build
- # itself once the install has committed.
- start_backend_service() {
- [ "${CLAUDE_SMART_DEFER_SERVICES:-}" = "1" ] && return 0
- if [ -x "$HERE/backend-service.sh" ]; then
- # backend-service.sh decides whether a bundled backend runs at all
- # (managed mode, a custom local server, and autostart=0 skip it).
- echo "[claude-smart] requested a backend start (see backend-service.sh status)" >&2
- bash "$HERE/backend-service.sh" start >/dev/null 2>&1 || true
- fi
- }
- install_vendored_reflexio() {
- local VENDORED_REFLEXIO PLUGIN_PYTHON
- VENDORED_REFLEXIO="$PLUGIN_ROOT/vendor/reflexio"
- if [ ! -f "$VENDORED_REFLEXIO/pyproject.toml" ]; then
- # A host plugin cache (~/.claude/plugins/cache/..., ~/.codex/plugins/cache/...)
- # is only ever populated from the npm package, which always carries the
- # vendored runtime. Missing it there means the plugin was installed straight
- # from the GitHub marketplace, where the bundle is gitignored — the backend
- # could never start. Fail here, at Setup, rather than at first session.
- case "$PLUGIN_ROOT" in
- */plugins/cache/*)
- write_failure "bundled Reflexio runtime is missing from $VENDORED_REFLEXIO. This happens when claude-smart is installed from the GitHub marketplace, which does not carry the generated runtime. Install with: npx claude-smart install"
- ;;
- esac
- # A source checkout legitimately has no vendor bundle (it is generated at
- # pack time); reflexio comes from the plugin venv instead.
- return 0
- fi
- if claude_smart_is_windows; then
- PLUGIN_PYTHON="$PLUGIN_ROOT/.venv/Scripts/python.exe"
- else
- PLUGIN_PYTHON="$PLUGIN_ROOT/.venv/bin/python"
- fi
- if [ ! -x "$PLUGIN_PYTHON" ]; then
- write_failure "plugin Python was not created by uv sync: $PLUGIN_PYTHON"
- fi
- echo "[claude-smart] installing bundled Reflexio source from $VENDORED_REFLEXIO" >&2
- if ! uv pip install --project "$PLUGIN_ROOT" --python "$PLUGIN_PYTHON" --quiet --reinstall --no-deps "$VENDORED_REFLEXIO" >&2; then
- echo "[claude-smart] warning: quiet vendored Reflexio install failed in $PLUGIN_ROOT; retrying with full output." >&2
- if ! uv pip install --project "$PLUGIN_ROOT" --python "$PLUGIN_PYTHON" --reinstall --no-deps "$VENDORED_REFLEXIO" >&2; then
- write_failure "vendored Reflexio install failed in $PLUGIN_ROOT"
- fi
- fi
- verify_vendored_reflexio_requirements "$PLUGIN_PYTHON"
- }
- # --no-deps skips the bundled Reflexio's own requirements, so a requirement
- # plugin/uv.lock does not install would otherwise surface only as an import
- # error in the backend. Fail the install instead, naming the missing package.
- verify_vendored_reflexio_requirements() {
- local python_bin report problems
- python_bin="$1"
- if report="$(uv pip check --python "$python_bin" 2>&1)"; then
- return 0
- fi
- printf '%s\n' "$report" >&2
- problems="$(printf '%s\n' "$report" | grep -E '^The package' | tr '\n' ';' | sed 's/;$//' || true)"
- write_failure "bundled Reflexio dependency check failed in $PLUGIN_ROOT/.venv: ${problems:-uv pip check failed} — this claude-smart package is missing a dependency of its bundled Reflexio; update with 'npx claude-smart update' or report it at https://github.com/ReflexioAI/claude-smart/issues"
- }
- write_success_marker() {
- install_fingerprint > "$SUCCESS_MARKER"
- }
- preflight_supported_runtime_platform() {
- local os_name machine darwin_major
- os_name="$(uname -s 2>/dev/null || echo unknown)"
- machine="$(uname -m 2>/dev/null || echo unknown)"
- case "$os_name" in
- Darwin*)
- if [ "$machine" != "arm64" ]; then
- write_failure "claude-smart currently supports Apple Silicon macOS 14+ only; Intel Mac is not supported because native ML wheels are unavailable."
- fi
- darwin_major="$(uname -r 2>/dev/null | awk -F. '{print $1}')"
- case "$darwin_major" in
- ''|*[!0-9]*)
- write_failure "claude-smart could not determine the macOS version; Apple Silicon macOS 14+ is required."
- ;;
- esac
- if [ "$darwin_major" -lt 23 ]; then
- write_failure "claude-smart currently supports macOS 14+ on Apple Silicon; macOS 13 and older are not supported because native ML wheels are unavailable."
- fi
- ;;
- MINGW*|MSYS*|CYGWIN*)
- case "$machine" in
- x86_64|amd64) : ;;
- *)
- write_failure "claude-smart currently supports Windows x64 only; Windows ARM is not supported because native ML wheels are unavailable."
- ;;
- esac
- ;;
- Linux*)
- : # Existing Linux installs remain supported when package wheels are available.
- ;;
- *)
- write_failure "claude-smart currently supports Apple Silicon macOS 14+, Windows x64, and Linux for vanilla installs."
- ;;
- esac
- }
- install_private_node() {
- local NODE_MIN_MAJOR NODE_MIN_MINOR NODE_LTS_MAJOR
- local node_os archive_ext reason node_arch node_platform base_url node_root
- local tmp_dir shasums_path archive_name ext_re install_dir archive_path
- local expected_hash actual_hash archive_win dest_win candidate_path next_link old_current
- NODE_MIN_MAJOR=20
- NODE_MIN_MINOR=9
- NODE_LTS_MAJOR="${CLAUDE_SMART_NODE_LTS_MAJOR:-26}"
- if claude_smart_node_satisfies "$NODE_MIN_MAJOR" "$NODE_MIN_MINOR" \
- && claude_smart_npm_available; then
- claude_smart_clear_dashboard_unavailable
- return 0
- fi
- case "$(uname -s 2>/dev/null)" in
- Darwin*) node_os="darwin"; archive_ext="tar.gz" ;;
- Linux*) node_os="linux"; archive_ext="tar.gz" ;;
- MINGW*|MSYS*|CYGWIN*)
- node_os="win"
- archive_ext="zip"
- if ! command -v powershell >/dev/null 2>&1; then
- reason="PowerShell is not on PATH, so claude-smart could not extract private Node.js on Windows."
- echo "[claude-smart] WARNING: $reason" >&2
- claude_smart_write_dashboard_unavailable "$reason"
- return 1
- fi
- ;;
- *)
- reason="unsupported OS for private Node.js install: $(uname -s 2>/dev/null || echo unknown)"
- echo "[claude-smart] WARNING: $reason" >&2
- claude_smart_write_dashboard_unavailable "$reason"
- return 1
- ;;
- esac
- case "$(uname -m 2>/dev/null)" in
- x86_64|amd64) node_arch="x64" ;;
- arm64|aarch64) node_arch="arm64" ;;
- *)
- reason="unsupported CPU for private Node.js install: $(uname -m 2>/dev/null || echo unknown)"
- echo "[claude-smart] WARNING: $reason" >&2
- claude_smart_write_dashboard_unavailable "$reason"
- return 1
- ;;
- esac
- node_platform="$node_os-$node_arch"
- base_url="${CLAUDE_SMART_NODE_BASE_URL:-https://nodejs.org/dist/latest-v${NODE_LTS_MAJOR}.x}"
- echo "[claude-smart] Node.js >=20.9 with npm not found — installing private Node.js from nodejs.org..." >&2
- node_root="$HOME/.claude-smart/node"
- mkdir -p "$node_root"
- tmp_dir=$(mktemp -d "$node_root/tmp.XXXXXX") || {
- reason="could not create temporary directory under $node_root"
- echo "[claude-smart] WARNING: $reason" >&2
- claude_smart_write_dashboard_unavailable "$reason"
- return 1
- }
- shasums_path="$tmp_dir/SHASUMS256.txt"
- if ! claude_smart_download "$base_url/SHASUMS256.txt" "$shasums_path"; then
- rm -rf "$tmp_dir"
- reason="could not download Node.js checksums from $base_url/SHASUMS256.txt"
- echo "[claude-smart] WARNING: $reason" >&2
- claude_smart_write_dashboard_unavailable "$reason"
- return 1
- fi
- ext_re=$(printf '%s' "$archive_ext" | sed 's/\./\\./g')
- archive_name=$(
- awk -v platform="$node_platform" -v ext="$ext_re" \
- '$2 ~ ("^node-v[0-9][^ ]*-" platform "\\." ext "$") { print $2; exit }' \
- "$shasums_path"
- ) || archive_name=""
- if [ -z "$archive_name" ]; then
- rm -rf "$tmp_dir"
- reason="could not resolve Node.js archive for $node_platform from $base_url"
- echo "[claude-smart] WARNING: $reason" >&2
- claude_smart_write_dashboard_unavailable "$reason"
- return 1
- fi
- install_dir="$node_root/${archive_name%.$archive_ext}"
- archive_path="$tmp_dir/$archive_name"
- expected_hash=$(awk -v name="$archive_name" '$2 == name { print $1; exit }' "$shasums_path")
- if [ -z "$expected_hash" ]; then
- rm -rf "$tmp_dir"
- reason="Node.js checksums did not include $archive_name"
- echo "[claude-smart] WARNING: $reason" >&2
- claude_smart_write_dashboard_unavailable "$reason"
- return 1
- fi
- if ! claude_smart_download "$base_url/$archive_name" "$archive_path"; then
- rm -rf "$tmp_dir"
- reason="Node.js download failed from $base_url/$archive_name"
- echo "[claude-smart] WARNING: $reason" >&2
- claude_smart_write_dashboard_unavailable "$reason"
- return 1
- fi
- actual_hash=$(claude_smart_sha256_file "$archive_path" || true)
- if [ -z "$actual_hash" ] || [ "$actual_hash" != "$expected_hash" ]; then
- rm -rf "$tmp_dir"
- reason="Node.js checksum verification failed for $archive_name"
- echo "[claude-smart] WARNING: $reason" >&2
- claude_smart_write_dashboard_unavailable "$reason"
- return 1
- fi
- rm -rf "$install_dir" "$node_root/current.next"
- if [ "$archive_ext" = "zip" ]; then
- archive_win="$archive_path"
- dest_win="$node_root"
- if command -v cygpath >/dev/null 2>&1; then
- archive_win=$(cygpath -w "$archive_path")
- dest_win=$(cygpath -w "$node_root")
- fi
- if ! ARCHIVE_PATH="$archive_win" DEST_DIR="$dest_win" powershell -NoProfile -ExecutionPolicy Bypass -Command \
- '$ProgressPreference="SilentlyContinue"; Expand-Archive -LiteralPath $env:ARCHIVE_PATH -DestinationPath $env:DEST_DIR -Force' >&2; then
- rm -rf "$tmp_dir" "$install_dir"
- reason="Node.js archive extraction failed for $archive_name"
- echo "[claude-smart] WARNING: $reason" >&2
- claude_smart_write_dashboard_unavailable "$reason"
- return 1
- fi
- elif ! tar -xzf "$archive_path" -C "$node_root"; then
- rm -rf "$tmp_dir" "$install_dir"
- reason="Node.js archive extraction failed for $archive_name"
- echo "[claude-smart] WARNING: $reason" >&2
- claude_smart_write_dashboard_unavailable "$reason"
- return 1
- fi
- if [ ! -d "$install_dir" ]; then
- rm -rf "$tmp_dir"
- reason="Node.js archive extracted without expected directory $install_dir"
- echo "[claude-smart] WARNING: $reason" >&2
- claude_smart_write_dashboard_unavailable "$reason"
- return 1
- fi
- if [ -x "$install_dir/bin/node" ]; then
- candidate_path="$install_dir/bin:$PATH"
- elif [ -x "$install_dir/node.exe" ] || [ -x "$install_dir/node" ]; then
- candidate_path="$install_dir:$PATH"
- else
- rm -rf "$tmp_dir"
- reason="Node.js archive extracted without a node executable"
- echo "[claude-smart] WARNING: $reason" >&2
- claude_smart_write_dashboard_unavailable "$reason"
- return 1
- fi
- if claude_smart_node_satisfies "$NODE_MIN_MAJOR" "$NODE_MIN_MINOR" \
- && claude_smart_npm_available; then
- : # existing PATH unexpectedly became suitable; keep going
- elif PATH="$candidate_path" claude_smart_node_satisfies "$NODE_MIN_MAJOR" "$NODE_MIN_MINOR" \
- && PATH="$candidate_path" claude_smart_npm_available; then
- : # candidate install is suitable
- else
- rm -rf "$tmp_dir"
- reason="private Node.js install completed but node/npm are still not usable"
- echo "[claude-smart] WARNING: $reason" >&2
- claude_smart_write_dashboard_unavailable "$reason"
- return 1
- fi
- if claude_smart_is_windows; then
- # Windows cannot rely on the POSIX symlink swap path; keep current recoverable.
- old_current="$node_root/current.old.$$"
- rm -rf "$old_current" 2>/dev/null || true
- if [ -e "$node_root/current" ] || [ -L "$node_root/current" ]; then
- if ! mv "$node_root/current" "$old_current"; then
- rm -rf "$tmp_dir" "$install_dir"
- reason="could not stage existing private Node.js install for replacement"
- echo "[claude-smart] WARNING: $reason" >&2
- claude_smart_write_dashboard_unavailable "$reason"
- return 1
- fi
- fi
- if mv "$install_dir" "$node_root/current"; then
- rm -rf "$old_current" 2>/dev/null || true
- else
- reason="could not activate private Node.js install at $node_root/current"
- if [ -e "$node_root/current" ] || [ -L "$node_root/current" ]; then
- if ! rm -rf "$node_root/current"; then
- reason="could not remove failed private Node.js install at $node_root/current; previous install remains at $old_current for manual recovery"
- rm -rf "$tmp_dir" "$install_dir"
- echo "[claude-smart] WARNING: $reason" >&2
- claude_smart_write_dashboard_unavailable "$reason"
- return 1
- fi
- fi
- if [ -e "$old_current" ] || [ -L "$old_current" ]; then
- if ! mv "$old_current" "$node_root/current"; then
- reason="could not restore previous private Node.js install from $old_current after activation failure; previous install remains at $old_current for manual recovery"
- fi
- fi
- rm -rf "$tmp_dir" "$install_dir"
- echo "[claude-smart] WARNING: $reason" >&2
- claude_smart_write_dashboard_unavailable "$reason"
- return 1
- fi
- else
- next_link="$node_root/current.next.$$"
- if ln -s "$install_dir" "$next_link" 2>/dev/null; then
- if mv -Tf "$next_link" "$node_root/current" 2>/dev/null; then
- :
- elif mv -hf "$next_link" "$node_root/current" 2>/dev/null; then
- :
- else
- rm -rf "$node_root/current"
- mv "$next_link" "$node_root/current"
- fi
- else
- rm -rf "$next_link" "$node_root/current"
- mv "$install_dir" "$node_root/current"
- fi
- fi
- rm -rf "$tmp_dir"
- claude_smart_prepend_node_bins
- if claude_smart_node_satisfies "$NODE_MIN_MAJOR" "$NODE_MIN_MINOR" \
- && claude_smart_npm_available; then
- claude_smart_clear_dashboard_unavailable
- echo "[claude-smart] installed private $(node -v) at $node_root/current" >&2
- return 0
- fi
- reason="private Node.js install completed but current node/npm are still not usable"
- echo "[claude-smart] WARNING: $reason" >&2
- claude_smart_write_dashboard_unavailable "$reason"
- return 1
- }
- if [ "${CLAUDE_SMART_INSTALL_PRIVATE_NODE_ONLY:-}" = "1" ]; then
- claude_smart_source_reflexio_env
- install_private_node
- exit $?
- fi
- preflight_supported_runtime_platform
- if (claude_smart_source_reflexio_env; install_complete); then
- claude_smart_source_reflexio_env
- verify_windows_local_embedding_runtime
- start_backend_service
- claude_smart_emit_continue
- exit 0
- fi
- if ! command -v uv >/dev/null 2>&1; then
- echo "[claude-smart] uv not found — installing from astral.sh..." >&2
- # The astral.sh bash installer downloads a zip and unzips it. On
- # Windows-flavoured bash (Git Bash / MSYS) the bundled `unzip` corrupts
- # the Windows uv binary (bad CRC on the inflated uv.exe), leaving the
- # install half-finished. Use the official PowerShell installer
- # (install.ps1) on Windows, which writes uv.exe to ~/.local/bin
- # natively — same destination the bash installer targets on POSIX, so
- # claude_smart_prepend_astral_bins picks it up uniformly afterwards.
- if claude_smart_is_windows; then
- if ! command -v powershell >/dev/null 2>&1; then
- write_failure "uv install needs PowerShell on Windows but powershell is not on PATH — install uv manually from https://docs.astral.sh/uv/"
- fi
- if ! powershell -NoProfile -ExecutionPolicy Bypass -Command "irm https://astral.sh/uv/install.ps1 | iex" >&2; then
- write_failure "uv install via PowerShell failed — install manually from https://docs.astral.sh/uv/"
- fi
- else
- UV_INSTALLER="$MARKER_DIR/uv-install.sh"
- if ! claude_smart_download https://astral.sh/uv/install.sh "$UV_INSTALLER"; then
- write_failure "uv installer download failed — install manually from https://docs.astral.sh/uv/"
- fi
- if ! sh "$UV_INSTALLER" >&2; then
- write_failure "uv install failed — install manually from https://docs.astral.sh/uv/"
- fi
- fi
- claude_smart_prepend_astral_bins
- if ! command -v uv >/dev/null 2>&1; then
- UV_FOUND=""
- for candidate in "$HOME/.local/bin/uv" "$HOME/.local/bin/uv.exe" "$HOME/.cargo/bin/uv" "$HOME/bin/uv"; do
- if [ -x "$candidate" ]; then
- UV_FOUND="$candidate"
- break
- fi
- done
- if [ -n "$UV_FOUND" ]; then
- write_failure "uv installed at $UV_FOUND — add its parent directory to PATH in your shell rc"
- else
- write_failure "uv install reported success but binary not found — install manually from https://docs.astral.sh/uv/"
- fi
- fi
- fi
- cd "$PLUGIN_ROOT"
- # Claude Code copies the plugin directory into ~/.claude/plugins/cache on every
- # install/update, yet runs it in place, so an in-place .venv (~1 GB) became an
- # unused duplicate per version. For the managed Claude Code copy, keep the env
- # outside the plugin directory and link it from .venv: Claude Code skips the
- # symlink when copying, and every "$PLUGIN_ROOT/.venv/bin/python" path still
- # resolves. One directory per install, so the package an update keeps aside for
- # rollback still owns its own env. Successful updates keep older envs for
- # sessions using cached hooks; explicit uninstall removes them.
- # Windows keeps the in-place .venv (symlinks need Developer Mode there).
- CLAUDE_SMART_VENVS_DIR="$HOME/.claude-smart/venvs"
- plugin_root_is_managed_claude_code_copy() {
- local managed
- claude_smart_is_windows && return 1
- managed="$(claude_smart_canonical_dir "$HOME/.claude-smart/claude-code/claude-smart/plugin" 2>/dev/null)" || return 1
- [ "$(pwd -P)" = "$managed" ]
- }
- plugin_venv_target() {
- [ -L "$PLUGIN_ROOT/.venv" ] || return 1
- readlink "$PLUGIN_ROOT/.venv"
- }
- if plugin_root_is_managed_claude_code_copy; then
- if [ -L "$PLUGIN_ROOT/.venv" ] && [ ! -d "$PLUGIN_ROOT/.venv" ]; then
- rm -f "$PLUGIN_ROOT/.venv"
- fi
- if [ ! -e "$PLUGIN_ROOT/.venv" ]; then
- mkdir -p "$CLAUDE_SMART_VENVS_DIR"
- venv_dir="$CLAUDE_SMART_VENVS_DIR/claude-code-$(date +%s)-$$"
- mkdir "$venv_dir"
- ln -s "$venv_dir" "$PLUGIN_ROOT/.venv"
- venv_freshly_linked=1
- fi
- fi
- # Self-heal a corrupt .venv before uv sync. uv refuses to reuse a venv that
- # exists but has no python executable (e.g. partial cleanup of an npm/npx
- # tree, an interrupted earlier install, or the underlying interpreter being
- # uninstalled) — it errors with "not a valid Python environment" instead of
- # rebuilding. Pre-clearing lets uv recreate it cleanly.
- if [ -d "$PLUGIN_ROOT/.venv" ] && [ -z "${venv_freshly_linked:-}" ]; then
- if claude_smart_is_windows; then
- plugin_python_path="$PLUGIN_ROOT/.venv/Scripts/python.exe"
- else
- plugin_python_path="$PLUGIN_ROOT/.venv/bin/python"
- fi
- if [ ! -x "$plugin_python_path" ]; then
- echo "[claude-smart] .venv at $PLUGIN_ROOT/.venv has no python executable; recreating" >&2
- if venv_target="$(plugin_venv_target)"; then
- # Clear the linked env in place; removing only the link would leak it.
- find "$venv_target" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
- else
- rm -rf "$PLUGIN_ROOT/.venv"
- fi
- fi
- fi
- echo "[claude-smart] running uv sync..." >&2
- if ! uv sync --locked --python 3.12 --quiet >&2; then
- if uv lock --check --python 3.12 >/dev/null 2>&1; then
- write_failure "uv sync failed in $PLUGIN_ROOT — run 'uv sync --locked --python 3.12' there to diagnose"
- fi
- echo "[claude-smart] plugin/uv.lock is out of sync; refreshing local lockfile and retrying uv sync" >&2
- if ! uv lock --python 3.12 >&2 || ! uv sync --python 3.12 --quiet >&2; then
- write_failure "uv sync failed in $PLUGIN_ROOT after refreshing plugin/uv.lock — run 'uv lock --python 3.12 && uv sync --python 3.12' there to diagnose"
- fi
- fi
- # Defend against a stale lockfile silently dropping the project install.
- # When plugin/uv.lock pins a different claude-smart version than pyproject.toml,
- # `uv sync --locked` exits 0 but does NOT install the claude_smart package, so
- # every hook fails later with `ModuleNotFoundError: No module named 'claude_smart'`.
- # Catch that here with a clear, user-visible install-failed marker.
- if ! claude_smart_python_imports "$PLUGIN_ROOT" claude_smart.hook; then
- write_failure "uv sync left claude_smart uninstalled in $PLUGIN_ROOT/.venv — plugin/uv.lock is likely out of sync with pyproject.toml (regenerate with 'uv lock --project plugin' and reinstall the plugin)"
- fi
- install_vendored_reflexio
- if ! claude_smart_python_imports "$PLUGIN_ROOT" claude_smart.hook; then
- write_failure "claude-smart package is not importable after vendored Reflexio install in $PLUGIN_ROOT/.venv"
- fi
- # Dependency preparation does not choose or rewrite the user's connection.
- # The prepared runtime supplies missing defaults under its native settings lock.
- # Discard metadata stdout so the hook emits only its own continuation payload.
- PLUGIN_PYTHON="$(claude_smart_plugin_python "$PLUGIN_ROOT")"
- if "$PLUGIN_PYTHON" -I -m claude_smart.env_config bootstrap-repair >/dev/null; then
- :
- else
- repair_status=$?
- if [ "$repair_status" -eq 75 ]; then
- echo "[claude-smart] settings are busy; retry setup after the active save" >&2
- claude_smart_emit_continue
- exit "$repair_status"
- fi
- write_failure "Unable to repair startup settings; check the settings error above before retrying."
- fi
- claude_smart_source_reflexio_env
- verify_windows_local_embedding_runtime
- case "${CLAUDE_SMART_HOST:-claude-code}" in
- opencode)
- if [ -z "${CLAUDE_SMART_OPENCODE_PATH:-}" ] && ! command -v opencode >/dev/null 2>&1; then
- echo "[claude-smart] WARNING: 'opencode' CLI not on PATH and CLAUDE_SMART_OPENCODE_PATH is not set — reflexio extractors will have no LLM until OpenCode is installed" >&2
- fi
- ;;
- codex)
- if ! command -v codex >/dev/null 2>&1; then
- echo "[claude-smart] WARNING: 'codex' CLI not on PATH — reflexio extractors will have no LLM until Codex is installed" >&2
- fi
- ;;
- *)
- if ! command -v claude >/dev/null 2>&1; then
- echo "[claude-smart] WARNING: 'claude' CLI not on PATH — reflexio extractors will have no LLM until Claude Code is installed" >&2
- fi
- ;;
- esac
- LEGACY_CS_CITE="$HOME/.claude-smart/bin/cs-cite"
- if [ -e "$LEGACY_CS_CITE" ]; then
- rm -f "$LEGACY_CS_CITE"
- echo "[claude-smart] removed legacy cs-cite helper at $LEGACY_CS_CITE" >&2
- fi
- CLAUDE_SETTINGS="$HOME/.claude/settings.json"
- if [ -f "$CLAUDE_SETTINGS" ] && command -v node >/dev/null 2>&1; then
- node - "$CLAUDE_SETTINGS" <<'JS' >&2 || true
- const fs = require("fs");
- const path = process.argv[2];
- const entry = "Bash(cs-cite:*)";
- let data;
- try {
- data = JSON.parse(fs.readFileSync(path, "utf8") || "{}");
- } catch {
- process.exit(0);
- }
- const allow = data?.permissions?.allow;
- if (!Array.isArray(allow)) process.exit(0);
- const next = allow.filter((item) => item !== entry);
- if (next.length === allow.length) process.exit(0);
- data.permissions.allow = next;
- fs.writeFileSync(path, `${JSON.stringify(data, null, 2)}\n`);
- console.error(`[claude-smart] removed legacy ${entry} permission from ${path}`);
- JS
- fi
- # Spawn the dashboard build detached so install returns immediately and
- # Claude Code's install-hook timeout never kills a half-finished
- # `next build` (which would force the user into a manual /claude-smart:restart
- # recovery). dashboard-service.sh will also re-spawn this on SessionStart
- # if .next is still missing, and dashboard-open.sh detects the build-pid
- # file to surface a "still building" message instead of a generic error.
- DASHBOARD_DIR="$PLUGIN_ROOT/dashboard"
- if [ -d "$DASHBOARD_DIR" ]; then
- install_private_node || true
- fi
- if [ "${CLAUDE_SMART_DEFER_SERVICES:-}" = "1" ]; then
- :
- elif [ -d "$DASHBOARD_DIR" ] && claude_smart_npm_available; then
- echo "[claude-smart] starting dashboard build in background (~1-2 min on first install)" >&2
- claude_smart_spawn_detached bash "$HERE/dashboard-build.sh" >/dev/null 2>&1
- elif [ -d "$DASHBOARD_DIR" ]; then
- reason="npm is not on PATH after private Node.js bootstrap"
- echo "[claude-smart] WARNING: $reason" >&2
- [ -f "$(claude_smart_dashboard_unavailable_marker)" ] || claude_smart_write_dashboard_unavailable "$reason"
- fi
- # Point ~/.reflexio/plugin-root at this install so slash commands can
- # reference one stable short path regardless of which install loaded us.
- if ! bash "$HERE/ensure-plugin-root.sh" "$PLUGIN_ROOT"; then
- echo "[claude-smart] WARNING: failed to set ~/.reflexio/plugin-root symlink — slash commands may not resolve" >&2
- fi
- start_backend_service
- write_success_marker
- if [ "${CLAUDE_SMART_DEFER_SERVICES:-}" = "1" ]; then
- echo "[claude-smart] install complete; the installer starts and reports services once the plugin is registered." >&2
- else
- echo "[claude-smart] install complete. Services start on session start when this setup uses them; see backend-service.sh status." >&2
- fi
- claude_smart_emit_continue
Ratings and comments
Sign in to rate this skill.
Sign inFree to use. If it’s helped, pass it on.