
instinct
io.github.koscak-labs/instinct
Agents bank what worked and recall it on the next similar task, from a local store.
Documentation
Instinct
Instinct warns your agent before rm -rf on an empty variable or git push --force, and hands it the one lesson that fits instead of your whole CLAUDE.md. One local memory of what worked, shared by every agent you use.
Install
cargo install --locked instinct-cli
Then, in Claude Code, add the plugin. It warns before risky shell commands from the first one, and serves your lessons over MCP:
/plugin marketplace add koscak-labs/instinct
/plugin install instinct@koscak-labs
Prebuilt binaries and other agents: Install.
- About 76x fewer bytes per prompt than the same lessons in a CLAUDE.md. Memory-file bench
- Killed shells fell from 8.4 a day to 0.3 with tripwires, 57 days on our own machine. Field report
- Hooks answer in about 12 to 15 ms at 2,000 lessons. PR #59
⭐ Star it if your agent should stop repeating your corrections.
You fix your agent's mistake on Monday. On Tuesday a fresh session makes it again, and the other agent you use never heard about it. Every repeat costs tokens, time and another question back to you.
Instinct gives all your agents one memory of what worked. When an agent finds a method that works, or you correct it, it saves the fix as a short lesson in a file on your machine. Before its next decision, any agent that reads that file gets the one lesson that fits, or nothing. Before a command a lesson is about, Claude Code and Codex get it as a warning. Lessons that keep getting marked wrong stop coming back.
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.
Grade your CLAUDE.md 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 cargo install --locked instinct-cli (or a prebuilt binary, see Install). Then save a lesson and describe a situation where it applies:
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
[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:
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.
What it saves your agents
| What we measured | Details | |
|---|---|---|
| Tokens | At 80 lessons, a lookup adds about 301 bytes to the prompt. Pasting the same lessons as one memory file adds 22,957, about 76 times more. | Memory-file bench |
| 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 |
| 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 |
| 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 |
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
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:
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.
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.
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).
An empty bank has nothing to say, so the hooks add the 36 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.
Install
1. Install the instinct command
Every route below calls this command, so install it first. With Rust 1.89 or later:
cargo install --locked 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.
Without Rust
Download the script, read it, then run it:
curl -fsSLO https://raw.githubusercontent.com/koscak-labs/instinct/main/install.sh
sh install.sh
On Windows, in 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.
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:
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:
/plugin marketplace add koscak-labs/instinct
/plugin install instinct@koscak-labs
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, 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 and Droid | instinct mcp over stdio. Config for each agent |
| Prompt hook | Claude Code (tested), plus Codex, Gemini CLI and Qwen Code from their docs | instinct prompt looks up a lesson on every prompt. Setup |
| Tool hook (tripwire) | Claude Code and Codex (payload-tested) | instinct guard warns before a command a lesson is about. Setup |
| Instructions file | Any agent with a shell, including Aider | Paste a short block into AGENTS.md or your agent's rules file |
| Claude Code plugin | Claude Code | /plugin marketplace add koscak-labs/instinct, then /plugin install instinct@koscak-labs |
The skill route needs instinct on the agent's PATH. The MCP server gives the agent four tools: save a lesson, look one up, record a hit or miss, and list proven lessons. Registering it by hand in Claude Code and Codex:
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):
{"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. 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.
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
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). 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, 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. 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 | 301 bytes |
| Wrong lessons added, 40 matching questions | 79 per question | 1 in total |
| Unrelated questions that got a lesson anyway | 20 of 20 | 1 of 20 |
| Right lesson ranked first | in the file, unranked | 38 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 6 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 · cargo run --release --locked --offline --example flatfile
How recall works
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.
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 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
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 and Cursor 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 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(...)'.
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:
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 |
| 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 |
| 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 |
| 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 · Replay · Audit |
| 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 |
The transfer experiment has the discovery prompt, the saved lesson, the fresh tasks, the comparison conditions and the timings. More examples are in use cases.
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 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 301 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, or build it in the playground and post the link. The community bank 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? Post the config so the next person can copy it. Questions and show-and-tell go in Discussions.
To work on the engine, read 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) at Koščák Labs. Licensed under Apache-2.0. Notice
instinct-clicargo install instinct-cli

