How cline/kanban works
1. What this repo is
Kanban is a local, repo-scoped agent orchestration tool. You run it from the root of an existing git repo; it starts a Node-based runtime server and opens a browser UI. The main product boundary is between the backend runtime that manages workspaces, tasks, terminals, and git state, and the React/Vite web UI that renders the board and controls.
2. Top-level architecture
The repository is effectively split into two applications:
- src/: the local runtime, CLI entrypoint, task/worktree orchestration, agent integrations, and APIs
- web-ui/: the browser client, with board UI, detail panels, terminal controls, git views, and settings
Supporting code includes tests, release tooling, docs, and CI workflows, but the core architecture lives in those two packages.
3. Core domain model: projects, tasks, and boards
The central business object is a task card on a kanban board. Cards belong to a project/workspace, can be linked into dependency chains, and transition through states like active, reviewed, trash, or completed. Board-specific logic lives in src/core/task-board-mutations.ts, src/core/kanban-command.ts, and the matching UI state in web-ui/src/state/board-state.ts and drag-rule helpers.
4. Workspace and git isolation
A major architectural feature is that each task runs in its own git worktree. The workspace layer handles cloning, initializing, syncing, history inspection, path sandboxing, and worktree path resolution. This isolation is what lets Kanban run many agents in parallel without merge conflicts. Files like src/workspace/task-worktree.ts, git-sync.ts, git-history.ts, and path-sandbox.ts define that boundary, while the UI exposes worktree-aware views and git history panels.
5. Terminal and agent execution subsystem
Agent execution is centered around terminal sessions backed by PTYs. The backend manages terminal lifecycles, session state machines, state mirroring, output filtering, and websocket transport. Key pieces are src/terminal/pty-session.ts, session-manager.ts, session-state-machine.ts, terminal-session-service.ts, and ws-server.ts. On the UI side, persistent terminals and session geometry are managed separately so users can keep a stable terminal experience across reloads.
6. CLI agent integration layer
Kanban supports multiple external CLI agents rather than implementing its own model runtime. The src/terminal/agent-registry.ts, agent-session-adapters.ts, and commands/hook-events/* files show the adapter-based design for different agents such as Codex, Kiro, Droid, and related hook/event formats. This layer normalizes agent output, tool calls, and hook data into a common runtime shape so the board can show “latest message” or tool activity per task.
7. Cline SDK bridge
There is a dedicated integration boundary under src/cline-sdk/ for Cline-specific runtime behavior. This includes provider/runtime/session services, message storage, telemetry, slash commands, and event adapters. Architecturally, this acts as a compatibility layer between Kanban’s own task/worktree model and the Cline agent/runtime abstractions used by the product’s sidebar chat and task automation features.
8. Backend API and state distribution
The browser talks to the runtime through a typed API surface built with tRPC and websocket state streaming. The routers in src/trpc/ expose project, workspace, runtime, and hooks operations, while src/server/runtime-state-hub.ts and runtime-server.ts push live state updates to the UI. This split lets the UI query authoritative state, then subscribe to incremental updates for task progress, workspace changes, terminal state, and runtime events.
9. Security, workspace access, and shutdown
The runtime includes explicit boundaries for local access and safe lifecycle management. Passcode/auth handling gates websocket upgrade and runtime access, workspace metadata monitors track available repos, and shutdown coordination ensures terminals, sessions, and child processes are cleaned up coherently. These concerns are handled in src/security/passcode-manager.ts, src/server/shutdown-coordinator.ts, src/server/process-termination.ts, and related runtime shutdown utilities.
10. Web UI composition
The UI is a single-page React app with substantial domain-specific panels: kanban board, task detail view, diff viewer, git history, terminal panels, onboarding, runtime settings, and project navigation. Its internal data flow is built around runtime hooks (web-ui/src/runtime/* and web-ui/src/hooks/*) that consume tRPC queries, runtime streams, and local persistence. This is where the product experience is assembled, but it delegates all authoritative state changes to the backend runtime.
11. Persistence and local state
Persistent state is split between backend-managed workspace/task state and frontend-local preferences. Backend state covers task/workspace metadata, runtime session state, and terminal state mirrors; frontend state covers UI layout, resizing, onboarding, theme, and local storage. The separation is deliberate so the board can reload and reconnect without losing the underlying task execution model.
12. Telemetry, update, and release tooling
The repo includes optional product telemetry and release automation, but these are supporting concerns rather than core runtime dependencies. Sentry/PostHog/Featurebase integration lives mostly in the web UI and telemetry modules, while auto-update, CI, publish workflows, changelog extraction, and release commands are managed in scripts/, .github/workflows/, and release docs. These affect deployment and observability, not the main control flow of task execution.
13. How data flows end to end
The typical flow is: user opens a repo → CLI starts local runtime server → UI connects and loads board/workspace state → user creates or starts a task → backend creates a task-specific worktree and terminal session → agent runs through the terminal/hook adapter layer → runtime streams status, output, and diffs back to the UI → user reviews, commits, or chains the next linked task. That loop is the core architecture to capture in any diagram.
14. Important architectural boundary to diagram
The most important boundary is between the browser-facing UI and the local execution engine. Everything that mutates git, launches terminals, or talks to agents stays in the Node runtime; everything that presents the board, diffs, and controls stays in web-ui/. The worktree-per-task model sits at the center of that boundary and is the reason the system can run many autonomous tasks in parallel.
Main entry points: runtime-server.ts Runtime server · App.tsx App shell · use-runtime-state-stream.ts Runtime hooks · task-worktree.ts Workspace layer
Components 21
Node runtime
Local execution engine, git/worktree orchestration, agents, and API server.
- CLI · Starts the local runtime from a repo root.
src/cli.ts - Runtime server · Hosts the local API, browser transport, and runtime lifecycle.
src/server/runtime-server.ts - State hub · Broadcasts authoritative runtime state to the UI.
src/server/runtime-state-hub.ts - tRPC API · Project, workspace, runtime, and hooks routers.
src/trpc/app-router.ts - Workspace layer · Clone, sync, sandbox, inspect, and resolve task-specific worktrees.
src/workspace/task-worktree.ts - Board core · Defines task cards, board mutations, commands, and task state transitions.
src/core/task-board-mutations.ts - Terminal core · Manages PTY sessions, session state, output filtering, and websocket transport.
src/terminal/terminal-session-service.ts - Agent adapters · Normalizes external agent CLIs and hook events into Kanban's runtime shape.
src/terminal/agent-session-adapters.ts - Cline bridge · Dedicated SDK/runtime boundary for Cline-specific messaging, telemetry, and sessions.
src/cline-sdk/cline-session-runtime.ts - Workspace state · Backend-managed workspace metadata and runtime session state.
src/state/workspace-state.ts
Web UI
React/Vite application that renders the board and controls.
- App shell · Bootstraps the browser client and top-level providers.
web-ui/src/App.tsx - Board UI · Renders the board, cards, columns, and drag interactions.
web-ui/src/components/kanban-board.tsx - Detail panels · Shows diffs, chat, file tree, history, and agent terminal panels.
web-ui/src/components/card-detail-view.tsx - Git views · Displays commit history, refs, and diff inspection tools.
web-ui/src/components/git-history-view.tsx - Terminal UI · Keeps terminal sessions and geometry stable across reloads.
web-ui/src/terminal/persistent-terminal-manager.ts - Runtime hooks · Client-side hooks for tRPC queries, state streams, and workspace sync.
web-ui/src/runtime/use-runtime-state-stream.ts - Board state · Client-side board model and drag rules for task movement.
web-ui/src/state/board-state.ts - Local persistence · Stores UI preferences, layout, and workspace-local browser state.
web-ui/src/storage/local-storage-store.ts
Supporting code
Security, telemetry, update, and release-related subsystems.
- Access gate · Passcode-based local access control for runtime and websocket upgrades.
src/security/passcode-manager.ts - Shutdown coordinator · Coordinates terminal, process, and server shutdown.
src/server/shutdown-coordinator.ts - Updater · Handles auto-update checks and application updates.
src/update/update.ts
Connections 28
- CLI → Runtime server: starts · Launches the local Node runtime and serves the browser app.
- Runtime server → Access gate: gates · Protects local access and websocket upgrades.
- Runtime server → State hub: publishes · Streams live runtime state to connected clients.
- Runtime server → tRPC API: serves · Exposes typed queries and mutations to the UI.
- Runtime server → Workspace layer: orchestrates · Coordinates task worktrees, sync, and repo inspection.
- Runtime server → Terminal core: runs · Manages PTY-backed task sessions and websocket transport.
- Runtime server → Board core: mutates · Applies board actions and task lifecycle changes.
- Runtime server → Agent adapters: adapts · Normalizes hook/event formats from external agent CLIs.
- Runtime server → Cline bridge: bridges · Connects Kanban task execution to Cline SDK abstractions.
- Runtime server → Workspace state: persists · Maintains authoritative workspace and runtime session state.
- Runtime server → Shutdown coordinator: coordinates · Cleans up terminals, sessions, and child processes.
- Runtime server → Updater: checks · Supports optional update and release flows.
- Workspace layer → Board core: feeds · Task/worktree state underpins board transitions and dependencies.
- Workspace layer → Terminal core: isolates · Creates per-task worktrees for parallel execution.
- Agent adapters → Terminal core: uses · Runs agents through terminal sessions and hook payloads.
- Cline bridge → Agent adapters: normalizes · Maps Cline runtime behavior into the common agent execution model.
- tRPC API → App shell: queries · Provides authoritative data and commands to the browser client.
- State hub → Runtime hooks: streams · Delivers incremental task, workspace, and terminal updates.
- App shell → Board UI: renders · Composes the main kanban surface.
- App shell → Detail panels: renders · Shows task-specific panels and inspectors.
- App shell → Git views: renders · Surfaces commit history and diff review views.
- App shell → Terminal UI: contains · Hosts persistent terminal panels and session controls.
- App shell → Runtime hooks: consumes · Uses hooks for tRPC, runtime streams, and workspace sync.
- Board UI → Board state: uses · Applies client-side task ordering and drag rules.
- Detail panels → Board state: reads · Follows the selected task and board context.
- Git views → Runtime hooks: loads · Fetches history and diff data from the runtime.
- Terminal UI → Local persistence: stores · Keeps geometry and session preferences across reloads.
- Runtime hooks → Local persistence: syncs · Caches UI and workspace-local browser state.