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.

53 commands

Global flags

FlagDescription
-h, --helpPrint help for any command
--versionPrint CLI version
-p, --personalTarget 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).

FlagDescription
--localForce local mode even if you are logged in.
--cloudForce cloud mode (requires login).
--no-guidedSkip 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.

FlagDescription
--setupRun 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]

Creates a new lesson or adds a new version to an existing one. Without flags, opens your default editor ($VISUAL or $EDITOR, falls back to notepad / nano). Content that looks like it contains a credential (API keys, private key blocks, tokens) triggers a warning and a confirmation, since saved lessons flow into search, AI context, and embeddings for the whole workspace.
FlagDescription
-c, --contentLesson content as a string. Skips the editor.
-m, --messageVersion note (like a commit message). Optional.
--allow-secretsSave 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.

FlagDescription
--underPrefix for imported lesson paths, e.g. --under legacy.
--no-splitImport each file as a single lesson instead of splitting a multi-section document into one lesson per section.
--dry-runShow what would be imported without saving.
-y, --yesImport all clean files without prompting; conflicting ones are listed for review.
-m, --messageVersion 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.

FlagDescription
-o, --outputWrite to this file (default: the format's filename, e.g. CLAUDE.md).
--underOnly export lessons under this path prefix, e.g. --under auth.
--stdoutPrint 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]

Prints the current (latest) version of a lesson to stdout: the path, the last-updated timestamp, the version note (if any), and the Markdown content. A cross-workspace reference works too (cloud; permission-checked), naming the target workspace by name or slug: ws:Platform/errors. Pass --json for a machine-readable object (path, content, message, updated_at); this is what editor integrations read.
FlagDescription
--jsonOutput 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]

Opens the current content of a lesson in your editor for modification. Saves a new version on exit. Like add, warns and asks for confirmation when the content looks like it contains a credential.
FlagDescription
-m, --messageVersion note for the new version.
--allow-secretsSave 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

Lists every lesson in the current knowledge base as an indented tree, derived from the slash-separated paths, much like the output of the tree command.
sourcebrain ls

sourcebrain log

sourcebrain log <path>

Shows the full version history of a lesson, newest first. Each entry shows version number, timestamp, author (cloud), and the version note.
sourcebrain log auth/jwt
sourcebrain log db/migrations

sourcebrain context

sourcebrain context <query>

Searches all lessons for the query string and bundles matching lessons into a single Markdown document printed to stdout. Designed for pasting into AI prompts.
sourcebrain context "authentication"
sourcebrain context "database"
sourcebrain context "rate limiting" > context.md   # save to file

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.

FlagDescription
-f, --forceSkip 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.)

FlagDescription
-f, --forceSkip 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.

FlagDescription
--strictExit 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, --verbosePrint the code references resolved for each lesson, so "no findings" is debuggable.
--stagedChange-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
💡
Pin a lesson's references explicitly with a refs: frontmatter block so doctor checks exactly the files you mean instead of relying on heuristics:
auth/jwt lesson
---
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.

FlagDescription
-m, --messageAttestation note saved with the new version.
--forceSave 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.

FlagDescription
--jsonOutput 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.

FlagDescription
--editor <cmd>Editor command to open the file with (overrides $SOURCEBRAIN_EDITOR/$EDITOR).
--printPrint 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

ℹ️
These commands only apply to cloud mode. Local mode does not require authentication.

sourcebrain signup

sourcebrain signup

Create a new account. Prompts for email and password (password input is hidden). Saves the auth token to ~/.sourcebrain/config.json on success.
sourcebrain signup

sourcebrain login

sourcebrain login [--github | --google]

Log in to an existing account. By default prompts for email and password. With --github or --google, opens your browser for SSO and captures the token via a temporary local callback; the same accounts work across the CLI and web. Saves the auth token to ~/.sourcebrain/config.json.
FlagDescription
--githubSign in with GitHub (SSO) via the browser.
--googleSign in with Google (SSO) via the browser.
sourcebrain login            # email + password
sourcebrain login --github   # browser SSO
sourcebrain login --google

sourcebrain logout

sourcebrain logout

Clears the saved auth token from ~/.sourcebrain/config.json. You will need to log in again to use cloud mode.
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

ℹ️
Cloud mode only. Workspaces are shared knowledge bases accessible by multiple users.

sourcebrain workspace create

sourcebrain workspace create <name>

Creates a new cloud workspace with the given name. You become the owner. The workspace is automatically set as active.
sourcebrain workspace create my-team
sourcebrain workspace create backend-docs

sourcebrain workspace list

sourcebrain workspace list

Lists all workspaces you belong to (owned, invited, or seen through an organization). When you are in an organization, the list groups its workspaces under the org name, with everything else under "Not in an organization". Alias: 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>

Sets the named workspace as active. Subsequent commands (add, show, ls, etc.) will target this workspace.
sourcebrain workspace use my-team
sourcebrain workspace use backend-docs

sourcebrain workspace delete

sourcebrain workspace delete <name>

Permanently deletes a workspace and all its lessons. Only the workspace owner can delete. You will be prompted to type the workspace's slug (not its display name) to confirm before deletion proceeds; 'sourcebrain workspace list' shows the slug beside each name.
sourcebrain workspace delete my-team

Organizations

ℹ️
A Pro, cloud feature. An organization groups many workspaces behind a single member list: joining the org grants access to its org-visible workspaces automatically, and leaving revokes it. There is no "active org"; the active workspace stays the CLI's only cursor, and every org command takes the org slug explicitly.

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

sourcebrain org shared

sourcebrain org shared <org> [workspace] [--clear]

Designates one org-visible workspace as the organization's shared context: the cross-repo conventions space that search, ask, the context bundle, and MCP retrieval include alongside every member workspace's own lessons. Shared hits appear with a ws:slug/path prefix and rank slightly below same-workspace matches, so repo-specific knowledge wins ties.

Org-admin only. Run with --clear (or without a workspace) to remove the designation.

FlagDescription
--clearRemove the shared-context designation.
sourcebrain org shared acme-engineering platform
sourcebrain org shared acme-engineering --clear
💡
Lessons can link across workspaces with a qualified wikilink: [[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

ℹ️
Your personal My Lessons space is private to you. Add -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.

sourcebrain share

sourcebrain share <lesson> [--with <email>] [--can-edit] [--remove <email>] [--publish <workspace>]

Share one of your personal lessons with specific people, or publish a copy to a whole team workspace. With no flags, it lists who the lesson is shared with.

Recipients must have a SourceBrain account and see the lesson via sourcebrain shared. --can-edit grants edit access (default is read-only). Sharing acts on your cloud personal space (Pro).

FlagDescription
--with <email>Share with this person (repeatable).
--can-editGrant edit access to --with recipients (default read-only).
--remove <email>Revoke a person’s access (repeatable).
--publish <workspace>Publish a copy of the lesson into a team workspace (slug).
-m, --messageVersion note for --publish.
sourcebrain share auth/jwt --with sam@acme.com
sourcebrain share auth/jwt --with sam@acme.com --can-edit
sourcebrain share auth/jwt --publish my-team -m "promoted from my notes"
sourcebrain share auth/jwt                    # list current shares

sourcebrain shared

sourcebrain shared [show <path> | edit <path>]

Lists the lessons other people have shared with you, with the owner and whether you can edit.

show <path> prints a shared lesson; edit <path> opens it in your editor and saves a new version, available only when the owner granted you edit access. Add -m to edit for a version note.

sourcebrain shared
sourcebrain shared show auth/jwt
sourcebrain shared edit auth/jwt -m "fixed the TTL note"

Team & moderation

ℹ️
Roles: admin (the owner, plus anyone promoted, who can manage members, invite, edit AI instructions, and moderate), member (read and write lessons), and viewer (read-only — can read every lesson and take part in discussion, but cannot add, edit, delete, or import). The owner is always an admin.

sourcebrain members

sourcebrain members [invite <email> | role <email> <admin|member|viewer> | remove <email> | pending | revoke <email>]

Lists the active workspace’s members and their roles. Subcommands (admin only) invite a user, change a member’s role, or remove a member. Roles are admin, member, and viewer — a viewer has read-only access and can comment but not change lessons. Inviting an email with no account yet records a signup invite; pending lists those outstanding invites and revoke cancels one before it’s accepted.
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.

FlagDescription
--allinbox: show recent activity, not just unread items.
--readinbox: 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

ℹ️
Cloud/team feature. A project is a sub-scope of a workspace with its own members; its lessons and plans are visible only to those members. A plan is a status-tracked lesson (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>]

Lists the active workspace's teams (formerly projects, a name that still works as an alias). Subcommands create a team (you become its first member) and manage its membership.
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.

FlagDescription
--team <slug>Create the plan inside this team (create only).
-c, --contentPlan content as a string (skips the editor).
-m, --messageVersion 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.

FlagDescription
-c, --contentSchema content as a string (skips the editor).
-m, --messageVersion note.
--team <slug>Create the schema inside this team.
--fenceddiagram: 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

ℹ️
These commands require both a local .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
KeyAction
kKeep the local version: uploads local content to cloud
cCloud wins: writes cloud content to local database
eEdit manually: opens your editor with both versions for manual merge
sSkip: 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.

FlagDescription
--jsonOutput 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.

FlagDescription
--sharedInstall into .claude/settings.json (committed, whole team) instead of settings.local.json.
--removeUninstall, leaving every other tool's hooks untouched.
--printPreview 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.

FlagDescription
--linesRestrict to a line range, e.g. 40-58 (or a single line, 42). Defaults to the whole file.
--jsonOutput 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.

FlagDescription
--jsonEmit 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.

FlagDescription
--jsonOutput 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.

FieldDefaultDescription
api_urlhttps://cloud.sourcebrain.ioBase URL for the SourceBrain server
token(empty)JWT auth token saved after login
workspace(empty)Active cloud workspace name

sourcebrain config

sourcebrain config

Prints the effective configuration: the server URL (and whether it comes from the file or the environment), your login status, and the active workspace.
sourcebrain config

sourcebrain config set-url

sourcebrain config set-url <url>

Change which SourceBrain server the CLI talks to. The default hosted service is right for almost everyone; you would only change it to point at a local dev server.
sourcebrain config set-url http://localhost:8080
SourceBrain Docs · SourceBrain