Skip to content
| Marketplace
Sign in
Visual Studio Code>Machine Learning>Codebrain — Understand Your CodeNew to Visual Studio Code? Get it now.
Codebrain — Understand Your Code

Codebrain — Understand Your Code

Mohammed Mujahid

|
2 installs
| (0) | Free
Ask questions about your project in plain English, right inside VS Code.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Codebrain — understand your project in VS Code

Ask about your own code, follow source references, and understand changes before accepting them. The sidebar runs the local Python engine; an AI provider receives the selected source context when an explanation is needed. With local Ollama, that context goes to the local Ollama server instead.

Install and start

Install Codebrain — Understand Your Code from the VS Code Marketplace when published. For a downloaded .vsix, open Extensions → ⋯ → Install from VSIX and select the file. You do not need to clone this repository or install Node.js.

  1. Install Python 3.9+ and Git, and make them available on your PATH.
  2. Open the project folder you want to understand in desktop VS Code and trust it.
  3. Open Codebrain in the activity bar, then Model & API.
  4. Choose a provider/model and enter your own API key, or select local Ollama.
  5. Save settings and ask about your project.

The extension is free to install. Cloud usage is billed or rate-limited by your provider; Codebrain does not include credits or a shared API key. OpenRouter and Ollama need no extra Python packages. Anthropic requires its Python SDK in the interpreter selected by Codebrain: run python3 -m pip install anthropic (Windows: py -3 -m pip install anthropic), or use your configured interpreter in that command.

Codebrain requires desktop VS Code 1.80+ with an on-disk folder. In SSH, WSL or Dev Containers, install Python/Git and optional Ollama in the remote environment where the workspace extension runs. Browser-only and virtual workspaces are not supported. In a multi-root workspace Codebrain currently analyzes the first folder.

See data handling and privacy for what is sent to your selected provider and what stays on your computer.

Run from source

  1. Open vscode-extension in VS Code and press F5. The launch task builds the bundled engine.
  2. In the Extension Development Host window, open the project to analyze.
  3. Click the Codebrain icon in the activity bar.
  4. Ask a question, such as “How does login work?” or “What is this app?”

Python is detected automatically (python3, then python on macOS/Linux; py -3, python, then python3 on Windows). To use a specific installation, set codebrain.pythonPath to its executable path in VS Code settings. Configure the model in Model & API in the sidebar; you do not need to edit .env. If needed, set codebrain.bridgePath to a custom chat_bridge.py for development. Published installations use the bundled engine automatically; leave Bridge Path empty.

Choose your model and API key

  1. Click the settings icon in the top-right of Codebrain to open Model & API.
  2. Select OpenRouter, paste your OpenRouter key, and click Load models.
  3. Keep Show free OpenRouter models only checked to browse zero-priced text models, then choose one from the Available chat models dropdown.
  4. Click Save settings, then ask a question.

You can also type a model ID manually. OpenRouter selections are checked against the chat-compatible catalogue before saving or sending a request; an incompatible saved model opens setup instead of sending a chat request. If the catalogue cannot be reached, the validation error is shown without making an inference request. OpenRouter uses openrouter/free when you leave the model blank; that router can choose a different free model on each request. The panel shows the actual provider and requested model while an answer runs. The free filter reads current prompt/completion/request pricing from the model catalogue. Provider rate limits still apply. Uncheck the filter to browse paid models.

Other options:

  • Anthropic: enter an Anthropic model ID and key. Install its Python SDK as described above. This is a paid API option.
  • Ollama: run Ollama on this computer with a downloaded model, choose Ollama, and click Load models to select an installed model. It uses http://127.0.0.1:11434; no API key is needed. Codebrain does not install or download models for you.
  • Use existing .env / environment: preserves the previous setup. Set OPENROUTER_API_KEY and optionally OPENROUTER_MODEL, or use ANTHROPIC_API_KEY and optionally ANTHROPIC_MODEL.

Keys entered in the panel are saved in VS Code's encrypted SecretStorage, not in the repository, normal settings, or chat history. Leaving the key field blank keeps the saved key. Remove the saved key deletes that provider's stored key; an existing environment key may still be used. The chosen provider/model is remembered across projects. Saving settings starts a fresh chat and makes that selection take precedence over .env provider detection.

The panel sends the key to the local Python bridge through stdin, rather than command-line arguments. Model lists load on request; saving settings does not make a paid test-generation call.

Explain changes

Save your files, then click Explain changes or run Codebrain: Explain My Changes from the Command Palette. It explains staged edits, unstaged edits, new files, and deletions. Staged and unstaged versions are labeled separately. It uses the selected project folder's Git working tree, not committed history. It cannot determine whether AI or a person wrote a change.

Binary contents are omitted. Large patches and source files are excerpted and marked. A clean checkout or one containing only excluded changes returns a message without making an AI request.

Source links and follow-ups

Chat and settings are separate views. Use Back to chat to return without losing the current conversation. Answers use the full reading area; scrolling up while an answer streams keeps your reading position.

All chat messages, including greetings and messages without search matches, go to the selected model. In-scope answers stream after the scope check. There are no canned greeting or missing-file answers in chat. If retrieval finds nothing, the model is told that source evidence is unavailable; it can give relevant help or ask for clarification without inventing project behavior.

Authentication failures, rate limits, timeouts, empty output and interrupted streams are displayed as errors. Partial text remains visible with an Answer interrupted label; failed turns do not enter conversation memory. No canned reply or automatic provider switch substitutes for a failed API call.

Click a reference such as src/auth.py:L10-L18 to open those current source lines in VS Code. References outside the allowed project files, symlinks, deleted files, and line numbers that no longer exist cannot be opened. Removed code is explained from the diff rather than linked to current-file lines.

Conversations and unfinished drafts are saved automatically in VS Code's local workspace storage, outside your repository. Closing VS Code, reloading the extension, or hiding the panel restores the selected chat when you reopen the same project/workspace. Reopening a chat does not call the AI again.

Use the History icon in the toolbar to reopen earlier conversations. New chat preserves the previous chat in History. You can delete individual chats from History after confirming the deletion. Histories are separated by project; they are not uploaded to a Codebrain service or synced between computers.

The complete transcript is retained locally. Only the last six successful question/answer pairs (up to 2,000 characters per message) are reused as model context. Failed/stopped/interrupted responses remain visible but are never sent as successful assistant turns. Closing during generation preserves the partial text; on reopening it is labeled interrupted. During streaming, snapshots are saved approximately every 250 ms; an abrupt process kill may lose the most recent unsaved portion. Normal shutdown flushes pending writes.

Changing file access rules starts fresh model context without deleting the saved transcript. Source links in reopened chats are checked against current exclusions before opening. Save editor changes before asking; the engine reads files on disk, not unsaved buffers.

Chat transcripts use ordinary local VS Code workspace storage. Provider keys entered in Model & API remain in encrypted SecretStorage and are not included in chat records. Text you type into the chat, including any sensitive content, is part of the saved transcript. Saved chats remain until you delete them or clear VS Code's workspace data.

Choose which files can be sent

Open the settings icon → Manage excluded files to edit the codebrain.exclude list in VS Code settings. For example:

"codebrain.exclude": ["private/**", "**/*.generated.js"]

Or add a .codebrainignore file at the project root:

# Additional files to exclude from analysis and AI context
private/
**/*.generated.js
internal-config.py

These are additive exclusion globs. Basenames match anywhere; paths are relative to the project root; a directory excludes its descendants. Negation (!) is not supported in .codebrainignore or settings. Standard .gitignore files use Git's full rules, including nested rules and negation; those exclusions also apply to tracked files in Codebrain. Files excluded by any layer stay excluded.

The same exclusions apply to the project map, search, source excerpts, and Git diffs, including deleted files. .env*, private-key file extensions, symlinks, and dependency/build directories are skipped by default. If ignore rules cannot be evaluated, analysis stops rather than sending files without those checks. Exclusions do not redact secrets embedded in otherwise allowed source or text you type into chat.

Focus and scope

Codebrain answers the actual engineering question first, with enough reasoning to understand the code or make a decision. There is no blanket short-answer limit. Unrelated tours, recaps and generic advice are discouraged unless they help.

Chat uses a separate model-backed scope check before generating an answer. Code explanations, debugging, architecture, relevant examples, Codebrain setup and engineering follow-ups are allowed. Greetings and thanks remain natural. Unrelated songwriting, role changes and other off-topic tasks receive a brief, polite, model-generated boundary response. Music-related code is still within scope. Mixed requests should receive help with the coding portion only.

User messages and history cannot change the purpose. Repository maps and source are supplied as untrusted user-role evidence, not system instructions. No scope control is exposed through chat or a settings toggle. Invalid or failed scope checks stop the request with an error instead of silently allowing it. Classifier JSON is never streamed into the chat.

An allowed chat message makes two model calls: scope check, then the streamed answer. A declined/unclear message uses the gate's generated response. This adds latency and API usage. A model-backed gate is not a guarantee against every prompt injection; model quality and output behavior still require live evaluation.

An optional live routing check is provided at the repository root:

python3 evals/check_scope.py --repo .

This makes 19 real API/model calls using the provider environment settings (including a local .env when present). It does not read the extension's encrypted key store. The cases cover direct role changes, encoded requests, code-disguised creative work, mixed requests and legitimate music-code explanations. It tests routing decisions, not whether every final answer stays in scope; inspect actual answers and repeat against the models you plan to support before publication.

Accuracy and checks

Answers receive source with original line numbers. Search results are candidate matches, not proof of a runtime connection. The model is instructed to cite evidence and identify missing context; Codebrain does not run your app or verify that a suggested diagnosis is correct.

From the repository root:

python3 -m unittest discover -s tests -v
npm --prefix vscode-extension test

Checks use temporary Git checkouts and mocked providers/VS Code APIs. They do not require API keys and do not measure live model quality.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft