os-brain writes nothing into CLAUDE.md, AGENTS.md or any other instruction file. It reaches the agent through the hooks the agent already runs. This page is the reasoning behind that choice and the five things a markdown file cannot do.
An instruction file is text the model reads and then weighs against everything else in its context. "Check the brain before you search files" is a sentence like any other. Under a vague question the model's habit wins and it goes and opens the files.
A hook is a command the agent runs by itself at a fixed moment. os-brain init wires five of them for Claude Code and none of them depends on the model deciding to look:
SessionStart $ os-brain wakeup # the brief, before turn one UserPromptSubmit $ os-brain hook-recall # memories that match this prompt Stop $ os-brain hook-stop # what the session did and stored PostToolUse $ os-brain hook-tool # direct messages, mid turn SessionEnd $ os-brain hook-end # mark the session gone
The text that used to sit in an instruction file ("this project has a brain, recall before you search, write before you finish") now opens the brief instead. It is paid for once per session instead of staying resident in the context window for all of it. The agents page says what init wires for each of the other agents.
The per-prompt hook searches the brain for what you just typed and puts the matches in front of the model before it answers. The model does not have to think of asking.
$ # you type: why do the invoice PDFs lose their fonts on the new box? [brain] 2026-11-21 00:00 GMT (Saturday night) [invoices brain ยท local file] possibly relevant memories (os-brain get <id> for the full text): #4 [global/gotcha] The PDF renderer drops fonts when the cache dir is not writable — set FONTCONFIG_CACHE to a writable path in the unit file
An instruction file is loaded once, whole, whatever you go on to ask. This answers the question you actually asked, on the turn you asked it.
Nothing in a markdown file can say that one line replaced another. Both lines load into every session and the model goes with whichever one it noticed. --supersedes makes the new fact replace the old one and a search in the old words gets the new answer, with the old one kept as history.
A gotcha, state or incident carries the commit it was saved at. Recall prints tree unchanged since stored or 2 commits since stored with a reminder to re-check against source, fact by fact. A markdown file says nothing about when a line was written, so the only safe move is to re-read everything.
Infrastructure facts never fade. "The box is rebooting" loses half its weight every four days and is buried within two weeks without anyone deleting it. In a markdown file nothing fades, so the only edit anyone ever makes is to add more.
It ranks what it has, cuts the least important parts, names what it cut and prints the command to see the rest. By default it is 6000 bytes, about 1.5k tokens. Guardrails and preferences are printed first, so a host that truncates still keeps the part that binds.
A host moves or a key is rotated and nothing in the repository records it. infra and access memories get a review date 30 days out and show up as due when it passes. A line in a markdown file looks just as current on the day it goes wrong.
Only the person who made a decision can make it wrong, never a commit. Flagging one as stale invites people to argue it again. So the staleness line stays on a short list of types: a warning that shows on every memory is one everybody learns to skip.
Hooking the reads and leaving the writes to an instruction would keep half the problem. A session that learned five things and stored none would look exactly like one that learned nothing.
So the Stop hook closes each session's record and, when a session ran for a while or moved the tree and stored nothing, says so. The next session's brief says it again, once, under THE LAST SESSION HERE LEFT NOTHING BEHIND. A report at the end reaches the session that already failed. A report at the start reaches one that can still act.
Nothing forces a write and nothing should. A two-minute session, or one that stored something, is never flagged.
A brain beside another memory store that loads by itself guarantees a contradiction nobody sees: both are read into every session and the one that loads first wins, whichever is right.
init looks for one in both places it lives: a MEMORY.md or memory/ directory in the project and Claude Code's own auto-memory outside the repository under ~/.claude/projects/<slug>/memory/. When it finds one it says so. It never moves, rewrites or deletes it, because your own memory files are not init's to destroy.
If you want a committed, readable copy of what the brain holds, generate it with os-brain snapshot --out <file> --allow-tracked. Without that flag a path inside the repository that git does not ignore is refused, because a snapshot is every memory in cleartext. It carries a DO NOT EDIT header: edit the brain and regenerate, never the other way round. Do not call it MEMORY.md at the project root: init and the brief would report it as a second memory store.
A project's own top-level instructions belong to the project. How to build it, how to run the tests and the conventions of the codebase are stable and they belong in that file, written by you.
init reads CLAUDE.md for one reason: to tell you when it still carries the "Project memory" section an older install appended. The hook now carries that text, so the section is redundant. init says so and leaves the deleting to you.
What belongs in the brain is everything that changes or gets corrected: why an approach was turned down, what broke last time, a limit that is in no file, a preference you stated once. Those are the lines that go stale in a markdown file without anyone noticing.
Open your CLAUDE.md, your AGENTS.md or your .cursorrules. Pick five lines you can check: a file path, a count, a command name, a directory, a version number. Check each one against the code.
A file meant to save the agent from reading the code can only be checked by reading the code. If one of your five was wrong, every session since has loaded it with full confidence.
$ go install github.com/chka/os-brain/cmd/os-brain@latest # then, in the project you want it to remember $ os-brain init