branch-ai
Reasoning canvas for AI CLIs — captures extended thinking from Claude Code, Codex, Gemini, and Droid as a navigable, forkable tree. Rewind, fork from any node, inject facts mid-thought. Local-first, ships an MCP server.
Install / Use
claude mcp add nikolas-sapa -- npx -y github:nikolas-sapa/branch-aiIf the server publishes to npm under a different name, use that package instead — check the repo README.
MCP Server
Model Context Protocol server
Quality Score
Category
AI & Machine LearningSupported Platforms
Skill content
View source on GitHubbranch-ai
The reasoning canvas for any AI CLI. Works with Claude Code, OpenAI Codex, Google Gemini, or Factory.ai Droid — captures each tool's reasoning as a navigable, forkable tree. Walk backward through the thinking, explore alternative paths from any point, or add a new fact mid-thought and watch how the conclusion changes.
See it live: Try the public demo — view real reasoning trees. To create your own and fork them, install locally below.
Why this exists. When an AI works through a hard problem, the reasoning vanishes the moment you see the answer. Branch preserves every reasoning step, lets you rewind to any point, and explore "what if I changed this assumption?" — without starting over.

What is Branch AI?
Branch is a reasoning canvas for AI CLIs that captures the extended thinking from Claude Code, OpenAI Codex, Gemini CLI, and Factory Droid as a navigable, forkable tree. Instead of watching reasoning scroll past in your terminal and vanish, Branch turns it into a tree you can rewind, fork from any step, and edit mid-thought.
Why Branch
Terminal output is a transcript — you read it once and it's gone. Branch keeps the reasoning as structure. From any node you can fork an alternative path, inject a new fact and re-reason from that point, or record why you decided what you decided and what would change the answer later. It works with four AI CLIs, runs fully local by default, and ships an MCP server so agents can externalize their own reasoning.
Branch vs. the alternatives
| | Branch | Scrolling terminal output | LLM tracing (LangSmith, Langfuse) | Chat/session loggers | |---|---|---|---|---| | Captures reasoning as a navigable tree | Yes | No (linear text) | Spans/timeline, not forkable | Messages only, not reasoning steps | | Fork from any step / explore alternatives | Yes | No | No | No | | Inject a fact mid-thought and re-reason | Yes | No | No | No | | Built for interactive CLI use (no app instrumentation) | Yes | n/a | No — for apps you build | Varies | | Local-first, no API key required | Yes | Yes | No (hosted) | Varies |
Honest scope: if you need production tracing across a deployed agent app with dashboards and eval runs, use LangSmith/Langfuse — that's what they're for. Branch is for the interactive loop: one developer, one hard question, at the CLI, wanting to see and steer the reasoning.
When to use Branch
- You're working a hard decision through Claude Code / Codex / Gemini and want to see how it got there, not just the answer.
- You want to explore "what if I changed this assumption?" without re-running the whole prompt from scratch.
- You want to record a decision — what you picked, what you rejected, and what would make you revisit it.
- You want your Claude Code agent to externalize and fork its own reasoning via MCP.
- You want to compare or merge the reasoning from two different runs or two different models.
FAQ
Does Branch need an API key? No. Branch uses your existing CLI auth (Claude Code, Codex, Gemini, or Droid). It never asks for its own API key.
Which AI CLIs does it support?
Claude Code (richest reasoning capture), OpenAI Codex CLI, Google Gemini CLI, and Factory Droid. Run branch doctor to see which are on your PATH.
Is my reasoning uploaded anywhere?
No, unless you opt in. Sessions save to ~/.branch/sessions/ on your machine. Sharing is per-session and explicit (branch share <id>).
What's the MCP server for?
branch-mcp gives Claude Code 13 tools so an agent can externalize its reasoning as a tree, fork it, inject facts, diff/merge runs, and record decisions — from inside a session.
Does it capture everything the model "thinks"? No. It captures the surfaced reasoning steps when extended thinking is on. Token-level cognition is never exposed by any API — Branch captures what the model narrates, not everything it computes.
Supported CLIs
- Claude Code — full thinking-block capture (richest reasoning)
- OpenAI Codex CLI — captures reasoning summaries from o3 / gpt-5
- Google Gemini CLI — captures Flash thinking-mode output
- Factory.ai Droid — routes across underlying models; captures thinking when the routed model supports it
Run branch doctor after install to see which are available on your PATH.
What you get
branch "prompt"— CLI that captures reasoning as a navigable tree (auto-detects which AI CLI to use, or pass--cli claude|codex|gemini)branch-mcp— MCP server so Claude Code agents can externalize their own reasoning, fork it, or add facts mid-thought- Web viewer — React Flow canvas where you click any node to explore an alternative path or add a new fact
branch decide— record what you decided, what you rejected, and what would change the answer laterbranch doctor— see which AI CLIs are installed and which one Branch will use by default
Requirements
- Node 20+
- At least one AI CLI on PATH:
- Claude Code signed in (Claude Pro, Max, or Team subscription)
- OpenAI Codex CLI (
codexbinary) - Google Gemini CLI (
geminibinary) - Factory.ai Droid (
droidbinary)
- Branch uses your existing CLI auth — no API keys required by Branch itself
Install
npm install -g branch-ai
Quickstart
# Terminal 1 — start the viewer
git clone https://github.com/nikolas-sapa/branch-ai && cd branch-ai
npm run viewer
# viewer runs on http://localhost:7432
# Terminal 2 — run the CLI
branch "Should I deploy on Friday afternoon? Think carefully through the tradeoffs"
# opens the reasoning tree in your browser automatically
CLI
branch [--cli claude|codex|gemini|droid] [--model <model>] [--local] "your prompt"
--cli— pick an AI CLI. Defaults to auto-detect (first available on PATH).--model— model name (each adapter has its own defaults; e.g.sonnetfor Claude,gpt-5for Codex,gemini-2.5-flashfor Gemini,defaultfor Droid)--local— skip auto-sharing for a single run whenBRANCH_AUTO_SHARE=1is set (auto-share is OFF by default — see Privacy section)
Run branch doctor to see which CLIs are available and which Branch will use by default.
Sessions are saved to ~/.branch/sessions/<id>.json. The viewer reads them from there.
All commands
| Command | What it does |
|---|---|
| branch "prompt" | Run a prompt and open the reasoning tree |
| branch list | Recent sessions |
| branch search <query> | Search across all sessions including decision conclusions |
| branch share <id> | Upload a session to Vercel Blob for sharing |
| branch decide <id> | Record a decision anchor for a session |
| branch decisions | List all sessions with recorded decisions |
| branch export <id> | Export as Markdown or Mermaid |
| branch diff <a> <b> | Compare two sessions |
| branch tag <id> <tag> | Tag a session |
| branch pin <id> | Pin a session to the top of the list |
| branch replay <id> [--model X] | Re-run a session's original prompt (optionally with a different model) and link the new run back to the source |
| branch merge <a> <b> | Synthesize two sessions into a third — finds agreement, divergence, and a unified answer |
| branch watch on\|off\|status | Install/remove a Claude Code Stop hook that auto-saves every CC session as a Branch tree |
| branch mcp install <client> | Add the branch-mcp server to a client's config file (claude-code, claude-desktop, cursor, codex, cline) |
| branch mcp install --all | Install branch-mcp into every supported client at once |
| branch mcp uninstall <client> | Remove branch-mcp from a client's config |
| branch mcp status | Show which clients have branch-mcp installed |
Environment variables
BRANCH_VIEWER_URL— override where the CLI prints the viewer link. Default:http://localhost:7432.BLOB_READ_WRITE_TOKEN— Vercel Blob token. Required forbranch share <id>(manual upload). By itself, this does NOT cause auto-upload — seeBRANCH_AUTO_SHARE.BRANCH_AUTO_SHARE— set to1to opt in to auto-upload of everybranch "prompt"run. Off by default. Use--localto opt out per-run when auto-share is on.
Decision anchors
After a reasoning session, record what you actually decided:
branch decide <sessionId>
# interactive prompts: conclusion, rejected alternatives, confidence, revisit trigger
# or non-interactive:
branch decide <id> --conclusion "Build modular monolith" --rejected "Microservices;Mongo migration" --confidence high --revisit-if "Team grows past 15 engineers"
Decisions show up in branch list with a [decided] marker and the conclusion line. branch decisions shows only settled questions. The viewer renders a decision card at the top of the session.
Gallery
The viewer ships a /gallery route with a hardcoded list of curated reasoning examples you can explore in the tree canvas:
http://localhost:7432/gallery
Click any card to open the full session — fork from any node, add a new fact, or compare with branch diff.
Privacy note: The gallery is NOT auto-populated. Only the sessions explicitly listed in viewer/lib/gallery.ts and bundled into viewer/public/gallery-sessions/ ship with the viewer. Your own sessions in ~/.branch/sessions/ are private to your machine unless you choose to share them.
Privacy
By default, Branch is fully local:
- Sessions save to
~/.branch/sessions/<id>.json— only on your machine - The viewer reads from your local disk
- Nothing leaves your machine unless you explicitly share
Sharing is opt-in per use:
branch share <id>— manual upload of one session to public Vercel BlobBRANCH_AUTO_SHARE=1(env var) — opt in to auto-upload every run; remove the var to stop--localflag — skip auto-share for a single run whenBRANCH_AUTO_SHARE=1is set
When you share, the entire session JSON (prompt + reasoning tree + final answer + decision) is uploaded to a publicly readable URL. Don't share sessions containing secrets, internal company data, or anything you wouldn't post on GitHub.
MCP server — use Branch from inside Claude Code
Add this to ~/.claude.json under mcpServers:
"branch": {
"type": "stdio",
"command": "branch-mcp",
"env": { "BRANCH_VIEWER_URL": "http://localhost:7432" }
}
Restart Claude Code. From inside any CC session you'll have 13 tools:
branch_think({ prompt, model? })— externalize Claude's own reasoning as a tree. Returns viewer URL.branch_fork({ sessionId, nodeId, modifier })— fork from any node in an existing session.branch_inject({ sessionId, nodeId, fact })— inject a new fact at a node and re-reason from there.branch_list_sessions({ limit? })— recent trees.branch_search({ query, limit? })— full-text search across all sessions (recall before duplicating effort).branch_decide({ sessionId, conclusion, rejected?, confidence, revisitIf })— record a decision anchor (conclusion + rejected + confidence + revisit-if).branch_diff({ sessionA, sessionB })— compare two sessions semantically (shared / changed / only-A / only-B).branch_export({ sessionId, format })— export as markdown or mermaid flowchart.branch_replay({ sessionId, model? })— re-run a session's original prompt wit
Truncated for display — read the full file on GitHub.
Related Skills
momen-cursurrules-prompt-file
40.6kCursor rules for building custom frontends with Momen.app as headless BaaS with GraphQL API, actionflows, AI agents, and Stripe integration.
semiotic-react-dataviz-cursorrules-prompt-file
40.6kCursor rules for Semiotic data visualization library with 30+ chart types, MCP server, and AI-assisted chart generation.
claude-mem
90.9kPersistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More
Understand-Anything
79.6kGraphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.
