How bb, the programmable IDE for coding agents, is built
By Flavio
Updated
Tagged: AI
I read the bb source to follow one coding-agent task through its server, SQLite database, host daemon, provider runtime, event stream, and app.
I’ve been trying out bb, an open source IDE built around coding agents. Its tagline is “the IDE for loop-driven development”: you hand tasks to agents, they work in separate threads, and you check in to review, steer, or pass a thread along to another agent.
What caught my attention is that bb treats its own interface as something agents can drive too. The web app, CLI, SDK, and HTTP API all talk to the same system. You can click a button to start a thread, an agent can run a CLI command to spin up another one, or a script can trigger one on a schedule. Instead of just being a window where you watch agents work, the IDE acts as the runtime coordinating all of them.
I wanted to see how it pulls that off under the hood, so I dug into the bb source and traced a single task all the way through the system.
The problem is no longer running one agent
Running a single coding agent is straightforward. You open a terminal, describe what you want, and wait for it to finish.
Things get messy once you’re running five at the same time. Suddenly you’re tracking a pile of questions in your head:
- which agent owns each task?
- which directory is each agent changing?
- which one is waiting for approval?
- which one finished?
- how does a reviewer see another agent’s work?
- who merges, cleans up, and closes the session?
The agents handle the coding part fine, while all the coordination around them still falls back on you. bb tries to take that coordination work off your plate by giving every unit of work a durable identity, an execution environment, a lifecycle, and an event history. In bb, that unit is called a thread.
Everything starts with a thread
A thread in bb stores a lot more than a chat transcript. Each one keeps track of:
- the project
- the agent provider
- the environment where work runs
- the current lifecycle state
- its parent or source thread
- an ordered stream of messages, tool calls, approvals, and file changes
Threads come in two flavors: standard threads that do work directly, and manager threads that coordinate other threads. Every child thread points directly to its parent, so delegation lives in the data model instead of getting buried inside a prompt.
That structure pays off as soon as a manager spins up five worker threads. The app can render the whole tree, the CLI can wait on a specific child, and the parent can collect results from all five when they wrap up.
The system has four runtime pieces
Here’s how the four main pieces of bb fit together:
Each part has a clear job:
- The server owns product state and policy. It exposes the HTTP API, stores everything in SQLite, and pushes live notifications over WebSocket.
- The host daemon runs on every machine that executes work. It provisions workspaces, starts provider processes, and streams their events back to the server.
- The app is the web interface.
- The CLI and SDK expose the same operations to people, agents, and scripts.
Two contract packages define the boundaries between these pieces:
@bb/server-contractdefines the API between clients and the server@bb/host-daemon-contractdefines the commands and events between the server and host daemons
Keeping those boundaries strict means the server never has to care how a provider process runs, and the daemon never makes product decisions about projects or threads.
Following one task through bb
To see how these pieces talk to each other, let’s trace one task from start to finish:
Find why the tests fail, fix the problem, and report what changed.
1. The client creates the thread
The app, CLI, and SDK all call the same server API. From the CLI, creating that thread looks like this:
bb thread spawn \
--project proj_flaviocopes \
--prompt "Find why the tests fail, fix the problem, and report what changed"
When the request arrives, the server validates the project, provider, parent thread, environment choice, visibility, and permission mode, then writes a new thread row to SQLite. The initial status is usually starting. Because bb creates the row before spawning any agent process, the thread already has an identity and can record what went wrong even if environment provisioning fails.
2. bb resolves the execution environment
Every thread needs a directory on a specific machine, which bb calls an environment. An environment can point to an existing folder, or bb can manage it for you by creating an isolated Git worktree and removing it once no active thread is using it.
Environments also enforce the host boundary. Instead of telling a machine to “run in /Users/flavio/project” and hoping that path exists everywhere, the server identifies both the host and the workspace belonging to that host.
Each environment moves through its own lifecycle:
provisioning → ready → retiring → destroying → destroyed
Provisioning can fail, destruction can fail, and a scheduled retirement gets cancelled if a new thread starts using the environment again. Tracking these as explicit transitions beats scattering Boolean flags across the codebase.
3. The server sends a command to the host daemon
Once the environment is ready, the server sends a thread.start command to the daemon connected to that host. They communicate over a WebSocket connection, with messages structured as an RPC protocol.
The command carries the thread ID, environment ID, provider, prompt, execution settings, and skills. The daemon sends back a command result separately from the stream of agent events:
- the command result tells the server whether starting the work succeeded
- thread events describe everything that happens while the work runs
Splitting those two keeps process startup errors separate from whatever the agent outputs once it’s running.
4. The daemon starts the provider runtime
Next, the daemon resolves the workspace path, retains the environment while the command runs, and hands the thread off to @bb/agent-runtime.
This package holds the adapters for Codex, Claude Code, Pi, and any agent implementing the Agent Client Protocol. Every provider talks a different language: Codex uses its app-server protocol, Claude Code has its own process and message format, ACP agents expose a shared protocol, and Pi connects through its SDK bridge.
Rather than letting those quirks leak into the rest of the app, each adapter translates provider-specific commands and responses into one shared set of thread events. That way, every screen and automation only has to understand bb’s event model instead of every provider’s protocol.
5. Provider output becomes thread events
As the provider process runs, the runtime reads its output and translates it into structured events like:
turn/started- a message item starting
- a command execution waiting for approval
- a file change completing
turn/completed- a provider error
The daemon doesn’t write to SQLite directly. Instead, it pushes events into an in-memory queue where ordinary events batch for up to 100 milliseconds, while important ones (approvals, completed items, completed turns, interruptions, and non-retrying errors) flush right away. That cuts down on tiny network writes without making the UI feel sluggish.
The source is upfront about the trade-off here: the queue retries after connection drops, so it handles temporary blips fine, but it isn’t a durable log. If the daemon crashes before queued events reach the server, those pending events are lost. For progress telemetry, that’s a reasonable compromise, even if you’d never build a payment ledger that way.
6. The server assigns the final event order
When a batch arrives from a daemon, the server verifies that every thread in the batch belongs to that daemon’s host and writes all accepted events in a single SQLite transaction.
While writing them, the server assigns a monotonically increasing sequence number to each thread’s events. Letting the server own the ordering while the daemon only supplies the content stops reconnecting or overlapping producers from fighting over positions in the timeline.
Each row in the event table stores the thread, environment, turn, provider thread, event type, item identity, data, timestamp, and server sequence. That sequence number is what lets the app ask for everything after event 47 and pick up right where it left off.
7. The app receives a notification
Right after committing the transaction, the server sends a lightweight notification to connected clients. The push just tells the app that the thread changed instead of sending the whole reconstructed thread, and the app then reads the new timeline data from the server.
That keeps SQLite as the single source of truth. If a client misses a WebSocket notification, nothing in the history is lost, because the app can reconnect and rebuild its entire view from the stored events.
Thread state is a state machine
A thread doesn’t rely on a loose collection of flags like running, failed, and stopped. Instead, it moves through a small state machine:
idle → starting → active → stopping → idle
↓
error
Transitions are driven by events like:
run.preparingrun.startedrun.succeededrun.failedstop.requestedstop.settled
In the database, bb applies those transitions using compare-and-swap writers. If a stale event shows up late, it gets recorded as a no-op instead of quietly overwriting newer state. Say a user archives or deletes a thread while the daemon is still responding: an old run.started callback won’t accidentally bring that thread back to life. Once a local app starts juggling multiple asynchronous processes, that’s the exact kind of race condition you hit right away.
Why the event log matters
Having an append-only event stream gives bb a lot more to work with than a plain chat transcript. From that stream alone, it can reconstruct:
- which turn is active
- which tool is waiting for approval
- which files changed
- whether the provider is retrying
- what a child thread reported
- what happened before a crash
It also lets different interfaces share the same view of the world. The web app renders the timeline visually, the CLI prints the latest output, plugins can react to thread.completed, and a manager agent can inspect a child’s result, all reading from the exact same history.
Manager threads are ordinary threads with more tools
There’s no separate manager service running a special kind of AI behind the scenes. A manager is just a regular thread that’s allowed to create, inspect, steer, and wait for other threads.
bb exposes its CLI to agents through a built-in skill, so a manager can kick off a worker with a command like this:
bb thread spawn \
--project proj_flaviocopes \
--parent-thread thr_manager \
--prompt "Inspect the failing API tests and report the cause"
Then it can wait for the child to finish:
bb thread wait thr_worker
And read back the result:
bb thread output thr_worker
That turns agent orchestration into normal application behavior built out of threads, parent-child links, commands, and events. A manager is still an agent, though, so it can make bad decisions, spawn overlapping tasks, or misread a worker’s output. bb gives you the primitives to coordinate threads, while you still have to keep an eye on how the manager uses them.
The same project can run on several machines
Splitting the server from the daemon also unlocks remote execution. You can enroll several machines on a single bb server and map the same project to a different path on each host, like this:
MacBook /Users/flavio/project
Mac Studio /Users/flavio/www/project
Linux server /srv/project
Because the browser is only a control surface, opening bb on your laptop doesn’t mean the work runs there. When you create a thread, you pick the target machine and the server sends the command to that host’s daemon. Filesystem access stays local to the machine holding the files.
That setup also matters for security. Any connected daemon can run commands and modify code, and the server API can spin up new work. If you bind the server directly to a public interface, you expose an unauthenticated API that can execute commands and read files. Put it behind the managed bb connection or a private network like Tailscale, and never expose the raw local server to the public internet.
The IDE can extend itself
Plugins in bb can add server behavior, CLI commands, skills, automations, and interface panels, using the exact same APIs as the built-in app.
So if you ask an agent to “add a task tracker to bb”, it doesn’t stop at a code diff. It can add the server records, the CLI surface, the sidebar panel, and the instructions that teach other agents how to use the new tool. Having those stable contracts in place means an AI-generated panel can turn into a real product feature.
Why SQLite fits this system
Using a single SQLite database as the source of truth keeps the local setup lightweight:
- no external database server to run
- transactions around event ordering
- straightforward backups
- one file holding all the durable coordination state
The server can still drive remote machines without pulling everything into that database. Code and processes stay on the remote hosts, and only the coordination state comes back to the central file.
There is a clear trade-off here. One bb server owns one coordination domain, so this isn’t a globally distributed scheduler. If the server machine disappears, remote daemons can’t keep coordinating on their own through a fallback server. For a personal setup or a small team, keeping the whole thing in one local file is much easier to maintain.
What I like about the architecture
None of the building blocks here are exotic:
- HTTP
- WebSocket
- SQLite
- child processes
- explicit state machines
- append-only events
- typed contracts
What I like is how those pieces fit together. bb treats an agent as just another operator of the app, while assuming the underlying agent process can fail at any moment. Processes disconnect, events race, commands finish late, and every provider speaks a different protocol, so the system puts explicit boundaries around each of those failure modes instead of pretending they won’t happen.
What can go wrong
bb is still young. The core architecture is stable, while the workflows and UI surfaces are still changing, so there are a few limits worth keeping in mind.
Queued daemon events aren’t durable. If a daemon crashes before its buffered progress events reach the server, those updates are lost.
The server is also a single coordination point, even though SQLite makes it easy to run. Remote execution widens the trust surface too: an enrolled host runs commands, so a compromised server can dispatch work to every connected machine.
Normalizing events doesn’t make Codex, Claude Code, Pi, and ACP agents behave the same way, either. Resume behavior, approvals, models, and tool semantics still vary across providers.
Separate environments help when you run agents in parallel, but two agents can still make incompatible architectural decisions or edit shared external systems at the same time. A manager thread won’t fix a vague brief, so you still need a good plan, clear ownership, and concrete completion criteria.
How I would use bb
If you want to try bb on real work, start with tasks that already split cleanly into independent chunks:
- inspect separate parts of a codebase
- fix unrelated test failures
- audit several pages
- review a completed implementation
- monitor CI after a change
- update independent documentation files
Keep one clear owner for shared abstractions so parallel threads don’t fight over the same core interfaces. It also pays to separate implementation from review, letting one thread write the change while another reads the diff and runs the checks.
Wait until that loop feels reliable before you automate it. Once it does, you can wire up a sequence like this:
- Create a worker for one issue.
- Wait for it to finish.
- Create a reviewer on the same project with a clean context.
- Send actionable findings back to the worker.
- Wait for CI.
- Archive the threads once the work is done.
That takes away the manual babysitting while keeping a real review step in the loop, which is the exact opposite of slop grenades.
The deeper idea
Most coding-agent tools try to make a single agent more capable, while bb focuses on the system around the agents. T3 Code takes a similar local control-plane approach to the same problem, putting one interface over several provider CLIs with threads, approvals, and diffs.
With bb, every piece of work gets an identity and its output gets an ordered history. Each run is tied to a specific host and environment, and people, agents, scripts, and plugins all share the same controls. If agents are going to be regular participants in software development, treating them like chat boxes bolted onto an editor isn’t going to cut it. They need APIs, lifecycle state, permissions, isolation, and observable work, and bb is an early take on what that looks like.
The project is MIT-licensed, local-first, and hosted in the get-bb/bb repository. If you want to spin it up locally, run this command:
npx bb-app@latest
Once it’s running, open http://localhost:38886 in your browser.
If some of the foundations behind these workflows are new to you, I have free courses on Git and the command line. I also cover parallel agents, review loops, and agent-managed workflows in the AI Workshop.
Want me to talk about your product? You can sponsor this site.
Related posts about ai: