`sunbeam code` is a terminal-based coding agent powered by Sol. It connects to Sol's gRPC `CodeAgent` service and provides an interactive TUI for writing code, asking questions, and executing tools — with Sol handling the AI reasoning and the CLI handling local file operations.
## Quick Start
```bash
sunbeam code # start a session (auto-detects project)
sunbeam code start --model devstral-small # override the model
sunbeam code start --endpoint http://sol:50051 # custom Sol endpoint
sunbeam code demo # demo the TUI without Sol
```
## How It Works
```mermaid
sequenceDiagram
participant User
participant TUI as sunbeam code TUI
participant Agent as Background Agent
participant Sol as Sol gRPC
User->>TUI: sunbeam code
TUI->>TUI: Discover project context
TUI->>Agent: Spawn background tasks
Agent->>Sol: StartSession (project, capabilities)
Agent->>Sol: IndexSymbols (tree-sitter symbols)
Sol-->>Agent: SessionReady (session_id, model)
Agent-->>TUI: Connected
User->>TUI: Type message, press Enter
TUI->>Agent: Chat request
Agent->>Sol: UserInput (text)
loop Tool calls
Sol-->>Agent: ToolCall (is_local=true)
Agent->>Agent: Check permissions
alt needs approval
Agent-->>TUI: Show approval prompt
User->>TUI: yes / always / no
TUI->>Agent: Decision
end
Agent->>Agent: Execute tool locally
Agent->>Sol: ToolResult
end
Sol-->>Agent: TextDone (response + tokens)
Agent-->>TUI: Display response
```
## Project Discovery
On startup, the CLI discovers project context from the current working directory:
- **Project name** — directory basename
- **Custom instructions** — `.sunbeam/prompt.md` (injected into Sol's system prompt)
All of this is sent to Sol in the `StartSession` message so it has full project context.
## Symbol Indexing
After connecting, the CLI extracts code symbols from the project using tree-sitter and sends them to Sol via `IndexSymbols`. Sol indexes these in OpenSearch for code search during the session.
LSP tools: `lsp_definition`, `lsp_references`, `lsp_hover`, `lsp_diagnostics`, `lsp_symbols`. These are advertised as client capabilities in `StartSession` — Sol only registers tools for LSP servers the client can actually spawn.
### Server-Side Tools
Sol can also call its own server-side tools during coding sessions: `search_code`, `search_archive`, `search_web`, `research`, and others. These execute on Sol's side — no local action needed.
## Tool Permissions
Configure in `.sunbeam/config.toml`:
```toml
[model]
name = "devstral-2" # override default model
[tools]
file_read = "always" # always, ask, never
file_write = "ask"
bash = "never" # block shell commands entirely
search_replace = "ask"
grep = "always"
list_directory = "always"
```
Permissions:
- **`always`** — execute immediately, no prompt
- **`ask`** — show approval prompt with three choices: *yes*, *yes, always allow*, *no*
- **`never`** — deny silently, Sol gets an error response
Choosing "yes, always allow" upgrades the permission to `always` for the rest of the session (in-memory only).
The TUI shows real-time status updates as Sol thinks and executes tools. Approval prompts appear inline when a tool needs permission.
## Session Resumption
Sessions are tied to a project path + git branch. If a session already exists for the current context, Sol resumes it — the TUI loads conversation history and you can continue where you left off.
## Code Reindexing
Separately from coding sessions, you can trigger repo indexing into Sol's code search:
```bash
sunbeam reindex-code # all repos
sunbeam reindex-code --org studio # specific org
sunbeam reindex-code --repo studio/sol --branch main # specific repo + branch
```
This calls Sol's `ReindexCode` gRPC endpoint, which walks Gitea repos, extracts symbols via tree-sitter, and indexes them to OpenSearch.
## Architecture
The `sunbeam code` command is structured as three concurrent layers: