Docs ยท agents

Your agent, with a brain.

Every coding agent takes in outside context its own way. Some run a command when a session opens, some on every message, some only talk MCP. For each agent this page says what the brain gets through, what os-brain init writes for it and what you add by hand.

What a brain needs from an agent #

An agent reaches a brain in three ways. Hooks bring the brain in without being asked. Shell commands and MCP are how the agent asks the brain and writes to it: any agent that can run a command can use the CLI and MCP gives the same commands as tools. The tables below call each hook moment a channel, with MCP as the last one.

ChannelWhat it carriesWho decides
Session startThe brief: the clock, the guardrails, preferences, pinned facts and the working treeThe hook. Always.
Every messageMemories that match what you typedThe hook. Always.
Session endWhat the session did and whether it stored any of it, for the next briefThe hook. Always.
MCPNearly every command, as a toolThe model, when it thinks of it

The brief at session start matters most: the model has it before it decides anything. A hook runs every time, whether the model remembers or not. MCP runs only when the model decides to call it, which is most of the time and never all of the time. So init wires hooks wherever an agent has them and MCP fills the gaps.

Hooks for agents other than Claude Code, Copilot and Devin call brain/autoexec.sh, a three-line script init writes beside the database. It finds the brain from its own location, so the hook works from whatever directory the agent runs it in:

# brain/autoexec.sh, as init writes it
#!/bin/sh
# Written by `os-brain init`. Resolves this brain from its own location, so the
# hook works whatever directory the agent runs it from.
OS_BRAIN_HOME=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
export OS_BRAIN_HOME
exec os-brain "$@"

Those hook files name the script by absolute path, because these agents make no promise about the directory they run a hook from. The cost is that the file belongs to your checkout: keep it out of the repository and let each person run init in their own.

How init picks agents #

$ cd ~/src/yourproject
$ os-brain init                        # at a terminal: asks which agent
$ os-brain init --agent claude,cursor    # no question, exactly these

At a terminal, plain os-brain init lists the agents, marks the ones it found on this machine and asks. The last choice, "I will do it myself", wires nothing and prints the block each agent needs so you can add it by hand. With no terminal to ask (a script, </dev/null), it wires every agent whose config directory it finds in the project or in your home directory. --agent takes any of claude, codex, cursor, gemini, opencode, kilo, copilot, devin, qwen, hermes and continue.

Whatever it picks, init adds its entries beside what each file already holds and refuses a file it cannot parse rather than replacing it: a config somebody wrote by hand is worth more than a hook. Run it again and nothing changes. It never writes into CLAUDE.md or any other instruction file. A line in a markdown file is a request the agent may ignore, while a hook runs every time.

os-brain uninstall takes every entry back out (a dry run until --apply) and keeps the database.

Claude Code #

The hooks were designed around Claude Code and it carries every channel, plus one more during a turn that carries direct messages between live sessions.

ChannelIn Claude CodeHow
Session startWorksSessionStart runs os-brain wakeup
Every messageWorksUserPromptSubmit runs os-brain hook-recall on what you typed
Session endWorksStop at the end of each turn, SessionEnd when you quit
During a turnWorksPostToolUse runs os-brain hook-tool, so a message sent to a busy session lands on its next tool call
MCPWorksclaude mcp add, or .mcp.json
$ os-brain init --agent claude
  + SessionStart hook -> OS_BRAIN_HOME="$CLAUDE_PROJECT_DIR/brain" os-brain wakeup
  + Stop hook -> OS_BRAIN_HOME="$CLAUDE_PROJECT_DIR/brain" os-brain hook-stop
  + PostToolUse hook -> OS_BRAIN_HOME="$CLAUDE_PROJECT_DIR/brain" os-brain hook-tool
  + SessionEnd hook -> OS_BRAIN_HOME="$CLAUDE_PROJECT_DIR/brain" os-brain hook-end
  + UserPromptSubmit hook -> OS_BRAIN_HOME="$CLAUDE_PROJECT_DIR/brain" os-brain hook-recall
  + .claude/commands/who.md
  ...

Five hooks go into .claude/settings.json:

# .claude/settings.json, the hooks part
"hooks": {
  "SessionStart":     [{ "hooks": [{ "type": "command", "command": "OS_BRAIN_HOME=\"$CLAUDE_PROJECT_DIR/brain\" os-brain wakeup" }] }],
  "UserPromptSubmit": [{ "hooks": [{ "type": "command", "command": "OS_BRAIN_HOME=\"$CLAUDE_PROJECT_DIR/brain\" os-brain hook-recall" }] }],
  "PostToolUse":      [{ "hooks": [{ "type": "command", "command": "OS_BRAIN_HOME=\"$CLAUDE_PROJECT_DIR/brain\" os-brain hook-tool" }] }],
  "Stop":             [{ "hooks": [{ "type": "command", "command": "OS_BRAIN_HOME=\"$CLAUDE_PROJECT_DIR/brain\" os-brain hook-stop" }] }],
  "SessionEnd":       [{ "hooks": [{ "type": "command", "command": "OS_BRAIN_HOME=\"$CLAUDE_PROJECT_DIR/brain\" os-brain hook-end" }] }]
}

The hooks name the brain through $CLAUDE_PROJECT_DIR, which Claude Code sets, so there is no absolute path in the file. Commit it only if everybody working on the repository has os-brain installed: for anyone who does not, every session starts with a failing hook. --no-auto-recall leaves out UserPromptSubmit, which also turns off the prompt capture: the hook keeps what you type (up to 8000 characters, for 30 days) and os-brain utterances lists it.

init also writes slash commands into .claude/commands/ for seeing and messaging other live sessions: /who, /msg, /rdo, /dnd, /inbox, /accept and /reject. init --channel registers the direct-message channel server in .mcp.json, which wakes a session the moment a message arrives.

The hooks already bring memories in on every message and Claude Code can run os-brain commands, so MCP is optional. Add it when you want the model to use typed tools instead of shell commands:

$ claude mcp add brain -- os-brain mcp

Claude Code starts the server in the project, so it finds the brain with no path. On a shared store add -e OS_BRAIN_PROJECT=yourproject; the MCP page says why the server refuses to guess.

Codex CLI #

Codex runs Claude-style hooks from its own .codex/hooks.json and carries every channel. Two of its rules decide whether the hooks run at all.

ChannelIn CodexHow
Session startWorksSessionStart in .codex/hooks.json, matching startup|resume
Every messageWorksUserPromptSubmit, recall on what you typed
Session endWorksStop
MCPWorksA stdio server in Codex's own config
$ os-brain init --agent codex
  + Codex SessionStart hook -> /home/you/src/yourproject/brain/autoexec.sh wakeup --emit codex
  + Codex UserPromptSubmit hook -> /home/you/src/yourproject/brain/autoexec.sh hook-recall --emit codex
  + Codex Stop hook -> /home/you/src/yourproject/brain/autoexec.sh hook-stop --emit codex

Codex runs a hook only when its hooks feature is on and each hook has been reviewed. The interactive CLI asks the first time it meets one; a headless codex exec skips unreviewed hooks unless you allow them. Codex also reads a hook's output as JSON whenever it starts with [ and marks the hook failed if that does not parse. The brain's recall block starts [brain], so --emit codex hands it over in the JSON shape Codex reads. If you wired Codex with an older build, run init again: it replaces the brain's old entries rather than adding a second set, which would brief twice.

Cursor #

ChannelIn CursorHow
Session startWorkssessionStart, with the brief in additional_context
Every messageNot availableCursor's prompt hook can block a message but cannot add to it. Use MCP.
Session endWorksstop and sessionEnd
MCPWorksA stdio server in Cursor's MCP settings
# .cursor/hooks.json, as init writes it in ~/src/yourproject
{
  "version": 1,
  "hooks": {
    "sessionStart": [{ "command": "/home/you/src/yourproject/brain/autoexec.sh wakeup --emit cursor" }],
    "stop":         [{ "command": "/home/you/src/yourproject/brain/autoexec.sh hook-stop" }],
    "sessionEnd":   [{ "command": "/home/you/src/yourproject/brain/autoexec.sh hook-stop" },
                     { "command": "/home/you/src/yourproject/brain/autoexec.sh hook-end" }]
  }
}

Cursor takes no plain text from a session-start hook: context arrives only in the JSON field additional_context, which is what --emit cursor produces. Its prompt hook is deliberately not wired, since a recall hook there would run on every message and inject nothing. So recall only happens when the model asks for it: add os-brain mcp as a stdio server in Cursor's MCP settings with OS_BRAIN_HOME set to the project's brain directory.

Cursor also runs the hooks in .claude/settings.json. In a repository wired for both (init --agent claude,cursor) the Claude hook notices from the payload that Cursor started it and that Cursor's own hook carries the brief, so it stays quiet and the brief arrives once. A Claude Code session started from Cursor's terminal is unaffected.

Gemini CLI #

Gemini carries every channel a brain needs, so nothing has to go through MCP that a hook can do instead.

ChannelIn GeminiHow
Session startWorksSessionStart
Every messageWorksBeforeAgent runs recall on what you typed
Session endWorksAfterAgent at the end of each turn, SessionEnd when you quit
MCPWorksmcpServers in .gemini/settings.json
# .gemini/settings.json, the hooks part
"hooks": {
  "SessionStart": [{ "hooks": [{ "type": "command", "command": "/home/you/src/yourproject/brain/autoexec.sh wakeup --emit gemini" }] }],
  "BeforeAgent":  [{ "hooks": [{ "type": "command", "command": "/home/you/src/yourproject/brain/autoexec.sh hook-recall --emit gemini" }] }],
  "AfterAgent":   [{ "hooks": [{ "type": "command", "command": "/home/you/src/yourproject/brain/autoexec.sh hook-stop --emit gemini" }] }],
  "SessionEnd":   [{ "hooks": [{ "type": "command", "command": "/home/you/src/yourproject/brain/autoexec.sh hook-end" }] }]
}

Gemini reads a hook's output only as JSON (hookSpecificOutput.additionalContext), which is what --emit gemini is for. It also passes everything added so far into the prompt it hands the next hook; os-brain strips that out before it searches, so recall matches what you typed and not the brief. SessionEnd is not awaited, so it gets only the cheap bookkeeping of hook-end.

OpenCode #

OpenCode runs no hook commands. It loads JavaScript plugins instead, so init writes one and every channel works through it.

ChannelIn OpenCodeHow
Session startWorksThe plugin adds the brief to the system prompt, once per session
Every messageWorkschat.message: recall on what you typed, sent with that turn
Session endWorkssession.idle, at the end of each turn
MCPWorksA local server in OpenCode's config
$ os-brain init --agent opencode
  + OpenCode plugin -> /home/you/src/yourproject/.opencode/plugins/brain.js

Only a session somebody typed into gets the brief. The extra model call OpenCode makes to name a session does not, since briefing it paid for the whole brief again and left a session that never ended. The plugin runs the brain's own autoexec.sh and hands it OpenCode's session id, so a session's start and end land on the same record. If a brain.js of your own is already there, init leaves it alone and prints the plugin for you to merge by hand. os-brain uninstall removes the plugin only if init wrote it.

Kilo #

Kilo takes the same plugin as OpenCode, at its own path, so everything in the OpenCode section applies.

$ os-brain init --agent kilo
  + Kilo plugin -> /home/you/src/yourproject/.kilo/plugin/brain.js

Kilo reads .kilo/plugin/ (singular) and ignores .opencode/plugins/, so a repository where some people use OpenCode and some use Kilo can carry both and nobody is briefed twice. Plain init finds Kilo through .kilo in the project, ~/.kilo or ~/.config/kilo.

Copilot CLI #

Copilot CLI runs the hooks in .claude/settings.json and sends them Claude Code's own payloads, so it takes the same wiring as Claude Code. The difference is the reply: Copilot reads only JSON. The brain tells the two agents apart and answers each in its own format.

$ os-brain init --agent copilot
  + SessionStart hook -> OS_BRAIN_HOME="$CLAUDE_PROJECT_DIR/brain" os-brain wakeup (Copilot CLI reads this file)
  ...

That writes Claude Code's hook file even if nobody on the project uses Claude Code, because that is the file Copilot reads. Using one file means a project used from both agents gets one brief in each and never two. Copilot also reads .github/hooks/; leave the brain out of there, or every session gets the brief twice.

Devin CLI #

Devin CLI runs .claude/settings.json as Copilot does and reads only the JSON form of the reply, which the brain sends it.

$ os-brain init --agent devin
  + SessionStart hook -> OS_BRAIN_HOME="$CLAUDE_PROJECT_DIR/brain" os-brain wakeup (Devin CLI reads this file)
  ...

Devin also reads .devin/hooks.v1.json, so the brain stays out of there. Devin skips a SessionStart entry whose matcher lists Claude Code's session sources, so the brain's entry has no matcher at all.

Qwen Code #

Qwen Code takes Claude Code's hook format and payloads and reads plain output, from its own .qwen/settings.json. It does not look at .claude/.

$ os-brain init --agent qwen
  + Qwen Code SessionStart hook -> /home/you/src/yourproject/brain/autoexec.sh wakeup
  + Qwen Code UserPromptSubmit hook -> /home/you/src/yourproject/brain/autoexec.sh hook-recall
  + Qwen Code Stop hook -> /home/you/src/yourproject/brain/autoexec.sh hook-stop
  + Qwen Code SessionEnd hook -> /home/you/src/yourproject/brain/autoexec.sh hook-end

Hermes Agent #

Hermes keeps its hooks in ~/.hermes/config.yaml: one file for your whole user, outside every project. Rewriting somebody's agent config to wire one project is not init's call, so it prints the block instead, with this project's paths filled in:

$ os-brain init --agent hermes
...
    hooks:
      pre_llm_call:
        - {command: "/home/you/src/yourproject/brain/autoexec.sh hook-recall --emit hermes", timeout: 20}
      on_session_end:
        - {command: "/home/you/src/yourproject/brain/autoexec.sh hook-stop", timeout: 15}

the brain exists but nothing reads it until the block above is added

pre_llm_call is the only Hermes hook whose output reaches the model, so it carries the brief on a session's first turn as well as recall. The hooks run from Hermes's own install directory, not your project, so they name the brain through the script's absolute path and one Hermes setup reads one brain. If hooks: is already in the file, merge the entries into it rather than adding a second key. Hermes asks you to approve new hooks the first time they run.

Continue CLI #

Continue's CLI loads hook files and never fires them, so the brain reaches it through MCP only, when the model decides to ask. init prints the server block for the YAML config you run cn with:

$ os-brain init --agent continue
...
    mcpServers:
      - name: brain
        type: stdio
        command: os-brain
        args: [mcp]

The server starts in the project, so this one entry finds the right brain wherever you run cn. On a shared store add env: {OS_BRAIN_PROJECT: yourproject}.

Cline CLI #

Cline's CLI throws away what its hooks print, so nothing a hook says reaches the model and init writes nothing for it. The brain gets in through MCP: create the brain with plain os-brain init and add os-brain mcp to ~/.cline/data/settings/cline_mcp_settings.json with OS_BRAIN_HOME in its env.

Here OS_BRAIN_HOME is required. The Cline CLI starts every MCP server from one shared background process, which sits in whichever project started it first, so a server that looked for its brain in the current directory would answer from another project with no warning. The server recognises Cline and refuses every call until OS_BRAIN_HOME or OS_BRAIN_PROJECT names the brain:

this server cannot tell which brain you mean: Cline starts MCP servers from one shared process
whose directory is whichever project started it first, so the working directory names the wrong
project as often as the right one. Set OS_BRAIN_HOME to this project's brain directory (and
OS_BRAIN_PROJECT on a shared store) in the server's env in ~/.cline/data/settings/cline_mcp_settings.json

That file is per user, so it points at one brain. Moving to another project means editing the path.

Any other agent #

An agent that can run a shell command can use the CLI as it is: tell it to run os-brain brief at the start and os-brain recall before it searches files. An agent that speaks MCP over stdio can run os-brain mcp; start with the MCP page. Neither gives you the brief before the first turn, which is what hooks are for, so if your agent has hooks of its own tell us how they work.

Check it worked #

Each hook is a command you can run yourself. If a session does not seem to know what the brain holds, run the hook by hand from the project and look at what it prints:

$ os-brain wakeup --no-cursor                                 # Claude Code, Copilot, Devin, Qwen
$ ./brain/autoexec.sh wakeup --emit cursor --no-cursor         # Cursor: one JSON object
{"additional_context":"## THIS PROJECT HAS A BRAIN ...
$ echo '{"prompt":"what port does staging use"}' | ./brain/autoexec.sh hook-recall --emit gemini
{"hookSpecificOutput":{"additionalContext":"[brain] 2026-11-21 00:05 GMT (Saturday night)","hookEventName":"BeforeAgent"}}

--no-cursor keeps the last-brief marker where it was, so the next real session still sees what is new. If the command prints the brief but the agent never shows it, the agent did not run the hook: open a new session rather than resuming an old one, check the agent trusts the folder and see troubleshooting.