Skip to content

Session Context ​

A wired repo's agent session starts with the dotbrain convention already in context. This page explains what gets injected, how, what the agent reads on its own, and how the session's hooks keep the dotbrain home in sync.

What Happens at Session Start ​

At startup, the runtime hook supplies the shared convention in a wired checkout. The selected workflow retrieves the relevant project records when needed.

The plugin's SessionStart hook runs dotbrain hook session-start. It fires on startup, resume, /clear, and compaction, so the convention survives a context reset. Before it injects the convention, it runs home sync.

What Is Injected ​

The shared convention .brain/DOTBRAIN.md, which Dotbrain owns and keeps current through dotbrain refresh. It covers wiring rules, where execution lives, the public/private boundary, and how the Brain is laid out. Private knowledge is not injected.

The project's own files are not injected:

FileLoaded how
.brain/DOTBRAIN.mdInjected by the hook
Public AGENTS.md and root RULES.mdRepository entry point routes making/reviewing changes to tracked rules, usable without a Brain
.brain/CONTEXT.md, adr/, designs/Read by the agent when the work needs them
.brain/docs/Relevant records read when their domain meaning, rationale, or evidence is needed
Beads workflow primerNot injected by dotbrain; the agent runs bd prime when it needs it

Use the owning implementation or maintained documentation for current mechanics. Check a historical record's applicability before relying on it. Reading a record does not itself require repairing it; scoped maintenance may remove obsolete records rather than keeping them in normal retrieval.

To have the Beads primer injected too, add Beads' own hook with bd setup claude or bd setup codex. Dotbrain does not install it.

Why not inject everything?

Dotbrain tests its session-start payload against a 10,000-byte budget. This budget comes from measured Claude Code behavior: 9,961 bytes reached the model, while 10,010 bytes were written to a file instead. It is not a verified limit for every runtime. DOTBRAIN.md has a bounded size; repository rules and private knowledge grow with the project. Injecting only the convention keeps the payload within that budget.

Home Sync ​

The plugin registers three hooks. Each one syncs the dotbrain home, the Git repository that holds every Brainspace, so Brain changes reach your other machines without a manual commit and push.

HookRunsWhat it does
SessionStartdotbrain hook session-startRuns a full sync and waits up to 10 seconds, then injects the convention. A slower sync keeps running in the background, and the session starts from local state. On compaction it only records and pushes, because compaction happens mid-turn.
Stopdotbrain hook stopAfter each turn of the main agent, starts a background sync that records and pushes without fetching, and returns at once. Files never change under a running agent.
SessionEnddotbrain hook session-endStarts a full sync in the background and returns at once; skipped on /clear, whose SessionStart syncs.

Hermes, OpenCode, Pi, and Cursor call dotbrain hook run, which reads no hook payload. It takes the event as --event startup|resume|clear|compaction|turn-end|session-end, the checkout as --checkout PATH (default: the working directory), and --format json to print the convention as {"additional_context": "..."}. Each event syncs as its hook above does: the session starts (startup, resume, clear) wait for a full sync and inject the convention; compaction and turn-end only record and push; session-end starts a full sync. A cleared session sends only clear, never session-end.

A full sync runs five steps:

  1. Record. Every uncommitted change becomes a sync commit: one per changed Brainspace, then one home commit for everything else. Files over the size limit and nested Git repositories are skipped and reported. Commits you wrote yourself are left alone. A skill submodule is recorded when it is new or moved forward to a commit its own remote holds.
  2. Fetch the upstream of the home's current branch.
  3. Integrate. Merge the upstream into the current branch. When both machines changed a file, this machine's version stays in place and the other machine's version is saved beside it as a conflict copy. When one side deleted a file and the other edited it, the edit wins. If incoming changes would overwrite an uncommitted or ignored local file, Git refuses the merge and sync reports its diagnostic without pushing.
  4. Push. If the remote moved in the meantime, sync fetches and tries again, at most three times. It never force-pushes.
  5. Update submodules. When the merge brought changes, a submodule is missing, or one is not at its recorded commit, sync checks out each recorded commit and clones new submodules. Compaction and turn-end syncs skip this step.

Home sync is quiet and fails open. It writes nothing to the agent's context, and a failure never blocks the session. Offline machines and homes without a remote keep their sync commits locally until a later sync can push them. Hooks sync only in a checkout wired to a Brainspace, or in the dotbrain home itself. A lock keeps two syncs on one machine apart. The full sync at session start briefly waits for a busy lock within its 10-second bound. The push-only sync after compaction and other sync entrypoints return at once if the lock is busy. Run dotbrain sync to sync by hand, and dotbrain doctor to see waiting commits, conflict copies, and skipped files. To turn sync off, see sync:.

Home sync does not sync the Beads tracker; dotbrain beads sync keeps its own path.

Known limits

  • Sync unstages everything before it records, so state that exists only in the index (partially staged hunks, git rm --cached, a staged mode change) is replaced by the working tree.
  • Nested Git repositories inside the home are never recorded.
  • A Git command you run in the home while a hook is committing can hit Git's lock error. Run it again.
  • When two machines changed the same lines, the merge that resolves the conflict rewrites those files in the shared home. Another session on the same machine can briefly see or overwrite them during that step. Sync refuses to merge over uncommitted edits that Git would overwrite.

Failing Open ​

The hook never blocks a session. Outside a git repo, in a repo that is not wired, or when dotbrain is not on PATH, it prints nothing and exits cleanly. The cost of that choice is that a broken setup is silent: if a session in a wired repo does not know the convention, run dotbrain doctor. See Troubleshooting.

Runtime Notes ​

  • Claude Code runs the hooks as soon as the plugin is installed.

  • Codex runs plugin hooks only after you trust them: open /hooks in codex, trust the dotbrain hooks, and start a new thread. Until then Codex sessions get no injected convention and do not sync. Codex runs session-end hooks with a short time limit, so that hook only launches the sync and returns. Whether Codex fires Stop for the main thread only, and whether it runs the Stop hook in the background, is not yet verified. Stop and session-end syncs exit at once if another sync is running, and a push-only sync returns quickly.

  • Hermes (see Hermes) runs the hooks once the plugin is enabled. Before the first model request of a session, the plugin runs dotbrain hook run --event startup and adds the convention to that first user message, not to the system prompt. Hermes keeps it in the session history, so a resumed session runs resume for the sync but gets no second copy. When compaction drops it from the history, the next turn runs compaction and adds it again. By default Hermes moves hook context over 10,000 characters to a file, so a convention must stay below that size. Hermes fires its own session-end hook after every turn, so that hook starts the turn-end push in the background. A real exit runs session-end. Delegated child agents get no convention and no sync.

  • OpenCode (see OpenCode) runs the hooks once the plugin file is in its config directory. Before the first model request of a session, the plugin runs dotbrain hook run --event startup and adds the convention to the system prompt of every request in that session; a session this OpenCode process did not create, such as one continued with opencode run -c, runs resume instead. After compaction it runs compaction and keeps adding the convention. When a run finishes and the session goes idle, it starts the turn-end push in the background. When OpenCode exits, it starts session-end for each idle session. Killing OpenCode or closing its window skips that step; the next session start syncs what was left. A config reload also shuts the plugin down, but while a session is still running it only pushes. Task subagents get no convention and no sync.

  • Pi (see Pi) runs the hooks once the extension is in its agent directory. At each session start, the extension runs dotbrain hook run (startup, resume, clear for /new, and compaction for a reload or fork) and adds the convention as a system prompt section on every run of that session. After compaction it runs compaction and keeps adding the convention; a failed refresh keeps the one it had. When a run settles, it starts the turn-end push in the background. /quit runs session-end. Closing the console window probably skips that step; the next session start syncs what was left.

  • Cursor (see Cursor) runs the hooks dotbrain adds to ~/.cursor/hooks.json. At sessionStart it runs dotbrain hook run --event startup with Cursor's project folder as the checkout, and returns the convention as context that accompanies every request of the session, so compaction does not drop it. A resumed session keeps the convention it started with; Cursor runs no sessionStart for it, so no startup sync either. Each stop starts the turn-end push in the background, and sessionEnd runs session-end. Closing the console window probably skips that step; the next session start syncs what was left.

  • In a runtime with no hook support, invoke the brain-convention skill to load the convention by hand, and run dotbrain sync yourself.

  • Antigravity loads the hook commands from plugin/hooks.json in the source tree. Dotbrain installs that file as hooks.json in the plugin directory. SessionStart runs dotbrain hook antigravity --event startup. Dotbrain reads JSON from stdin and looks for a wired checkout in cwd, then in workspacePaths. It waits up to 10 seconds for home sync, then returns DOTBRAIN.md as a systemMessage in injectSteps. Stop runs dotbrain hook antigravity --event turn-end. It starts a detached push-only home sync and returns {} immediately. Both commands use || echo {} to return an empty JSON object if the command fails. Antigravity has no SessionEnd hook for a full sync on exit.

    Use agy plugin enable dotbrain or agy plugin disable dotbrain to control activation. dotbrain doctor reads the setting in ~/.gemini/config/config.json. Antigravity manages that file.

Subagents ​

Dotbrain delivers selected custom Claude Code and Codex definitions; it ships no workflow agents. Use subagents: in global config.yaml or project project.yaml. The dotbrain- prefix is reserved to protect preserved old resources. Hermes, OpenCode, Pi, Cursor, and Antigravity receive no native custom subagents from Dotbrain.

Claude definitions are symlinks; Codex definitions are generated TOML copies with the # dotbrain-managed-agent: v1 marker. Edit the private source, not a generated copy. dotbrain subagents link reconciles the current checkout; use --scope global for global homes. Foreign resources and collisions are preserved and reported. Doctor inspects delivery; a successful native invocation is separate evidence that a runtime consumed a definition.

The selected workflow supplies assignments, context retrieval/capture timing, verification and recovery; its skills are selected like any other skills.

Released under the MIT License.