# databricks/ucode architecture

> Architecture diagram of the GitHub repository databricks/ucode, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/databricks/ucode
- Repository: https://github.com/databricks/ucode

## Overview

#### Purpose and entry points
`ucode` is a Python 3.12+ CLI that configures and launches third-party coding agents against Databricks AI Gateway using Databricks workspace credentials rather than agent-provider API keys. The command surface and dispatch live in `src/ucode/cli.py`; launch orchestration is in `src/ucode/launcher.py`; initial authentication/configuration flow begins in `src/ucode/bootstrap.py`.

#### Workspace state, authentication, and configuration lifecycle
The CLI resolves workspace URLs or Databricks CLI profiles, authenticates, discovers available Gateway models, persists local state, and writes/restores agent-owned configuration files. This is the boundary between local machine state and Databricks workspace APIs. Key modules are `src/ucode/state.py`, `src/ucode/config_io.py`, and `src/ucode/databricks.py`. Existing configurations are backed up before mutation and can be restored through `revert`.

#### Agent adapter layer
Each supported coding tool has an adapter responsible for native config format, launch command, model defaults, and validation behavior. Shared registration is in `src/ucode/agents/__init__.py`; representative implementations are `src/ucode/agents/codex.py`, `src/ucode/agents/claude.py`, and `src/ucode/agents/cursor.py`. Cursor is structurally distinct: it receives MCP configuration only and is not routed through Gateway model configuration.

#### Gateway launch and model routing
After local configuration, the launcher starts the selected external CLI as a child process with its normal arguments. Agent traffic is directed to Databricks AI Gateway endpoints, with model availability and validation mediated through the Databricks integration. Smart routing is opt-in for Codex and Claude: it selects a root-session model before launch and installs agent-profile hooks for subagent requests. Core routing logic and tool-specific integration are in `src/ucode/smart_routing/routing.py`, `src/ucode/smart_routing/codex_routing.py`, and `src/ucode/smart_routing/claude_routing.py`.

#### MCP and skills integration
MCP-capable agents are configured to invoke a local stdio proxy rather than directly contact Databricks HTTP endpoints. The proxy refreshes OAuth credentials per request, bridging the agent’s MCP client to Databricks streamable-HTTP MCP services. Registration and proxy behavior are centered in `src/ucode/mcp.py`, `src/ucode/mcp_proxy.py`, and `src/ucode/gateway_proxy.py`. Skills support either downloads Unity Catalog skill content into agent skill directories or exposes skills through MCP; implementation is in `src/ucode/skills_download.py` and `src/ucode/mcp_web_search.py`.

#### Managed workspace configuration
Workspace administrators can author a versioned local managed-config manifest, compose agents/models/MCPs/skills/spend tiers, compare it with the live workspace configuration, and publish updates atomically. This admin plane is separate from individual developer setup. Main stages are manifest representation and resolution (`src/ucode/managed_config.py`, `src/ucode/managed_resolve.py`), interactive authoring (`src/ucode/managed_setup.py`, `src/ucode/managed_wizard.py`), and budget policy (`src/ucode/managed_budget.py`).

#### Operational reporting and dependencies
Usage reporting can query AI Gateway activity and workspace SQL warehouse data; telemetry and tracing provide runtime observability. Relevant paths are `src/ucode/usage.py`, `src/ucode/telemetry.py`, and `src/ucode/tracing.py`. Material external dependencies are the Databricks CLI/auth profile system, Databricks AI Gateway, Databricks MCP and Unity Catalog services, installed coding-agent CLIs, and npm when an agent CLI must be installed.

Main entry points: [`src/ucode/launcher.py`](https://github.com/databricks/ucode/blob/main/src/ucode/launcher.py) (Launcher), [`src/ucode/agents/__init__.py`](https://github.com/databricks/ucode/blob/main/src/ucode/agents/__init__.py) (Agent registry), [`src/ucode/bootstrap.py`](https://github.com/databricks/ucode/blob/main/src/ucode/bootstrap.py) (Bootstrap), [`src/ucode/managed_config.py`](https://github.com/databricks/ucode/blob/main/src/ucode/managed_config.py) (Managed manifest)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI &amp; Launch"]
  node_cli_dispatch["CLI commands<br/>Python CLI<br/>[cli.py]"]
  node_launcher["Launcher<br/>orchestrator<br/>[launcher.py]"]
end

subgraph group_local["Local Setup"]
  node_bootstrap["Bootstrap<br/>setup flow<br/>[bootstrap.py]"]
  node_state_config[("Local state &amp; config I/O<br/>local persistence<br/>[state.py]")]
  node_databricks["Databricks integration<br/>workspace client<br/>[databricks.py]"]
end

subgraph group_agents["Agent Adapters"]
  node_agent_registry["Agent registry<br/>adapter registry<br/>[__init__.py]"]
  node_codex_adapter["Codex adapter<br/>agent adapter<br/>[codex.py]"]
  node_claude_adapter["Claude adapter<br/>agent adapter<br/>[claude.py]"]
  node_cursor_adapter["Cursor adapter<br/>MCP-only adapter<br/>[cursor.py]"]
end

subgraph group_routing["Gateway &amp; MCP"]
  node_smart_routing["Smart routing<br/>routing policy<br/>[routing.py]"]
  node_agent_routing_hooks["Agent routing hooks<br/>tool integration<br/>[codex_routing.py]"]
  node_mcp_registration["MCP registration<br/>MCP configuration<br/>[mcp.py]"]
  node_mcp_proxy["Local MCP proxy<br/>stdio proxy<br/>[mcp_proxy.py]"]
  node_skills["Skills integration<br/>skill delivery<br/>[skills_download.py]"]
end

subgraph group_managed["Managed Admin Plane"]
  node_managed_manifest["Managed manifest<br/>versioned configuration<br/>[managed_config.py]"]
  node_managed_resolution["Managed resolution<br/>configuration resolver<br/>[managed_resolve.py]"]
  node_managed_authoring["Managed authoring<br/>interactive setup<br/>[managed_setup.py]"]
  node_budget_policy["Budget policy<br/>spend controls<br/>[managed_budget.py]"]
end

node_reporting["Usage &amp; observability<br/>reporting<br/>[usage.py]"]
node_databricks_services{{"Databricks workspace<br/>external platform"}}
node_agent_clis{{"Installed agent CLIs<br/>external processes"}}

node_cli_dispatch -->|"setup commands"| node_bootstrap
node_cli_dispatch -->|"launch / revert"| node_launcher
node_bootstrap -->|"authenticate and discover"| node_databricks
node_bootstrap -->|"persist setup"| node_state_config
node_launcher -->|"write, backup, restore config"| node_state_config
node_launcher -->|"select adapter"| node_agent_registry
node_agent_registry --> node_codex_adapter
node_agent_registry --> node_claude_adapter
node_agent_registry --> node_cursor_adapter
node_launcher -.->|"opt-in routing"| node_smart_routing
node_smart_routing -->|"install profiles"| node_agent_routing_hooks
node_launcher -->|"configure MCP agents"| node_mcp_registration
node_mcp_registration -->|"local stdio endpoint"| node_mcp_proxy
node_mcp_proxy -->|"OAuth-backed MCP requests"| node_databricks_services
node_launcher -->|"configure skills"| node_skills
node_skills -->|"Unity Catalog content"| node_databricks_services
node_launcher -->|"spawn with normal arguments"| node_agent_clis
node_agent_clis -->|"Gateway model traffic"| node_databricks_services
node_databricks -->|"workspace APIs"| node_databricks_services
node_managed_authoring -->|"author manifest"| node_managed_manifest
node_managed_manifest -->|"resolve and compare"| node_managed_resolution
node_budget_policy -->|"spend tiers"| node_managed_manifest
node_managed_resolution -->|"atomically publish"| node_databricks_services
node_reporting -->|"Gateway activity and SQL usage"| node_databricks_services

click node_cli_dispatch "https://github.com/databricks/ucode/blob/main/src/ucode/cli.py"
click node_bootstrap "https://github.com/databricks/ucode/blob/main/src/ucode/bootstrap.py"
click node_launcher "https://github.com/databricks/ucode/blob/main/src/ucode/launcher.py"
click node_state_config "https://github.com/databricks/ucode/blob/main/src/ucode/state.py"
click node_databricks "https://github.com/databricks/ucode/blob/main/src/ucode/databricks.py"
click node_agent_registry "https://github.com/databricks/ucode/blob/main/src/ucode/agents/__init__.py"
click node_codex_adapter "https://github.com/databricks/ucode/blob/main/src/ucode/agents/codex.py"
click node_claude_adapter "https://github.com/databricks/ucode/blob/main/src/ucode/agents/claude.py"
click node_cursor_adapter "https://github.com/databricks/ucode/blob/main/src/ucode/agents/cursor.py"
click node_smart_routing "https://github.com/databricks/ucode/blob/main/src/ucode/smart_routing/routing.py"
click node_agent_routing_hooks "https://github.com/databricks/ucode/blob/main/src/ucode/smart_routing/codex_routing.py"
click node_mcp_registration "https://github.com/databricks/ucode/blob/main/src/ucode/mcp.py"
click node_mcp_proxy "https://github.com/databricks/ucode/blob/main/src/ucode/mcp_proxy.py"
click node_skills "https://github.com/databricks/ucode/blob/main/src/ucode/skills_download.py"
click node_managed_manifest "https://github.com/databricks/ucode/blob/main/src/ucode/managed_config.py"
click node_managed_resolution "https://github.com/databricks/ucode/blob/main/src/ucode/managed_resolve.py"
click node_managed_authoring "https://github.com/databricks/ucode/blob/main/src/ucode/managed_setup.py"
click node_budget_policy "https://github.com/databricks/ucode/blob/main/src/ucode/managed_budget.py"
click node_reporting "https://github.com/databricks/ucode/blob/main/src/ucode/usage.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli_dispatch,node_launcher toneBlue
class node_bootstrap,node_state_config,node_databricks toneAmber
class node_agent_registry,node_codex_adapter,node_claude_adapter,node_cursor_adapter toneMint
class node_smart_routing,node_agent_routing_hooks,node_mcp_registration,node_mcp_proxy,node_skills toneRose
class node_managed_manifest,node_managed_resolution,node_managed_authoring,node_budget_policy toneIndigo
class node_reporting,node_databricks_services,node_agent_clis toneNeutral
```

## Components

### CLI & Launch

- [CLI commands](https://github.com/databricks/ucode/blob/main/src/ucode/cli.py): Python CLI · Command parsing and dispatch. · `src/ucode/cli.py`
- [Launcher](https://github.com/databricks/ucode/blob/main/src/ucode/launcher.py): orchestrator · Configures and starts the selected agent process. · `src/ucode/launcher.py`

### Local Setup

- [Bootstrap](https://github.com/databricks/ucode/blob/main/src/ucode/bootstrap.py): setup flow · Initial workspace authentication and configuration. · `src/ucode/bootstrap.py`
- [Local state & config I/O](https://github.com/databricks/ucode/blob/main/src/ucode/state.py): local persistence · Persists state and backs up or restores agent configuration. · `src/ucode/state.py`
- [Databricks integration](https://github.com/databricks/ucode/blob/main/src/ucode/databricks.py): workspace client · Resolves profiles, authenticates, and discovers Gateway models. · `src/ucode/databricks.py`

### Agent Adapters

- [Agent registry](https://github.com/databricks/ucode/blob/main/src/ucode/agents/__init__.py): adapter registry · `src/ucode/agents/__init__.py`
- [Codex adapter](https://github.com/databricks/ucode/blob/main/src/ucode/agents/codex.py): agent adapter · `src/ucode/agents/codex.py`
- [Claude adapter](https://github.com/databricks/ucode/blob/main/src/ucode/agents/claude.py): agent adapter · `src/ucode/agents/claude.py`
- [Cursor adapter](https://github.com/databricks/ucode/blob/main/src/ucode/agents/cursor.py): MCP-only adapter · Uses MCP configuration rather than Gateway model configuration. · `src/ucode/agents/cursor.py`

### Gateway & MCP

- [Smart routing](https://github.com/databricks/ucode/blob/main/src/ucode/smart_routing/routing.py): routing policy · Selects root models and coordinates subagent routing. · `src/ucode/smart_routing/routing.py`
- [Agent routing hooks](https://github.com/databricks/ucode/blob/main/src/ucode/smart_routing/codex_routing.py): tool integration · Codex and Claude profiles route subagent requests. · `src/ucode/smart_routing/codex_routing.py`
- [MCP registration](https://github.com/databricks/ucode/blob/main/src/ucode/mcp.py): MCP configuration · `src/ucode/mcp.py`
- [Local MCP proxy](https://github.com/databricks/ucode/blob/main/src/ucode/mcp_proxy.py): stdio proxy · Refreshes OAuth credentials for each MCP request. · `src/ucode/mcp_proxy.py`
- [Skills integration](https://github.com/databricks/ucode/blob/main/src/ucode/skills_download.py): skill delivery · Downloads Unity Catalog skills or exposes skills through MCP. · `src/ucode/skills_download.py`

### Managed Admin Plane

- [Managed manifest](https://github.com/databricks/ucode/blob/main/src/ucode/managed_config.py): versioned configuration · Defines managed agents, models, MCPs, skills, and spend tiers. · `src/ucode/managed_config.py`
- [Managed resolution](https://github.com/databricks/ucode/blob/main/src/ucode/managed_resolve.py): configuration resolver · Compares and resolves manifest state against the workspace. · `src/ucode/managed_resolve.py`
- [Managed authoring](https://github.com/databricks/ucode/blob/main/src/ucode/managed_setup.py): interactive setup · `src/ucode/managed_setup.py`
- [Budget policy](https://github.com/databricks/ucode/blob/main/src/ucode/managed_budget.py): spend controls · `src/ucode/managed_budget.py`

### Other components

- [Usage & observability](https://github.com/databricks/ucode/blob/main/src/ucode/usage.py): reporting · Queries usage and emits telemetry and tracing. · `src/ucode/usage.py`
- **Databricks workspace**: external platform · AI Gateway, MCP services, Unity Catalog, and SQL warehouse.
- **Installed agent CLIs**: external processes · Third-party coding agents launched as child processes.

## Connections

- CLI commands → Bootstrap: setup commands
- CLI commands → Launcher: launch / revert
- Bootstrap → Databricks integration: authenticate and discover
- Bootstrap → Local state & config I/O: persist setup
- Launcher → Local state & config I/O: write, backup, restore config
- Launcher → Agent registry: select adapter
- Agent registry → Codex adapter
- Agent registry → Claude adapter
- Agent registry → Cursor adapter
- Launcher → Smart routing: opt-in routing
- Smart routing → Agent routing hooks: install profiles
- Launcher → MCP registration: configure MCP agents
- MCP registration → Local MCP proxy: local stdio endpoint
- Local MCP proxy → Databricks workspace: OAuth-backed MCP requests
- Launcher → Skills integration: configure skills
- Skills integration → Databricks workspace: Unity Catalog content
- Launcher → Installed agent CLIs: spawn with normal arguments
- Installed agent CLIs → Databricks workspace: Gateway model traffic
- Databricks integration → Databricks workspace: workspace APIs
- Managed authoring → Managed manifest: author manifest
- Managed manifest → Managed resolution: resolve and compare
- Budget policy → Managed manifest: spend tiers
- Managed resolution → Databricks workspace: atomically publish
- Usage & observability → Databricks workspace: Gateway activity and SQL usage
