instinct
by koscak-labs
README.md
> AI agent setting this up? Follow [AGENTS.md](AGENTS.md): run its install and connect commands. Connecting the hooks is part of setting Instinct up.
# Instinct
Instinct keeps the fix when the chat ends. Once you figure out how to run your project’s tests offline, you or your coding agent can save the command on your computer. The next time those tests fail, even a different connected agent can look up what worked.
- **See it work:** [Claude saved a rule. A fresh Codex used it to print four correct badges.](bench/relay/README.md) No install needed.
- **Try it yourself:** [Save a fix and find it in a fresh session.](#see-it-in-30-seconds)
- **Already installed?** Run `instinct doctor` to see what’s connected and what still needs setup.
<p align="center">
<a href="https://koscak.ai/instinct/"><img src="docs/assets/readme/hero.svg" alt="instinct: a dark field of faint drifting nodes, one ignites lime and a single thread runs to one lesson that fits, or nothing." width="100%"></a>
</p>
<p align="center">
<a href="https://github.com/koscak-labs/instinct/releases/latest"><img src="https://img.shields.io/github/v/release/koscak-labs/instinct?style=flat-square&label=release&color=beff3f&labelColor=070907" alt="Latest release"></a>
<a href="https://crates.io/crates/instinct-cli"><img src="https://img.shields.io/crates/d/instinct-cli?style=flat-square&label=crates.io&color=beff3f&labelColor=070907&logo=rust&logoColor=white" alt="crates.io downloads"></a>
<a href="https://github.com/koscak-labs/instinct/actions/workflows/candidate.yml"><img src="https://img.shields.io/github/actions/workflow/status/koscak-labs/instinct/candidate.yml?branch=main&style=flat-square&label=CI&labelColor=070907&logo=githubactions&logoColor=white" alt="CI"></a>
<a href="https://github.com/koscak-labs/instinct/actions/workflows/portable.yml"><img src="https://img.shields.io/github/actions/workflow/status/koscak-labs/instinct/portable.yml?branch=main&style=flat-square&label=windows%20%7C%20macos&labelColor=070907" alt="Windows and macOS"></a>
<a href="LICENSE"><img src="https://img.shields.io/github/license/koscak-labs/instinct?style=flat-square&color=beff3f&labelColor=070907" alt="License: Apache-2.0"></a>
<br>
<a href="https://x.com/PhilPhauler"><img src="https://img.shields.io/badge/X-%40PhilPhauler-000000?style=flat-square&logo=x&logoColor=white" alt="Follow on X"></a>
<a href="https://instagram.com/philphauler"><img src="https://img.shields.io/badge/Instagram-%40philphauler-E4405F?style=flat-square&logo=instagram&logoColor=white" alt="Follow on Instagram"></a>
</p>
**English** | [简体中文](README.zh-CN.md) | [日本語](README.ja.md)
Works with Claude Code · Codex · Cursor · Copilot · Gemini CLI · any MCP agent
<p align="center">
<img src="docs/assets/readme/demo.gif" alt="Terminal demo: instinct starter --apply banks 40 tripwire lessons, instinct guard warns before rm -rf on an unset variable, then a lesson is banked, recalled, marked as a hit, and shown under Paid off in instinct eval." width="100%">
</p>
**Install**
```sh
curl -fsSLO https://raw.githubusercontent.com/koscak-labs/instinct/main/install.sh
sh install.sh
```
Then add the Claude Code plugin. It warns before risky shell commands from the first one, and serves your lessons over MCP:
```sh
claude plugin marketplace add koscak-labs/instinct
claude plugin install instinct@koscak-labs
```
Inside a Claude Code session, the same steps are `/plugin marketplace add koscak-labs/instinct` and `/plugin install instinct@koscak-labs`. Windows, Rust and other agents: [Install](#install).
- **About 82x fewer bytes per prompt** than the same lessons in a CLAUDE.md. [Memory-file bench](bench/flat-file/README.md)
- **Killed shells fell from 8.4 a day to 0.3** with tripwires, 57 days on our own machine. [Field report](docs/field-report.md)
- **Hooks answer in about 12 to 15 ms** at 2,000 lessons. [PR #59](https://github.com/koscak-labs/instinct/pull/59)
⭐ Star it if your agent should stop repeating your corrections.
### What happens to a saved fix?
If no saved lesson fits, Instinct returns nothing. You or your agent can mark a lesson when it helps or gets in the way. Lessons that repeatedly miss stop being suggested. In Claude Code, the plugin can also warn before a risky command runs.
It plugs into Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode and more than 70 other agents through a skill, an MCP server, hooks or a few lines in `AGENTS.md`. It runs offline, needs no API key, and the engine has no third-party dependencies.
[](#install)
**[Grade your CLAUDE.md](https://koscak-labs.github.io/instinct/playground/)** in your browser: paste it and see how many tokens it adds to every prompt, next to what Instinct would add. Nothing leaves the page. The same page runs the real engine, compiled to WebAssembly. Save a lesson, mark it wrong twice, and watch it go quiet. You can share what you built as a link.
## See it in 30 seconds
Install first with the prebuilt binary above (or build it, see [Install](#install)). Then save a lesson and describe a situation where it applies:
```sh
export INSTINCT_STORE="$(mktemp -d)/bank.hxdb" # a throwaway bank for this try-out; skip it to use your real one
instinct bank --title 'Run the tests offline' \
--when 'Running the test suite in this repo' \
--found 'Tests fail when cargo tries to reach crates.io from the CI runner' \
--how 'Run cargo test --locked --offline' \
--reconsider 'If you add a dependency, fetch it once with the network on' \
--evidence 'CI failed twice online and passed offline'
instinct recall --q 'the test suite keeps failing on CI' --k 1
```
```text
[in-ux8hsjq] Run the tests offline (strength 0.50, 0 hit / 0 miss)
WHEN: Running the test suite in this repo
FOUND: Tests fail when cargo tries to reach crates.io from the CI runner
HOW: Run cargo test --locked --offline
EVIDENCE: CI failed twice online and passed offline
RECONSIDER: If you add a dependency, fetch it once with the network on
VALIDITY: source claim not independently verified; candidate, check original evidence
```
Ask about something unrelated, like `instinct recall --q 'write a birthday toast for my sister'`, and it prints nothing.
Then record how the lesson worked out. A hit raises its strength and a miss lowers it:
```sh
instinct hit in-ux8hsjq --note 'offline run passed'
```
Strength goes from 0.50 to 0.67. Two misses silence a lesson with no hits. This one has a hit, so it takes three, and then recall stops returning it. Its history stays in the file.
When you are done, run `unset INSTINCT_STORE` so the next commands use your real bank (`~/.local/share/instinct/bank.hxdb`) instead of the throwaway one.
## Try a decision workflow
Run `instinct guide review --example spreadsheet` to see an agent catch a postal code that lost its leading zeros, draft a lesson and hand the check to the next agent. For your own task, try `instinct guide prepare --q "Check the shared document for a guest"`. To take the interactive guide onto a phone or laptop, run `instinct guidebook > instinct-guidebook.html` and open the file in a browser. The same workflows are available from MCP or as a skill in ordinary chat. [Explore the ten workflows and ten examples](skills/instinct/references/workflows.md)
## What it saves your agents
| | What we measured | Details |
| --- | --- | --- |
| Tokens | At 80 lessons, a lookup adds about 280 bytes to the prompt. Pasting the same lessons as one memory file adds 22,957, about 82 times more. | [Memory-file bench](bench/flat-file/README.md) |
| Lookup time | A warm lookup through the MCP server takes 0.22 ms at 10,000 lessons. A cold CLI call takes about 5 ms at 100 lessons. | [Storage measurements](docs/helix-showcase.md) |
| Asking you again | With the lesson available, a fresh Codex printed all four badges. With an empty bank, it stopped and asked for the desk note. | [Handoff test](bench/relay/README.md) |
| Context per task | Across six first-use tasks, the lessons handed over came to 4,365 bytes, against 13,776 for always including the whole bank. | [First-use replies](bench/first-use/README.md) |
These are small, scripted tests on one machine, and they measure what reaches the agent more than what it does with it. In one run, framing the lesson for the agent made replies slower end to end (9.7 to 13.9 s against 3.0 to 5.2 s unaided), so measure it on your own work. [Transfer experiment](bench/README.md)
### See your own numbers
Every lookup adds one line of counts to a small file next to your bank: how many lessons it handed over, how many bytes, and how long it took. It never stores your questions or lessons. `instinct stats` adds it up:
```text
Savings, all recorded time:
lookups served 50 (40 found a lesson, 10 found nothing)
kept out of prompts 318,760 bytes versus pasting the whole bank each time, about 79.7k tokens (estimate, about 4 bytes per token)
lookup time 1.0 ms median, 1.1 ms p95
hits / misses 24 / 0 recorded on the bank
lessons proven 8 (2+ hits, strength 0.6 or more)
```
`instinct stats --share` turns that into one line you can post. Set `INSTINCT_METER=0` to turn the meter off.
Instinct also times your agent's shell commands by kind (`cargo test`, `gh run watch`, ...), warns before one that usually takes over 30 s in the foreground, and `instinct speed` shows where the time goes: [docs/speed.md](docs/speed.md).
## Tripwires before risky commands
Instinct can also speak up right before your agent acts. `instinct guard` runs as a pre-tool hook. When the agent is about to run a command that a saved lesson is about, the lesson reaches the agent as a warning. It never blocks the command, and it stays silent when nothing fits.
```sh
instinct bank --title 'pkill -f can kill your own shell' \
--when 'Stopping a process with pkill -f and a pattern' \
--found 'The pattern also matched the shell running the command, so the script died' \
--how 'Find the exact PID with pgrep, then kill that PID' \
--evidence 'Shell exited mid-script twice' \
--tags 'tool_bash pkill;pkill pattern'
```
Now, before `pkill -f server`, the agent reads "Instinct tripwire (advisory, nothing is blocked): a saved lesson fits this action", followed by the lesson. Before `ls -la` or `kill 4242`, it reads nothing. Tag command lessons with `tool_` plus the tool name and the command, like `tool_bash pkill`, so the guard can match them. The tool name only counts through a tag, so a lesson that merely mentions bash will not fire on every shell command. A check takes about 9 ms. In Claude Code the `instinct-autorecall` plugin turns tripwires on, and Codex takes the same hook ([setup](docs/connect.md#tripwires)).
An empty bank has nothing to say, so the hooks add the 40 starter tripwires the first time they meet a new bank (set `INSTINCT_STARTER=0` to skip it). `instinct starter --apply` does the same by hand: tripwires for classic agent disasters (`rm -rf` on an empty variable, `git push --force`, `git reset --hard`, `DROP TABLE`, `terraform destroy`, `curl | sh`), each with the safe alternative; run it without `--apply` to read the list first.
## Team memory
Run `instinct team init` in a repo and commit `.instinct/`. A teammate banks with `instinct bank --team ...`, you pull, and your agents get the lesson through the same hooks, after your own bank.
Hits and misses on a team lesson go to the same file, so the team shares the evidence. The file is plain lines that git merges with `merge=union`, and a line that arrives twice counts once.
Set `INSTINCT_TEAM=0` to read your own bank only. Details in [docs/connect.md](docs/connect.md#team-memory).
## Install
### 1. Install the `instinct` command
Every route below calls this command, so install it first. On Linux or macOS, download the script, read it, then run it:
```sh
curl -fsSLO https://raw.githubusercontent.com/koscak-labs/instinct/main/install.sh
sh install.sh
```
On Windows, in PowerShell:
```powershell
Invoke-WebRequest https://raw.githubusercontent.com/koscak-labs/instinct/main/install.ps1 -OutFile install.ps1; powershell -ExecutionPolicy Bypass -File .\install.ps1
```
The script downloads the binary for your system from the latest release, checks it against the release's `SHA256SUMS` and refuses to install on a mismatch. It puts `instinct` in `~/.local/bin` (`%LOCALAPPDATA%\instinct\bin` on Windows), tells you if that folder is not on your PATH, and changes nothing else. Set `INSTINCT_VERSION=v0.3.0` to pick a release and `INSTINCT_INSTALL_DIR` to pick the folder.
#### With Rust
Rust 1.89 or later builds it from the GitHub release tag. crates.io lags the GitHub releases, so `cargo install --locked instinct-cli` can install an older version:
```sh
cargo install --locked --git https://github.com/koscak-labs/instinct --tag v0.3.7 instinct-cli
instinct demo
```
`instinct demo` uses a throwaway bank and shows what a fresh agent gets for a familiar request and for an unrelated one.
### 2. Choose where your lessons live
Nothing to set up. With no configuration, Instinct keeps one bank per user at:
| System | Default bank |
|---|---|
| Linux, macOS | `$XDG_DATA_HOME/instinct/bank.hxdb`, else `~/.local/share/instinct/bank.hxdb` |
| Windows | `%LOCALAPPDATA%\instinct\bank.hxdb` |
Instinct creates the folder readable by you alone (mode 700 on Unix). Every agent on the machine shares the same bank, so they share what each one learns. To keep a bank elsewhere, set `INSTINCT_STORE` to a file path in the shell profile that starts your agents; it takes priority over the default.
### 3. Connect your agent
For most agents, one command adds the skill. Run it in your project and pick your agent from the list:
```sh
npx skills add koscak-labs/instinct --skill instinct
```
The skill tells your agent when to look up a lesson and when to save one. For MCP, hooks or an `AGENTS.md` block instead, see the next section. In Claude Code you can also install everything at once, from a shell:
```sh
claude plugin marketplace add koscak-labs/instinct
claude plugin install instinct@koscak-labs
```
Or inside a session: `/plugin marketplace add koscak-labs/instinct`, then `/plugin install instinct@koscak-labs`.
For the MCP server in Cursor or VS Code, one click adds it. Install the binary from step 1 first, because the buttons only register `instinct mcp`:
[](https://cursor.com/install-mcp?name=instinct&config=eyJjb21tYW5kIjoiaW5zdGluY3QiLCJhcmdzIjpbIm1jcCJdfQ%3D%3D) [](https://vscode.dev/redirect?url=vscode%3Amcp%2Finstall%3F%257B%2522name%2522%253A%2522instinct%2522%252C%2522command%2522%253A%2522instinct%2522%252C%2522args%2522%253A%255B%2522mcp%2522%255D%257D)
Start a fresh session. The next time your agent gets something right that it got wrong before, ask it to save the lesson.
Check your setup: `instinct doctor`
## Connect Claude Code, Codex, Cursor or any other agent
Instinct works with anything that can run a command or talk to an MCP server. Pick the first route your agent supports:
| Route | Works with | Setup |
| --- | --- | --- |
| Skill | [79 agents](https://github.com/vercel-labs/skills/blob/main/docs/agents.md), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, Roo Code, Kilo Code, Zed, Junie, Kiro, Goose, Amp, OpenCode and Warp | `npx skills add koscak-labs/instinct --skill instinct` |
| MCP server | Claude Code, Codex, OpenCode, Copilot CLI, VS Code, Cursor, Gemini CLI, Qwen Code, Cline, Roo Code, Kilo Code, Continue, Zed, Junie, Kiro, Claude Desktop, Goose, Amp, Droid, Windsurf, Warp and Crush | `instinct mcp` over stdio. [Config for each agent](docs/connect.md) |
| Prompt hook | Claude Code and Codex (tested; Codex needs `instinct codex-trust` once), plus Gemini CLI and Qwen Code from their docs | `instinct prompt` looks up a lesson on every prompt. [Setup](docs/connect.md) |
| Tool hook (tripwire) | Claude Code and Codex (live-tested; Codex needs `instinct codex-trust` once) | `instinct guard` warns before a command a lesson is about. [Setup](docs/connect.md#tripwires) |
| Instructions file | Any agent with a shell, including Aider | Paste [a short block](docs/connect.md#any-agent-with-a-shell-the-instructions-file) into `AGENTS.md` or your agent's rules file |
| Claude Code plugin | Claude Code | `claude plugin marketplace add koscak-labs/instinct && claude plugin install instinct@koscak-labs` (in a session: `/plugin marketplace add ...`, then `/plugin install ...`) |
The skill route needs `instinct` on the agent's PATH. The MCP server gives the agent tools to record project defaults, save or recall lessons, record feedback, list proven lessons, run a decision workflow and evaluate a defined check. Registering it by hand in Claude Code and Codex:
```sh
claude mcp add --transport stdio --scope local instinct -- instinct mcp
codex mcp add instinct -- instinct mcp
```
For automatic lookup in Claude Code, install `instinct-autorecall@koscak-labs`, or add this hook to `.claude/settings.local.json` and start Claude (set `INSTINCT_STORE` only if the bank lives elsewhere):
```json
{"hooks":{"UserPromptSubmit":[{"hooks":[{"type":"command","command":"instinct prompt"}]}]}}
```
The hook reads your prompt and working folder, finds at most one lesson, and adds it to the session. It never hands over the same lesson twice in one session; the record (`<store>.sessions`, ids and counts only) is pruned after 35 days. When you write again in the same session and a lesson from earlier still has no verdict, the hook adds one line asking the agent to record `instinct hit ID` or `instinct miss ID` if your message shows how it went. Your reply is the best evidence, and the question rides on a turn that is happening anyway, so the agent never takes an extra turn and its last answer stays its last answer. It asks once per session. When your message corrects the agent ("no, use pnpm"), the hook adds one line, once per session and after any verdict question, asking it to save the rule with `instinct bank` unless it is a one-off (`INSTINCT_CORRECTIONS=0` turns it off). For harnesses without a prompt hook, `instinct settle` asks the same question as a Stop hook (`--format codex` for Codex). The plugins and the CLI use the default bank when `INSTINCT_STORE` is not set.
**Judging lessons from what happened.** `instinct outcomes` joins each delivery in `<store>.sessions` to the Claude Code or Codex transcript of that session and reads what followed: after a prompt lesson, the next 3 user turns (was there a correction, did the agent act on words the lesson brought); after a tripwire, the next 8 tool calls (did the warned action fail again). Each delivery is labelled helped, misled, unused or unclear, with the evidence line. It is a dry run; `--apply` records a hit for helped and a miss for misled, once per delivery, and never on top of a hit or miss the agent recorded itself. To measure the effect itself, set `INSTINCT_EXPLORE=0.1`: the hooks then withhold that share of lessons (picked by a stable hash of session and lesson, so the same session always gets the same answer) and `outcomes` and `instinct eval` compare corrections and failures after delivered lessons against withheld ones, with counts and a plain warning while there are fewer than 30 observations per side. It is off by default. A window with no correction is not proof the lesson worked; the labels show what the transcript says, nothing more.
**Learning from sessions you already had.** `instinct mine` reads your Claude Code and Codex transcripts and finds two patterns: you corrected the agent and a later step passed or you confirmed, and a command failed and a changed command worked. No model, nothing leaves the machine. Keys, tokens and passwords are redacted, env dumps and one-off scripts are skipped, and windows that touch credentials or access (`authorized_keys`, `~/.ssh`, `.env`, `sshpass`, sudoers, `chmod 777`) are never mined. It is a dry run by default, shows the 10 most confident candidates (`--limit`), and `--apply` banks them as `source: mined`, which stay quiet until they earn a hit. Mining finds candidates; you decide what to bank.
**Spells.** The Claude Code plugin adds five one-word commands: `/instinct:learn` saves the fix that just worked, `/instinct:recall` shows what fits now, `/instinct:grade` grades this repo's memory file, `/instinct:stats` shows what Instinct saved, and `/instinct:wrong` marks the last lesson as a miss. The same spells for Codex and Gemini CLI are in [docs/spells.md](docs/spells.md).
**Two agents, one project.** If your agents work in different folders on the same project, save lessons with `--project lantern-studio` and set the hook to `instinct prompt --project lantern-studio`. Without `--project`, the hook uses the session's working folder. A lesson saved without a project shows up in every project that uses the same file.
**Two machines.** A laptop and a build server can share one workflow and still use different paths. Set `INSTINCT_MACHINE=laptop` on the laptop and save machine-specific lessons with `--applicability-machine laptop`. Those lessons only show up on that machine. [Two-machine example](skills/instinct/references/architecture.md#machine-specific-experience)
**Who you share with.** Anyone who can write to a bank can change what your agents are told. Share a bank only between agents and people you trust, and give everyone else their own file.
## Instinct vs CLAUDE.md and AGENTS.md
We measured 2,500 public memory files: the median adds about 784 tokens to every prompt, and the median `CLAUDE.md` about 1,043 ([census](bench/memory-file-census/README.md)). If you have a handful of rules, put them in `CLAUDE.md` or `AGENTS.md` and stop there. In our [Claude to Codex handoff test](bench/relay/README.md), pasting the lesson straight into the prompt worked as well as Instinct. Not sure how big yours is? Run `instinct audit CLAUDE.md`, or [grade it in your browser](https://koscak-labs.github.io/instinct/playground/). When the list has grown, `instinct import CLAUDE.md --apply` turns each rule into a lesson.
Instinct starts to pay off as the list grows, and when a lesson stops being true. We put 80 developer lessons in one memory file and in an Instinct bank, then asked 60 questions. Forty of them have a matching lesson and twenty are unrelated:
| | Memory file | Instinct (`--k 1`) |
| --- | ---: | ---: |
| Text added per question, all 60 | 22,957 bytes | 280 bytes |
| Wrong lessons added, 40 matching questions | 79 per question | 0 in total |
| Unrelated questions that got a lesson anyway | 20 of 20 | 1 of 20 |
| Right lesson ranked first | in the file, unranked | 36 of 40 |
| A lesson after three recorded misses | still in the file | no longer returned |
The memory file never misses a lesson it contains. Instinct missed 4 of 40, all of them questions worded differently from the lesson. No model read either version, so this measures what reaches the prompt and not what the agent does with it. [Lessons, questions and every result](bench/flat-file/README.md) · `cargo run --release --locked --offline --example flatfile`
What the agent does with it is measured separately, in a pre-registered agent benchmark: 360 fresh Claude Haiku sessions, 30 tasks plus 10 where no lesson applies. At 80 lessons, pasting them all into CLAUDE.md got the right first move more often (82%) than Instinct (60 to 66%). Instinct used 18 to 27% fewer input tokens. No setup applied a lesson where none fit. [Tasks, frozen hashes, raw receipts and regrade scripts](bench/proof/README.md)
## How recall works
```mermaid
flowchart LR
A["Your agent"] -->|"prompt or tool call"| H["instinct hook"]
B[("bank.hxdb")] --> R["scope, rank,<br/>two-word gate, quiet"]
H --> R
R -->|"one lesson or nothing"| A
A -->|"hit or miss"| B
B --> E["instinct eval"]
E -->|"quarantine, reword, merge"| B
```
Every step, constant and measured number is in [How Instinct works](docs/architecture.md).
A lesson has five parts: when it applies (`--when`), what was found (`--found`), the method (`--how`), the evidence (`--evidence`), and an optional note on when to reconsider (`--reconsider`).
Lookup matches words. Instinct ranks lessons with BM25 and returns one only when your question shares two words of four or more letters with its title, its `when` line or one of its tags. When you bank without `--tags`, one tag phrase is derived from the title. Common endings are folded, so "tests", "testing" and "tested" all match "test", and "updated" matches "update". Irregular forms (wrote, written) are not, and a question worded very differently can still miss a lesson that fits, so write the `when` line in the words you would use to ask about it later. To match by meaning as well, run [Ollama](https://ollama.com) and set `INSTINCT_OLLAMA=host:port` and `INSTINCT_EMBED_MODEL`. Lessons saved before that get embeddings when you run `instinct reembed`.
Looking a lesson up never changes its score. Only hits and misses do. Strength is (hits + 1) / (hits + misses + 2), so a new lesson starts at 0.50. Repeated misses silence a lesson, and `instinct instincts` lists the ones with at least two hits and a strength of 0.6 or more. Recall marks those lessons `proven in use` and tells the agent to act on them without re-checking the original evidence, unless the reconsider condition applies. `instinct decide` returns the same as `"proven": true`. You can quarantine a lesson to withdraw it while keeping its evidence, and `instinct retract` undoes a hit or miss recorded by mistake.
Every save, hit, miss, retraction and quarantine is written as a checksummed event to one local `.hxdb` file. The storage code is written in Helix, Koščák Labs' own language, and compiled to the plain Rust in `src/`, so `cargo install` needs nothing else. When another agent writes to the file, the next lookup rebuilds the index. [Storage, permissions and recovery](skills/instinct/references/architecture.md)
## Commands
| Command | What it does |
| --- | --- |
| `instinct bank --title … --when … --found … --how … --evidence …` | Save a lesson. `--reconsider`, `--project` and `--tags` are optional. |
| `instinct recall --q "…"` | Show the lessons that fit a situation. |
| `instinct decide --q "…"` | The same lookup, as JSON for your own code. |
| `instinct hit ID` and `instinct miss ID` | Record how a lesson worked out. Add `--note` to say why. |
| `instinct retract hit ID` or `instinct retract miss ID` | Undo a hit or miss recorded by mistake. |
| `instinct review ID --state quarantined --reason … --source-ref …` | Withdraw a lesson and keep its history. |
| `instinct instincts` | List lessons with at least two hits and a strength of 0.6 or more. |
| `instinct default ID --project P --instruction … --source-ref …` | Attach a standing instruction from the bank's owner. `--clear` removes it. |
| `instinct dream --q USUAL --changed CHANGED` | Show side by side which lessons the usual request and a changed one would get. Records nothing. |
| `instinct prompt` | Hook mode: read a prompt and print at most one lesson. |
| `instinct guard` | Tool hook mode: read a pre-tool payload and add a matching lesson as a warning. Never blocks. |
| `instinct mcp` | Run the MCP server over stdio. |
| `instinct doctor` | Check your setup: the bank, when `prompt` and `guard` last ran, and which of Claude Code, Codex, Gemini CLI, Cursor, Windsurf and Warp are wired, with the next command for each gap. Reads only. `--json`, `--store PATH`. |
| `instinct audit CLAUDE.md` | Grade a memory file: tokens it adds to every prompt, and what Instinct would add instead. `--share`, `--json`, `--k N`. |
| `instinct import CLAUDE.md --apply` | Turn each rule in a memory file into a lesson. Without `--apply` it only shows what it would save. Running it twice adds nothing new. |
| `instinct migrate --store old.jsonl --to new.hxdb` | Move an older JSONL bank to the current format. Pause its writers first. |
| `instinct stats` | What Instinct saved you: lookups served, tokens kept out of prompts, lookup time, proven lessons. `--since 7d`, `--json`, `--share`. |
| `instinct eval` | What your bank is doing for you: lessons that paid off, misled, were never judged or never fired, near-duplicates, savings, and the next three actions as runnable commands. `--since 7d\|30d\|all`, `--json`. Reads only; `--apply-quarantine` quarantines the misleading lessons and prints what it did. |
| `instinct outcomes [TRANSCRIPTS...]` | Judge delivered lessons from the session transcripts: helped, misled, unused or unclear, each with its evidence. `--since 7d`, `--json`. A dry run; `--apply` records hits and misses once per delivery. With `INSTINCT_EXPLORE` set it also compares delivered against withheld lessons. |
| `instinct mine [PATHS...]` | Find lesson candidates in past Claude Code and Codex sessions: a correction followed by a passing step or your confirmation, or a failed command followed by a changed one that worked. `--since 7d`, `--project P`, `--limit 10`, `--json`. A dry run; `--apply` banks the shown candidates as `source: mined`. Mining finds candidates; you decide what to bank. |
| `instinct scan [--days 30]` | A read-only report over your past Claude Code and Codex sessions: risky commands the starter tripwires would have caught, how often you corrected the agent, and what your memory files cost. `--json`, `--share`. No bank, no network, writes nothing. |
| `instinct export --store BANK` | Print every event in a bank as JSON lines. |
If a value starts with two dashes, attach it with an equals sign: `--found='--line: color-mix(...)'`.
### What did your agent get wrong last month?
<img src="docs/assets/readme/scan.svg" alt="Animated terminal: instinct scan is typed, then prints risky shell commands the starter tripwires would have caught (rm -rf on an unset variable, git push --force, curl | sh, DROP TABLE), how often the agent was corrected, and what CLAUDE.md costs; instinct scan --share then prints a 280-character summary. Run on a synthetic home folder." width="100%">
`instinct scan` reads the Claude Code and Codex transcripts already on your machine (`--days 30` by default) and prints one report. It needs no bank, uses no network and writes nothing.
It shows the shell commands the starter tripwires would have warned about, grouped by title with at most three redacted 60-character examples each. It counts how often you corrected the agent, and how often your next message was a correction again, compared with the same rate after any other message. It also estimates what your CLAUDE.md and AGENTS.md cost across the prompts in the window, in your user folders and in each project folder the sessions ran in (top 5 projects). The share text carries counts only. The detector counts clear corrections only, so the report calls its rates a floor.
Your prompts and the agent's replies are only counted, never printed. `--json` gives the same numbers, and `--share` prints a summary of at most 280 characters that you can paste anywhere; nothing is uploaded.
## Use it from your own code
A host program or agent framework can ask for lessons before it calls its model and pass them along as data:
```python
import json
import subprocess
def relevant_experience(situation, project):
reply = subprocess.run(
["instinct", "decide", "--project", project, "--q", situation],
capture_output=True, text=True, check=True,
)
return json.loads(reply.stdout)["experiences"]
```
Each match includes the method, the observed result, its evidence status, past hits and misses, and the condition for reconsidering. An empty list leaves the model to work it out. Your agent still makes the call, then saves what it learned or records a hit or miss.
## What we have tested
| Test | What happened | Details |
| --- | --- | --- |
| Claude to Codex | In a fictional badge-printing task, Claude saved a rule for which seats get a badge and whose name to print. A fresh Codex recalled it over MCP and printed all four badges. Pasting the lesson into the prompt also gave four. With an empty bank, Codex asked for the desk note. | [Inputs, controls and outputs](bench/relay) |
| First use | Claude pulled three lessons out of fictional chats. A fresh Codex used one to write Tess's client update in her format without asking for it again. Claude used the same format but added a recap she didn't want. On the editing tasks, both tools got it right without help. | [All 36 replies](bench/first-use/README.md) |
| Standing instructions | In a pricing task, an assistant that had seen one approved edit asked which fields it could change. Given the editor's standing instruction, it changed only the allowed fields and followed a later override. | [Cases and misses](bench/standing/README.md) |
| Everyday use | The engineering backtest, the everyday replay and the usage audit all include lookups that returned the wrong lesson and tasks where Instinct made no difference. | [Backtest](bench/backtest/README.md) · [Replay](bench/everyday/README.md) · [Audit](bench/usage.md) |
| 57 days of daily use | A private prototype ran on our main workstation for 57 days. Tripwires cut killed shells from 8.4 a day to 0.3. Raising the match threshold made each lesson better but delivered almost none, and feedback dried up unless something asked for it. Both shaped `instinct eval` and the once-per-session verdict question. | [Field report](docs/field-report.md) |
[](https://koscak.ai/instinct/replay/#proof)
The [transfer experiment](bench/README.md) has the discovery prompt, the saved lesson, the fresh tasks, the comparison conditions and the timings. More examples are in [use cases](docs/use-cases.md).
## FAQ
**Does Instinct work with my agent?** If your agent can run a shell command or connect to an MCP server, yes. [docs/connect.md](docs/connect.md) has setup for each agent we know, and which ones we tested ourselves.
**How is this different from CLAUDE.md or AGENTS.md?** A memory file goes into every prompt in full, and a wrong rule stays until someone edits it out. Instinct hands over the one lesson that fits, nothing when none does, and drops lessons that keep missing. With a few rules, the memory file is simpler.
**Does it save tokens?** Compared with pasting a memory file into every prompt, yes. At 80 lessons a lookup adds about 280 bytes where the file adds 22,957, and an unrelated question usually adds nothing. With only a few rules the difference is small.
**Is it fast enough to run on every prompt?** A warm lookup through the MCP server takes well under a millisecond, even at 10,000 lessons. A hook that starts the CLI each time takes a few milliseconds.
**Does it send my code or prompts anywhere?** No. Lookup runs on your machine. If you turn on embeddings, the text goes to the Ollama server you point it at.
**Can several agents or people share one bank?** Yes, by pointing them at the same file. Anyone who can write to it can change what your agents are told, so share it only with agents and people you trust.
**What if a lesson is wrong?** Record a miss. Two misses silence a new lesson. You can also quarantine it, and its history stays in the file.
## Contribute
Have a lesson other agents should learn? [Share it as an issue](https://github.com/koscak-labs/instinct/issues/new?template=share-lesson.yml), or build it in the [playground](https://koscak-labs.github.io/instinct/playground/) and post the link. The [community bank](https://github.com/koscak-labs/instinct/pull/16) is open for review. A good lesson has a situation people will recognize, a first move, evidence and an exception.
Got Instinct working with an agent or harness that is not listed in [docs/connect.md](docs/connect.md)? [Post the config](https://github.com/koscak-labs/instinct/issues/new?template=connect-agent.yml) so the next person can copy it. Questions and show-and-tell go in [Discussions](https://github.com/koscak-labs/instinct/discussions).
To work on the engine, read [CONTRIBUTING.md](CONTRIBUTING.md) and run the offline tests with `cargo test --locked --offline`. The optional model benchmark needs an authenticated model CLI, jq, mktemp and GNU timeout.
## Uninstall
In Claude Code, run `/plugin uninstall instinct@koscak-labs` (and `instinct-autorecall@koscak-labs` if you added it). Elsewhere, remove the skill folder and the MCP server or hook entry. Remove the binary with `cargo uninstall instinct-cli`. Delete the bank file only if you want to erase its history.
Made by Filip Koščák ([@philphauler](https://github.com/philphauler)) at Koščák Labs. Licensed under [Apache-2.0](LICENSE). [Notice](NOTICE)
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues