CLI Reference
Complete reference for every sourcebrain command. Commands work in both local and cloud mode unless noted. Auto-detection: if a .sourcebrain/ folder exists in the current directory or any parent, local mode is used; otherwise cloud mode.
All commands
Global flags
| Flag | Description |
|---|---|
-h, --help | Print help for any command |
--version | Print CLI version |
-p, --personal | Target your personal “My Lessons” space in the cloud instead of a workspace or local repo. Free saves up to 3 cloud lessons; Pro is unlimited. Requires login. |
init
sourcebrain init
sourcebrain init [name] [--local | --cloud] [--no-guided]
Initializes a new knowledge base. By default the mode is auto-detected from your login state:
- Logged in: creates a cloud workspace named
name(defaults to current directory name) and sets it as active. - Not logged in: creates
.sourcebrain/in the current directory for local mode.
Use --local to force a local repository even while logged in, or --cloud to require cloud mode. The two flags are mutually exclusive.
When run in an interactive terminal, init then offers a short guided setup: it can create a local .sourcebrain/ alongside a cloud workspace (so doctor and scan work), add .sourcebrain/ to your .gitignore, and, for Pro users, kick off an AI codebase scan. Pass --no-guided to skip it; it is skipped automatically in non-interactive shells (scripts, CI).
| Flag | Description |
|---|---|
--local | Force local mode even if you are logged in. |
--cloud | Force cloud mode (requires login). |
--no-guided | Skip the interactive guided setup after init. |
sourcebrain init # auto: cloud if logged in, else local sourcebrain init --local # always create a local .sourcebrain/ repo sourcebrain init --cloud my-team # cloud workspace named "my-team" sourcebrain init --no-guided # skip the post-init guided walkthrough
Status & orientation
Quick “where am I?” checks. Because SourceBrain auto-detects local vs. cloud mode, these tell you which backend a command would actually hit before you run it.
sourcebrain status
sourcebrain status
Prints a quick orientation snapshot, the CLI equivalent of git status. It reports which backend is active (a local .sourcebrain/ repository, a cloud workspace, or your personal @me space), your login state and server, the active workspace, the lesson count, and when the knowledge base last changed.
Run it whenever you're unsure whether you're working locally or against the cloud. It reads one lightweight listing, so it's cheap and needs no extra setup. In cloud mode it also prints the sourcebrain open hint for jumping to the web UI.
sourcebrain status sourcebrain status -p # your personal “My Lessons” space
sourcebrain whoami
sourcebrain whoami
Prints who you're logged in as on the cloud: your account email, billing plan, and the workspace commands currently target. A fast identity check when you juggle more than one account or server.
A cloud feature: you must be logged in. For a fuller local/cloud orientation (including whether you're inside a local repository and how many lessons it holds), use sourcebrain status.
sourcebrain whoami
sourcebrain guide
sourcebrain guide [--setup]
A guided tour of SourceBrain, tailored to your current setup. It opens with a checklist of where you are (logged in, active workspace, a local .sourcebrain/ repository, how many lessons are in reach) and the handful of commands most useful from there, then walks through the full tour. Safe to re-run whenever you want a refresher.
With --setup it instead runs the interactive walkthrough that init offers: create a local repository, add it to .gitignore, import existing knowledge files, and optionally kick off an AI codebase scan. Handy when you joined an existing workspace and never ran init on this machine.
| Flag | Description |
|---|---|
--setup | Run the interactive setup walkthrough instead of the tour (requires a terminal). |
sourcebrain guide # tailored checklist + full tour sourcebrain guide --setup # interactive local-repo setup
Lesson commands
sourcebrain add
sourcebrain add <path> [-c content] [-m message]
| Flag | Description |
|---|---|
-c, --content | Lesson content as a string. Skips the editor. |
-m, --message | Version note (like a commit message). Optional. |
--allow-secrets | Save even when the content looks like it contains credentials (e.g. a revoked example key). |
sourcebrain add auth/jwt # opens editor sourcebrain add auth/jwt -m "explain token lifetime" # opens editor, saves note sourcebrain add auth/jwt -c "JWT secret in env." -m "quick note"
sourcebrain import
sourcebrain import <file-or-dir>... [--under prefix] [--no-split] [--dry-run] [-y]
Brings preexisting knowledge, like CLAUDE.md and other agent memory files, docs folders, or note vaults, into SourceBrain without retyping it. Each file becomes a proposed lesson you review before anything is saved. Files can live anywhere on disk. Directories are walked for Markdown and text files; YAML front matter is stripped; the lesson path comes from the file's name and location.
A multi-section document is split into one lesson per top-level section, so a big CLAUDE.md or rules file becomes curated, per-topic lessons an agent can pull individually, not a single monolith. Pass --no-split to import each file whole.
Imports are safe to re-run: unchanged files are skipped, and a file that looks like it covers the same topic as an existing lesson is flagged during review so you can reconcile the two. No AI involved; in local mode nothing leaves your machine.
From a live database: a .sql file (DDL dump or migrations) turns into one draft schema node per CREATE TABLE, under db/<table>. You never hand SourceBrain a connection string; dump the schema with your database's own tool and import the file. Postgres (pg_dump), MySQL and MariaDB (mysqldump), SQLite (.schema), SQL Server (SSMS Generate Scripts), and Oracle dumps all work, and the dialect is detected automatically. Dump schema only, not data: a full dump's INSERT rows are your users' data and do not belong in a knowledge base.
| Flag | Description |
|---|---|
--under | Prefix for imported lesson paths, e.g. --under legacy. |
--no-split | Import each file as a single lesson instead of splitting a multi-section document into one lesson per section. |
--dry-run | Show what would be imported without saving. |
-y, --yes | Import all clean files without prompting; conflicting ones are listed for review. |
-m, --message | Version note (default: "imported from <file>"). |
sourcebrain import CLAUDE.md sourcebrain import docs/notes/ --under legacy sourcebrain import ~/vault/work/ --dry-run pg_dump --schema-only mydb > schema.sql && sourcebrain import schema.sql mysqldump --no-data mydb > schema.sql && sourcebrain import schema.sql sqlite3 app.db .schema > schema.sql && sourcebrain import schema.sql
sourcebrain export
sourcebrain export [claude-md|agents-md|markdown] [--under prefix] [-o file] [--stdout]
Assembles your lessons into a single Markdown rules file, the inverse of import. Two uses: your knowledge stays portable (export it back to a plain CLAUDE.md any time, no lock-in), and it bridges tools that don't speak MCP. Point Claude, Cursor, or a teammate at the generated file, and re-run sourcebrain export to refresh it after editing lessons.
The format only sets the default filename (claude-md writes CLAUDE.md, agents-md writes AGENTS.md); the content is the same. Scope to part of the tree with --under. Trashed lessons are never included.
| Flag | Description |
|---|---|
-o, --output | Write to this file (default: the format's filename, e.g. CLAUDE.md). |
--under | Only export lessons under this path prefix, e.g. --under auth. |
--stdout | Print to stdout instead of writing a file. |
sourcebrain export sourcebrain export agents-md sourcebrain export --under auth -o auth.md
sourcebrain show
sourcebrain show <path> [--json]
| Flag | Description |
|---|---|
--json | Output the lesson as JSON, for tools and editor integrations. |
sourcebrain show auth/jwt sourcebrain show db/migrations sourcebrain show auth/jwt --json
sourcebrain edit
sourcebrain edit <path> [-m message]
| Flag | Description |
|---|---|
-m, --message | Version note for the new version. |
--allow-secrets | Save even when the content looks like it contains credentials. |
sourcebrain edit auth/jwt sourcebrain edit auth/jwt -m "update token expiry"
sourcebrain ls
sourcebrain ls
sourcebrain ls
sourcebrain log
sourcebrain log <path>
sourcebrain log auth/jwt sourcebrain log db/migrations
sourcebrain search
sourcebrain search <query> [--json]
Searches lessons and prints their paths ranked by relevance, best match first. Works in both local and cloud mode. Unlike context, which bundles the full Markdown of matches for an AI prompt, search returns just the paths; pipe one into sourcebrain show to read it.
Ranking respects your plan automatically: local mode and Free workspaces use keyword ranking, while Pro and Enterprise blend in semantic ranking when the server has embeddings configured (and fall back to keyword otherwise).
On Pro and Enterprise, each result is prefixed with a normalized 0.00 to 1.00 relevance score (relative to the top match), and any result found by meaning alone (one keyword search would have missed) is tagged ~ semantic. Free and local results are unscored.
| Flag | Description |
|---|---|
--json | Output results as JSON ([{path, score, semantic}]) for tools and editor integrations. |
sourcebrain search "refresh token" # ranked lesson paths sourcebrain search auth # everything matching "auth" sourcebrain show "$(sourcebrain search jwt | head -1)"
sourcebrain context
sourcebrain context <query>
sourcebrain context "authentication" sourcebrain context "database" sourcebrain context "rate limiting" > context.md # save to file
sourcebrain links
sourcebrain links show <path> | graph [--json] | suggest <path>
Everything about the knowledge graph, in one place. Lessons link to each other with a wikilink: write another lesson's path in double brackets, e.g. [[auth/jwt]] (or [[auth/jwt|JWTs]] to show different text). links show lists every lesson that links to the given lesson, plus the links going the other way; links graph prints the whole graph (--json mirrors what the web graph view consumes); links suggest proposes wikilinks a lesson should add.
Outgoing links that point at a lesson which doesn't exist are flagged as broken. In cloud mode the same data drives the web graph view, and links show also resolves cross-workspace links ([[ws:slug/path]]) in both directions. (The old top-level backlinks and graph commands still work as deprecated aliases.)
sourcebrain links show auth/jwt sourcebrain links graph --json sourcebrain links suggest auth/jwt
sourcebrain diff
sourcebrain diff <path> [from] [to]
Shows a unified diff between two versions of a lesson, coloured like git diff in a terminal. With no version arguments it compares the previous version to the latest, i.e. exactly what the most recent edit changed.
Version labels match sourcebrain log: latest, v2, v1, or a bare number like 2. Pass one version to diff it against the latest, or two to diff any pair.
sourcebrain diff auth/jwt # previous → latest sourcebrain diff auth/jwt v1 # v1 → latest sourcebrain diff auth/jwt v1 v2 # v1 → v2
sourcebrain rm
sourcebrain rm <path> [-f]
Moves a lesson to the trash. It is a soft, recoverable delete: the lesson and its full history are kept and can be brought back with sourcebrain trash restore. You are asked to confirm first unless you pass -f. Alias: sourcebrain delete.
| Flag | Description |
|---|---|
-f, --force | Skip the confirmation prompt. |
sourcebrain rm auth/jwt sourcebrain rm auth/jwt -f
sourcebrain trash
sourcebrain trash | trash list | trash restore <path> | trash purge <path> [-f]
The lifecycle for deleted lessons. Bare sourcebrain trash (or trash list) lists what is currently in the trash, with when each lesson was deleted. trash restore brings a lesson back.
trash purge permanently deletes a trashed lesson and its entire history; this cannot be undone, so it confirms first unless you pass -f. (The old top-level sourcebrain restore and sourcebrain purge still work as deprecated aliases.)
| Flag | Description |
|---|---|
-f, --force | Skip the confirmation prompt (purge only). |
sourcebrain trash # list trashed lessons sourcebrain trash restore auth/jwt sourcebrain trash purge auth/jwt # permanent, cannot be undone
sourcebrain open
sourcebrain open [path]
Opens the active cloud workspace in the SourceBrain web app in your default browser. Pass a lesson path to jump straight to that lesson.
A cloud feature: you must be logged in with a workspace selected.
sourcebrain open # open the workspace home sourcebrain open auth/jwt # open a specific lesson
Health & maintenance
sourcebrain doctor
sourcebrain doctor [--strict] [-v] [--staged | --since <ref>]
Scans every lesson for references to code that has changed or been deleted since the lesson was last updated, then reports the likely-stale ones. Schema nodes are also checked against the repo's .sql migrations and dumps: undocumented columns, documented columns that no longer exist, and type drift. Alias: sourcebrain check.
Doctor inspects your working tree, so it must run inside a local repository (one initialized with sourcebrain init). For each lesson it resolves code references from an optional refs: frontmatter list, from inline code spans in the body, and from the lesson's own path when that path is itself a source file (e.g. a lesson named src/app.jsx is checked against that file). A ref may also include an anchor (path#Symbol for a function or type, or path:40-58 for a line range) to point at an exact location instead of a whole file. It then flags two problems:
- missing-file: a referenced file no longer exists.
- file-changed-since: a referenced file changed (by git commit time, or filesystem mtime outside git) after the lesson's last update.
- possible-secret: lesson content matches a known credential shape (API key, token, private key block). Lessons are shared knowledge; remove the value and rotate it if it was real. The same check warns at save time in
add,edit,import, and the MCP write tools.
On Pro, doctor additionally runs symbol-level code drift checks: if a lesson names a function or type that no longer exists in the referenced source file, it's flagged too. Go is parsed precisely; Python, Ruby, JavaScript/TypeScript, Rust, PHP, Swift, Kotlin, and Scala are checked by matching definition patterns (def, class, fn, …); for Java, C#, and C/C++ a symbol is flagged only when its name disappears from the file entirely, the most conservative signal.
Run outside a local repository (logged in, with a cloud workspace selected) and doctor runs the server-side checks instead, the same ones the web Health page shows: broken links — a [[wikilink]] whose target lesson doesn't exist — and overlapping lessons, pairs similar enough to duplicate or contradict each other. Broken links are checked on every plan; overlap detection needs Pro with semantic search. Links to a lesson that exists but you can't read are not reported: those work for everyone with access.
With --staged or --since <ref>, doctor switches to a change-scoped check: instead of auditing every lesson, it reports the lessons a specific change may have invalidated. It looks two ways, because the lesson that goes wrong often isn't the one anchored to the file you touched: anchored lessons whose refs point at a changed file, and related lessons whose content is about what you changed even if nothing links them to that file (keyword-ranked locally, semantic when embeddings are configured). This is the check to run in a pre-commit hook, or for an agent to run after editing code.
| Flag | Description |
|---|---|
--strict | Exit with a non-zero status when any issues are found (change-scoped mode gates on anchored lessons only). Useful in CI or a pre-commit hook. |
-v, --verbose | Print the code references resolved for each lesson, so "no findings" is debuggable. |
--staged | Change-scoped: check only the lessons affected by your staged changes (the git index). For a pre-commit hook. |
--since <ref> | Change-scoped: check only the lessons affected by everything changed since a git ref (e.g. main). |
sourcebrain doctor # audit every lesson for staleness sourcebrain doctor -v # also show which refs were resolved per lesson sourcebrain doctor --strict # non-zero exit if any issues (for CI) sourcebrain doctor --report # publish findings to the web Health page sourcebrain doctor --staged # only lessons affected by staged changes (pre-commit) sourcebrain doctor --since main # only lessons affected by changes since main
refs: frontmatter block so doctor checks exactly the files you mean instead of relying on heuristics:--- refs: - internal/auth/token.go # whole file - internal/auth/token.go#SignToken # a specific symbol - internal/auth/middleware.go:40-58 # a line range --- JWTs are signed in token.go and verified by the middleware…
sourcebrain verify
sourcebrain verify <path> [-m <note>] [--force]
The other half of sourcebrain doctor: when a lesson is flagged stale but is still accurate, sourcebrain verify clears the warning without editing the content. It shows the current staleness findings, then saves a new version with unchanged text and a “verified” note, moving the lesson's last-updated time past the code change that triggered the warning.
The attestation appears in sourcebrain log like any other version, so “someone checked this and it still holds” is recorded rather than implied. If the lesson is not still accurate, don't verify it — fix it with sourcebrain edit or trash it.
| Flag | Description |
|---|---|
-m, --message | Attestation note saved with the new version. |
--force | Save a verification even when there are no staleness findings. |
sourcebrain verify auth/jwt sourcebrain verify auth/jwt -m "re-checked after the token refactor" sourcebrain verify auth/jwt --force # refresh the timestamp with no findings
sourcebrain refs
sourcebrain refs <file> [--json]
The reverse of a lesson's reference list: given a source file, lists every lesson that references it, including any symbol or line anchors. Use it to answer "what knowledge is attached to the file I'm editing?"
It inspects your working tree, so run it inside your project, a local repository, or (in cloud mode) any git checkout with a workspace selected. It also flags any match whose file has changed or been removed since the lesson was written with a ⚠ stale marker, the same staleness signal as doctor.
--json emits machine-readable output intended for editor integrations and other tooling, including a stale flag (and stale_detail) per match.
| Flag | Description |
|---|---|
--json | Output matches as a JSON array (lesson, path, symbol, line range, raw ref). |
sourcebrain refs internal/auth/token.go sourcebrain refs ./src/app.jsx --json
sourcebrain code
sourcebrain code <lesson> [n] [--editor <cmd>] [--print]
The forward direction: opens a file a lesson references in your editor, jumping straight to the anchored symbol or line range. show lists a lesson's referenced files with an index; pass that index to pick one (with a single reference the index is optional).
The editor is chosen from --editor, then $SOURCEBRAIN_EDITOR, then code (VS Code) if it's on your PATH, then $VISUAL /$EDITOR. Symbol anchors are located by a best-effort search when the file has no line anchor. Like refs, it runs inside a local repository.
| Flag | Description |
|---|---|
--editor <cmd> | Editor command to open the file with (overrides $SOURCEBRAIN_EDITOR/$EDITOR). |
--print | Print the resolved absolute path:line instead of launching an editor. |
sourcebrain show auth/jwt # list the referenced files sourcebrain code auth/jwt # open the only referenced file sourcebrain code auth/jwt 2 # open the 2nd referenced file
Authentication
sourcebrain signup
sourcebrain signup
sourcebrain signup
sourcebrain login
sourcebrain login [--github | --google]
| Flag | Description |
|---|---|
--github | Sign in with GitHub (SSO) via the browser. |
--google | Sign in with Google (SSO) via the browser. |
sourcebrain login # email + password sourcebrain login --github # browser SSO sourcebrain login --google
sourcebrain logout
sourcebrain logout
sourcebrain logout
sourcebrain account
sourcebrain account name | nickname | password | verify-email | delete
Manage the logged-in account. name and nickname set the optional identity teammates see (each prints the current value with no argument, and clears it with --clear). password changes your password (prompts for the current one, then the new one twice; all hidden).
verify-email re-sends the address-verification link when sourcebrain whoami reports your email as unverified. The link always goes to the account's own address, and the server rate limits it to a few sends per ten minutes.
delete permanently deletes your account, your personal My Lessons space, and any workspaces you own that have no other members. You confirm by typing DELETE and your password. Team workspaces you own that still have other members must be handed off or deleted first. This cannot be undone; on success your saved credentials are cleared.
sourcebrain account nickname "Ada" sourcebrain account password sourcebrain account verify-email sourcebrain account delete
Workspace commands
sourcebrain workspace create
sourcebrain workspace create <name>
sourcebrain workspace create my-team sourcebrain workspace create backend-docs
sourcebrain workspace list
sourcebrain workspace list
sourcebrain workspace ls.sourcebrain workspace list sourcebrain workspace ls
sourcebrain workspace attach / detach / visibility
sourcebrain workspace attach <org> [workspace] | detach <org> [workspace] | visibility <org> <org|private> [workspace]
Manage a workspace's organization membership (see Organizations). attach puts a workspace you own into an org you belong to, and org members then see it automatically. detach takes it back out (workspace owner or org admin); people invited directly keep their access.
visibility flips an attached workspace between org (every org member gets access) and private (grouped under the org, but access stays invite-only). The workspace argument defaults to the active workspace.
sourcebrain workspace attach acme # attach the active workspace to org acme sourcebrain workspace attach acme backend # attach a specific workspace sourcebrain workspace visibility acme private sourcebrain workspace detach acme backend
sourcebrain workspace use
sourcebrain workspace use <name>
sourcebrain workspace use my-team sourcebrain workspace use backend-docs
sourcebrain workspace delete
sourcebrain workspace delete <name>
sourcebrain workspace delete my-team
Organizations
sourcebrain org
sourcebrain org list | create <name> | show <org> | invite <org> <email> | pending <org> | revoke <org> <email> | role <org> <email> <admin|member> | remove <org> <email> | leave <org> | delete <org>
Manage organizations. create makes you the owner (Pro); show prints the org's workspaces, members, and outstanding invites. invite adds an existing account immediately, or sends a signup invite to an email without one, and they join the org automatically when they register (pending lists those, revoke cancels one).
delete removes the org itself; its workspaces are not deleted, they just leave the org and keep their direct members. Attach and detach workspaces with sourcebrain workspace attach/detach.
sourcebrain org create "Acme Engineering" sourcebrain org invite acme-engineering sam@acme.com sourcebrain org show acme-engineering sourcebrain org role acme-engineering sam@acme.com admin
[[ws:Platform/errors]] points at the errors lesson in your Platform workspace. Write the workspace's name and it is saved as that workspace's slug, so the link keeps working if the workspace is later renamed. sourcebrain show ws:Platform/errors reads it directly (permission-checked), taking the name or the slug, and sourcebrain links show lists a lesson's cross-workspace links in both directions. A name that matches two workspaces you can reach is reported as an error rather than guessed at.Personal lessons & sharing
-p / --personal to any lesson command to target it (e.g. sourcebrain add -p notes/idea, sourcebrain ls -p). Free saves up to 3 personal lessons in the cloud; Pro is unlimited.Team & moderation
sourcebrain members
sourcebrain members [invite <email> | role <email> <admin|member|viewer> | remove <email> | pending | revoke <email>]
sourcebrain members sourcebrain members invite teammate@acme.com sourcebrain members role teammate@acme.com admin sourcebrain members role stakeholder@acme.com viewer # read-only access sourcebrain members remove teammate@acme.com sourcebrain members pending sourcebrain members revoke teammate@acme.com
sourcebrain requests
sourcebrain requests [approve <id> | reject <id> | enable | disable]
Lists pending change requests. When a workspace’s approval workflow (a beta feature) is on, a non-admin member’s lesson add/edit becomes a request an admin approves (applies it) or rejects. Admins see all pending requests; members see their own.
enable / disable turn the workflow on or off for the active workspace (admin only).
sourcebrain requests sourcebrain requests approve 12 sourcebrain requests reject 12 sourcebrain requests enable
sourcebrain watch / unwatch / watching / inbox
sourcebrain watch <path> | unwatch <path> | watching | inbox [--all] [--read]
A pull-based way to follow activity on the lessons, plans, and schemas you care about, with no notifications. watch subscribes to a node; unwatch stops. watching lists everything you follow with an unread count each.
inbox shows unread updates on the nodes you watch, newest first (changes by other people and plan status moves). You are never notified about your own edits. Add --all for recent activity regardless of read state, and --read to mark everything read after showing it.
A cloud/team feature: you must be logged in with a workspace selected.
| Flag | Description |
|---|---|
--all | inbox: show recent activity, not just unread items. |
--read | inbox: mark everything read after showing it. |
sourcebrain watch billing/subscriptions sourcebrain watching sourcebrain inbox sourcebrain inbox --read # mark everything read sourcebrain unwatch billing/subscriptions
Teams & plans
draft → proposed → accepted → in_progress → done, plus archived) that starts private to you and publishes when you propose it.sourcebrain teams
sourcebrain teams [create <name> | members <team> | add <team> <email> | remove <team> <email>]
sourcebrain teams sourcebrain teams create payments sourcebrain teams add payments sam@acme.com sourcebrain teams members payments
sourcebrain plan
sourcebrain plan create <path> [--team <slug>] [-c content] | plan status <path> <status>
Create a plan (opens your editor without -c). It starts as a draft visible only to you; publish it to its team or workspace by moving it to proposed.
plan status advances it through the lifecycle. Only valid transitions are allowed; archive is reachable from any state.
| Flag | Description |
|---|---|
--team <slug> | Create the plan inside this team (create only). |
-c, --content | Plan content as a string (skips the editor). |
-m, --message | Version note (create only). |
sourcebrain plan create design/refund-flow --team payments sourcebrain plan status design/refund-flow proposed sourcebrain plan status design/refund-flow in_progress
sourcebrain schema
sourcebrain schema create <path> [--team <slug>] [-c content] [-m message] | schema diagram [--fenced]
Creates a schema: a typed kind of lesson that documents a table or collection, each column's type, keys, allowed values, and the gotchas a plain DDL dump never captures. It renders as a structured view in the web app and is served to AI tools as structured JSON (get_lesson format="schema").
Without -c, schema create opens your editor prefilled with a starter template showing the fenced sourcebrain-schema block format; the content must contain a valid block. Creating is a cloud/team feature.
schema diagram renders every schema as a Mermaid ER diagram: one entity per table with keys and gotchas as attribute comments, and a relationship edge for each fk: reference. A referenced table with no schema node renders as an empty entity, an undocumented gap made visible. The output pastes into anything that renders Mermaid (GitHub, GitLab, Obsidian). Works in local and cloud mode.
| Flag | Description |
|---|---|
-c, --content | Schema content as a string (skips the editor). |
-m, --message | Version note. |
--team <slug> | Create the schema inside this team. |
--fenced | diagram: wrap the output in a ```mermaid code fence for pasting into Markdown. |
sourcebrain schema create billing/subscriptions sourcebrain schema create billing/subscriptions --team payments sourcebrain schema diagram --fenced # paste into a README or PR sourcebrain schema diagram > docs/data-model.mmd
sourcebrain comments
sourcebrain comments <lesson> | comments add <lesson> <text> | comments enable|disable|status
Read or add comments on a lesson or plan. Discussion is a beta feature an admin enables per workspace; you can comment on anything you can see. Comments are flat, plain-text, and pull-based (no notifications). enable / disable turn discussion on or off for the active workspace (admin only), and status shows whether it's on, the CLI counterpart to Settings → Discussion.
sourcebrain comments design/refund-flow sourcebrain comments add design/refund-flow "should we cap retries at 3?" sourcebrain comments enable sourcebrain comments status
Sync commands
.sourcebrain/ database and an active cloud workspace. Run them from a directory that contains or is inside a .sourcebrain/folder.sourcebrain push
sourcebrain push
Uploads lessons from the local database to the cloud workspace. For each lesson:
- If only local: upload it.
- If same hash: skip (already in sync).
- If both sides changed: show a diff and prompt to resolve.
Reports a summary: X pushed, Y skipped, Z unresolved.
sourcebrain push
sourcebrain pull
sourcebrain pull
Downloads lessons from the cloud workspace to the local database. Mirror of push:
- If only cloud: download it.
- If same hash: skip.
- If both sides changed: show a diff and prompt to resolve.
sourcebrain pull
sourcebrain sync
sourcebrain sync
Runs pull then push in one step, the full round trip. It pulls first, so you integrate the cloud's version before uploading yours, then pushes your local changes back up.
Both halves prompt on conflicts with a diff, exactly like running the two commands separately. Like push and pull, it needs both a local .sourcebrain/ repository and an active cloud workspace.
sourcebrain sync # pull, then push
Conflict resolution prompt
When a conflict is detected during push or pull, SourceBrain displays a unified diff and waits for your input:
Conflict: auth/jwt --- local +++ cloud @@ -1 +1 @@ -JWTs expire after 30 days. +JWTs expire after 7 days (tightened in v2.4). [k] keep local [c] cloud wins [e] edit manually [s] skip
| Key | Action |
|---|---|
k | Keep the local version: uploads local content to cloud |
c | Cloud wins: writes cloud content to local database |
e | Edit manually: opens your editor with both versions for manual merge |
s | Skip: leave both sides unchanged, come back later |
AI integration
sourcebrain ask
sourcebrain ask <question> [--json]
Asks a natural-language question and prints an answer synthesized from the lessons in your active workspace, followed by a list of the lessons it drew on. You can quote the question or type it as bare words.
The server retrieves only the lessons most relevant to your question (not the whole knowledge base) and asks the configured AI model to answer from them, so the answer stays grounded in your team's knowledge and cites its sources. When the workspace belongs to an organization with a shared context, those cross-repo lessons are considered too.
A Pro, cloud feature: you must be logged in with a workspace selected, and it is metered per workspace. Pass --json for a machine-readable { answer, sources } object. See Answering questions in the AI guide.
| Flag | Description |
|---|---|
--json | Output the answer and its sources as JSON, for tools and editor integrations. |
sourcebrain ask "how does authentication work?" sourcebrain ask why do we cache the workspace plan sourcebrain ask "what is the deploy process" --json
sourcebrain mcp
sourcebrain mcp
Starts a Model Context Protocol (MCP) server over stdio so AI tools like Claude Desktop and Cursor can read and write your knowledge base directly. The server targets whichever backend is active (local .sourcebrain/ or your selected cloud workspace) and exposes a full set of tools to read and search (get_workspace_info, search_lessons, get_lesson…), write (add_lesson, plans, change requests), navigate (get_graph, lessons_for_file), and check staleness (check_lessons).
You normally don't run this by hand; your AI tool launches it for you via its MCP config. See the AI Integration guide for setup.
sourcebrain mcp # usually invoked by your AI client, not run directly
sourcebrain integrate
sourcebrain integrate <target> [--shared] [--remove] [--print]
Installs SourceBrain's hooks into an AI coding tool so lessons reach the agent automatically, instead of depending on it remembering to call a tool. Where sourcebrain mcp makes lessons available, this makes them arrive. Currently supported target: claude-code.
The hooks shell out to sourcebrain hook, so the binary must be on PATH. On a machine with no knowledge base configured they are inert — silent, exit 0 — so committing the shared config can't break a teammate's setup. Removal only touches SourceBrain's own entries.
| Flag | Description |
|---|---|
--shared | Install into .claude/settings.json (committed, whole team) instead of settings.local.json. |
--remove | Uninstall, leaving every other tool's hooks untouched. |
--print | Preview the config that would be merged, without writing anything. |
sourcebrain integrate claude-code # personal, settings.local.json sourcebrain integrate claude-code --shared # committed, whole team sourcebrain integrate claude-code --print # preview without writing sourcebrain integrate claude-code --remove # uninstall
sourcebrain suggest
sourcebrain suggest <file> [--lines a-b] [--json]
Drafts a lesson describing a file (or a range of lines) using AI, so you don't start from a blank page. The draft is a starting point; review and edit it, then save it yourself with sourcebrain add. Nothing is saved automatically.
This is a Pro, cloud feature: you must be logged in, and the selected code is sent to the server, which calls the configured AI model. It's metered per workspace. See Lesson suggestion in the AI guide for the server requirements and limits.
| Flag | Description |
|---|---|
--lines | Restrict to a line range, e.g. 40-58 (or a single line, 42). Defaults to the whole file. |
--json | Output the suggestion as JSON ({path, content}), for editor integrations. |
sourcebrain suggest internal/auth/token.go sourcebrain suggest internal/auth/token.go --lines 40-58 sourcebrain suggest src/app.jsx --json
sourcebrain scan
sourcebrain scan
Bootstraps a workspace by drafting lessons for files you choose, so you don't start from an empty knowledge base. The CLI sends a list of your source files (paths and sizes only) and prints a link; open it to pick which files to scan and watch a budget bar. The CLI then uploads just those files' contents, the server drafts lessons, and you review and accept them in the browser. Nothing is saved automatically.
A Pro, cloud feature. You must be logged in, and it runs from inside a local repository. The first run asks you to opt in (your code is sent to the AI provider for the files you select). See Codebase scan in the AI guide for budgets and requirements.
sourcebrain scan # lists source files, opens a picker in the browser
sourcebrain usage
sourcebrain usage [--json]
Reports how close the active workspace is to its plan limits, feature by feature: lessons, members, and workspaces, plus the monthly AI budgets (lesson suggestions, answers, and codebase-scan tokens). Each limited feature shows a utilization bar and percentage; unlimited ones are labelled as such, and features not in your plan are flagged so you know what an upgrade unlocks. Alias: sourcebrain limits.
A cloud feature: you must be logged in with a workspace selected. Limits come from the workspace owner's plan, and the monthly budgets reset at the start of each calendar month. This is the CLI counterpart to the usage panel on the web Settings page.
| Flag | Description |
|---|---|
--json | Emit the utilization snapshot as JSON for scripts and dashboards. |
sourcebrain usage # utilization for the active workspace sourcebrain usage --json # machine-readable output
sourcebrain ai-instructions
sourcebrain ai-instructions | ai-instructions set [text]
Shows or sets the organization AI instructions for the active cloud workspace: the guidance returned at the top of get_workspace_info that steers every agent which connects. This is the CLI counterpart to the web AI Settings page. Alias: sourcebrain ai.
Run with no arguments to print the current instructions. set replaces them: pass the text as an argument, or run set with no argument to edit them in your $EDITOR. Pass an empty string ("") to clear them and fall back to the built-in default. A cloud feature.
sourcebrain ai-instructions # show current sourcebrain ai-instructions set "Always check auth/ first" # set inline sourcebrain ai-instructions set # edit in $EDITOR
sourcebrain ignore
sourcebrain ignore list [--json] | ignore check <path> [--json]
Inspects what a .sourcebrainignore file at the project root excludes, most importantly from the codebase scanner, which sends file contents to the AI provider. The file uses .gitignore syntax and is meant to be committed, so the whole team shares one policy and changes go through review. These commands are read-only views that resolve the patterns against your real working tree; to change what is excluded, edit .sourcebrainignore.
ignore list lists every excluded file with the pattern that matched it (useful for catching a typo'd pattern that silently matches nothing). ignore check <path> reports whether one file is excluded and by which pattern, exiting 0 when ignored and 1 when not, mirroring git check-ignore. Runs inside a local checkout.
| Flag | Description |
|---|---|
--json | Output the result as JSON, for tools. |
sourcebrain ignore list sourcebrain ignore check internal/security/keys.go sourcebrain ignore check .env --json
Configuration
Global config is stored in ~/.sourcebrain/config.json. You can inspect it directly, let the CLI manage it via the login/workspace commands, or use the sourcebrain config command.
| Field | Default | Description |
|---|---|---|
api_url | https://cloud.sourcebrain.io | Base URL for the SourceBrain server |
token | (empty) | JWT auth token saved after login |
workspace | (empty) | Active cloud workspace name |
sourcebrain config
sourcebrain config
sourcebrain config
sourcebrain config set-url
sourcebrain config set-url <url>
sourcebrain config set-url http://localhost:8080