Command families and operational workflows
The Bruin CLI gives engineers one command surface for creating pipeline projects, checking asset definitions, inspecting planned work, running data work, and operating local or cloud resources. It turns a project path, asset path, or named cloud resource into a controlled workflow with shared configuration, safety checks, and script-friendly output.
See CLI workflows for the wider lifecycle model and project scaffolding for project creation. For split cloud runs and recovery, see backfill and recovery.
Command model
The command model keeps the user-facing entry point stable while grouping actions by the object they affect. Most local commands start with a project or asset path. Cloud commands start with a resource family and then identify the remote object.
Root command and command families
The root command is bruin. It registers direct workflows such as run, validate, render, and unit-test. It also registers families such as import, connections, environments, cloud, and ai.
| Family or command | Main responsibility | Typical invocation |
|---|---|---|
init | Create a project from a bundled template | bruin init [template] [folder] |
format, patch, clean, docs | Prepare, repair, document, or clean local project files | bruin format [path] |
validate, unit-test, run | Check definitions, test SQL behavior, or execute assets | bruin validate [path] |
render, render-ddl, lineage, query, data-diff | Inspect planned work, dependencies, or data | bruin render path/to/asset.sql |
environments, connections | Manage local execution settings and service access | bruin connections test --name warehouse |
import | Turn database, service, package, or task definitions into Bruin assets | bruin import database path/to/pipeline |
cloud | Read and change Bruin Cloud resources | bruin cloud runs list --project-id ID --pipeline NAME |
ai, mcp | Use assisted asset workflows or expose Bruin context to tools | bruin ai enhance path/to/asset.sql |
version, upgrade | Inspect or update the CLI itself | bruin version |
The hidden internal family supports structured calls for editors, agents, and other tools. It is not the normal path for a person who wants to run a pipeline.
References: main.go• L39-86 cmd/internal.go• L39-61 cmd/internal_test.go• L398-432
Shared project context
Project commands use .bruin.yml as the shared source for environments and connections. When a command has no explicit configuration path, it finds the Git repository root and uses the project configuration there. The --config-file flag and BRUIN_CONFIG_FILE provide an alternate path for commands that support them.
An environment selects the connection values used by later work. Commands that can change data treat names that look like production environments as protected and ask for confirmation unless the user supplies the command's force control. A secrets backend can replace .bruin.yml as the source of secret-backed connections.
Cloud commands use the same project configuration for a repository login and an optional default team. An explicit --team or BRUIN_CLOUD_TEAM value takes priority over the saved team. If no team is selected, Cloud resolves scope from the credential or reports that a team is needed.
References: main.go• L48-61 cmd/helpers.go• L39-68 cmd/run.go• L847-856 cmd/render.go• L391-428 cmd/cloud.go• L147-213 cmd/cloud.go• L334-450 cmd/cloud_test.go• L200-318
Output and execution modes
Commands default to text for people at a terminal. Commands that expose --output can return JSON for scripts, editors, and agents. Machine output stays separate from status and error messages so callers do not need to parse a terminal display.
Common controls shape the same workflow without changing its purpose:
--debugadds diagnostic detail at the root level.--environmentselects the configuration context.--config-fileselects a different project configuration.--varsupplies pipeline or query variable overrides.--variantselects one declared pipeline variant.--output jsonrequests structured output where the command supports it.
Interactive views help with selection and live progress. Non-interactive flags make repeatable scripts possible. Query results can be printed as plain text, JSON, or CSV, or written to export files.
References: main.go• L21-37 cmd/helpers.go• L94-134 cmd/const.go• L217-243 cmd/run.go• L597-774 cmd/cloud.go• L92-144 cmd/cloud_test.go• L26-88
Local pipeline lifecycle
The local lifecycle moves from project content to a checked and observed execution. Each command can enter the lifecycle at a different point when the project, configuration, or asset already exists.
This diagram shows how a typical local change moves from preparation to execution and review.
flowchart LR
A[Initialize or import] --> B[Format or patch]
B --> C[Render or unit-test]
C --> D[Validate]
D --> E[Run selected work]
E --> F[Review logs and lineage]
G[Configure environment and connections] --> D
G --> E
Project and asset preparation
init creates a starting project from a bundled template. format normalizes asset definitions. patch repairs dependencies, fills column metadata, or applies structured changes. These commands prepare local inputs for validation and execution.
docs creates a self-contained view of pipeline and asset information. clean removes local run logs and selected runtime caches.
References: cmd/init.go• L203-235 cmd/init_template_test.go• L22-104 cmd/format.go• L23-81 cmd/patch.go• L227-247 cmd/docs.go• L18-74 cmd/clean.go• L22-49
Validation and execution
validate checks pipeline and asset definitions before data work starts. It returns findings rather than changing data. run resolves the project or asset path, builds the selected work, validates pending assets, and executes them through the configured connections.
Users can run one asset, several assets, downstream work, a selected group, checks, metadata pushes, or a date interval. A declared pipeline variant must be selected. Normal batch runs exclude streaming assets. Streaming mode targets one streaming asset and stays active until interruption.
Unless the user sets dates, run uses the beginning and end of the previous UTC day. A full refresh is a separate execution choice and can be restricted by the asset or environment. The run summary separates successful, failed, skipped, and not-started work.
Common invocations include:
bruin validate path/to/pipelinebruin run path/to/asset.sqlbruin run --downstream path/to/asset.sqlbruin run --selector 'tag:daily' path/to/pipelinebruin run --variant NAME path/to/pipelinebruin run --stream path/to/streaming-asset.ymlbruin run path/to/script.py
References: cmd/run.go• L534-595 cmd/run.go• L597-774 cmd/run.go• L775-1001 cmd/run.go• L1003-1219 cmd/run.go• L1424-1503 cmd/run_test.go• L2337-2412 cmd/variable_schema_test.go• L15-61
SQL unit testing
unit-test checks SQL assets against their configured connection without changing the target. It turns each declared test into a read-only query with mocked inputs, then compares the result with the expected values.
An asset path runs tests for one asset. A directory runs tests for every pipeline found below it. Variables, dates, macros, and the selected environment affect the prepared query. The command exits with failure when any test fails.
References: cmd/unittest.go• L24-124 cmd/unittest.go• L134-167 cmd/unittest.go• L226-323 cmd/unittest.go• L359-400
Query rendering and inspection
render shows the SQL that one SQL asset would use after project settings are applied. render-ddl shows the schema-changing form without running the asset. Both commands inspect planned work without running the full pipeline.
query is the direct data access path. It supports direct SQL with a connection, an asset query, or a semantic model query. Results can use plain text, JSON, or CSV output. lineage reports upstream and downstream relationships. data-diff compares two tables without changing either source.
| Need | Command | Result |
|---|---|---|
| See rendered SQL | bruin render path/to/asset.sql | Planned query |
| See table-changing DDL | bruin render-ddl path/to/asset.sql | Planned DDL |
| Run an ad hoc query | bruin query --connection NAME --query 'SELECT ...' | Query rows |
| Inspect dependencies | bruin lineage path/to/asset.sql --full | Dependency summary |
| Compare data | bruin data-diff TABLE_A TABLE_B | Comparison report |
References: cmd/render.go• L55-100 cmd/render.go• L101-235 cmd/render.go• L461-564 cmd/fetch.go• L56-337 cmd/query_stream.go• L19-76 cmd/query_stream_test.go• L50-355 cmd/lineage.go• L14-43 cmd/datadiff.go• L155-240
Import and metadata intake
The import family brings definitions that already exist in another system into a Bruin pipeline. It can discover database tables, scheduled queries, task definitions, packages, dashboards, and other service objects. The result is local asset content that can pass through formatting, dependency repair, validation, and execution.
Database import can create source or SQL view assets. With --ingestr and a destination, it creates runnable assets that replicate source tables. Re-import merges source facts into matching assets while preserving user-defined metadata.
| Command | Source or outcome |
|---|---|
bruin import database PIPELINE | Database tables and optional column details |
bruin import database PIPELINE --ingestr --destination DESTINATION | Runnable table replication assets |
bruin import bq-scheduled-queries PIPELINE | BigQuery scheduled queries |
bruin import snowflake-tasks PIPELINE | Snowflake task definitions and dependencies |
bruin import tableau PIPELINE | Tableau dashboards and views |
bruin import quicksight PIPELINE | QuickSight datasets and dashboards |
References: cmd/import.go• L44-172 cmd/import.go• L318-487 cmd/import_database_tui.go• L23-62 cmd/import_database_tui.go• L197-430
Schema discovery and fetch commands
The user-facing query command reads data. The hidden internal fetch-* commands discover service metadata before an asset is written or repaired. They return databases, tables, or columns in plain or JSON form.
The normal discovery order is databases, then tables for one database, then columns for one table. Fetch commands describe available schema. They do not read table data like query.
References: cmd/fetch.go• L52-193 cmd/internal.go• L39-61 cmd/internal.go• L935-1020 cmd/internal.go• L1044-1173 cmd/internal.go• L1236-1277
Configuration and service operations
Local configuration and cloud operations use the same CLI pattern but act on different scopes. Local commands update or consume .bruin.yml. Cloud commands send requests to Bruin Cloud and identify resources with project, pipeline, run, or resource IDs.
Authentication and credential scope
Cloud authentication can be stored in the current repository or in the operating system credential store. The CLI resolves credentials from an explicit API key, an environment key, an active act-as session, a repository Cloud connection, or a global login. bruin cloud auth status reports the source and scope without printing the token.
bruin cloud login starts sign-in and saves the result in the selected scope. Repository login uses the Git worktree's .bruin.yml and does not replace an existing login unless the user chooses reauthentication. It refuses to save tokens into a tracked configuration file. bruin cloud logout removes a repository connection or global credential. --revoke also invalidates the token in Bruin Cloud. Non-interactive use must state the login or logout scope.
bruin cloud act-as starts, reports, or stops a session that uses an agent's Cloud permissions. The session is team-bound and takes precedence over repository and global credentials. An explicit API key or BRUIN_CLOUD_API_KEY still takes precedence. Cloud commands renew the session near expiry. --stop returns them to the user's own login.
References: cmd/cloud_auth.go• L18-100 cmd/auth.go• L16-156 cmd/login.go• L41-55 cmd/cloud_act_as.go• L31-139 cmd/auth_test.go• L20-159 cmd/login_test.go• L23-50 cmd/login_test.go• L70-232 cmd/cloud_act_as_test.go• L144-274
Environment and connection management
environments manages named configuration contexts. Users can list, create, update, clone, or delete them. connections manages local service entries inside an environment.
A normal setup sequence is:
- Run
bruin environments listto see the available contexts. - Create or clone an environment when the project needs a new context.
- Add service entries with
bruin connections addor the interactive form. - Run
bruin connections test --name NAME --env ENVbefore validation or execution.
References: cmd/environments.go• L17-187 cmd/connections.go• L22-207
Cloud resource operations
cloud is the remote operations family. Team-scoped commands accept --team or BRUIN_CLOUD_TEAM, with a saved default as a fallback. cloud config manages that local default. It does not target a remote team resource. login, logout, and act-as manage account or session scope rather than a general team resource.
| Resource group | Operational purpose |
|---|---|
teams, projects | Discover team and project scope |
pipelines | Inspect and control deployed pipelines |
runs, backfills | Trigger, inspect, rerun, diagnose, and group remote runs |
assets, instances | Inspect deployed assets and run logs |
connections, connection-sets | Manage remote service access |
agents, skills | Manage cloud agents and their tools |
dashboards, semantic-layers, glossary | Manage cloud-facing data views and models |
scheduled-agents, audit-logs, cost | Operate schedules and inspect team activity or cost |
notification-rules | Manage cloud notifications |
Most read operations support --output json. List operations commonly support --limit and --offset. Resource actions require identifiers that avoid acting on an ambiguous object.
When a command needs a project and the user does not pass --project-id, the CLI can use the only accessible project. It asks for an explicit project when more than one is available.
References: cmd/cloud.go• L31-89 cmd/cloud.go• L155-213 cmd/cloud.go• L333-448 cmd/cloud.go• L472-642 cmd/cloud_test.go• L90-150 cmd/cloud_test.go• L200-318
Cloud semantic layer operations
A semantic layer is a named Cloud model definition that gives data views a shared business model. The semantic-layers family lets users list, inspect, create, update, and delete these definitions without changing local pipeline assets.
Creation and update accept the model definition as a JSON or YAML object supplied inline or through a file. The normal workflow is to list layers, inspect one, create or update it, then delete it when it is no longer needed.
References: cmd/cloud.go• L5369-5527 cmd/cloud_test.go• L1242-1317
Cloud dashboard notes
Dashboard notes attach human context to a Cloud dashboard. The notes workflow lists existing notes and shows the models, dimensions, and filters available to scope a new note.
bruin cloud dashboards notes create sends note content with optional model and dimension values. When a model is supplied, the CLI checks that the dashboard uses it before creating the note. JSON output is suitable for tools. Plain output combines notes with the available context.
References: cmd/cloud_dashboard_notes.go• L19-85 cmd/cloud_dashboard_notes.go• L119-207 cmd/cloud_dashboard_notes.go• L210-328 cmd/cloud_dashboard_notes_test.go• L52-182
Cloud run workflows
Cloud run commands control execution in Bruin Cloud rather than in the local process. runs trigger starts a run for a project and pipeline with a required date range. It can select assets, include downstream assets, apply a full refresh, pass variables, attach tags or a note, or split the interval into a backfill.
The usual remote review path is:
- Discover scope with
bruin cloud projects listandbruin cloud pipelines list --project-id ID. - Start work with
bruin cloud runs trigger --project-id ID --pipeline NAME --start-date START --end-date END. - Find the run with
bruin cloud runs list --project-id ID --pipeline NAME. - Inspect it with
bruin cloud runs getor--latest. - Inspect asset instances and step logs with
bruin cloud instances listandbruin cloud instances logs. - Use
bruin cloud runs diagnosefor one report of run details and failure logs.
runs rerun can repeat a full run or only failed assets. With --split, Cloud creates a backfill group with one run for each date-range batch. backfills list and backfills runs make the group and its child runs visible.
References: cmd/cloud.go• L953-1123 cmd/cloud.go• L1140-1290 cmd/cloud.go• L1292-1420 cmd/cloud.go• L1466-1781 cmd/cloud_test.go• L521-619 cmd/cloud_test.go• L1389-1526
Cloud agent and data operations
Cloud agents have their own operational loop. Users can create an agent, send a message, inspect status and threads, manage prompts and persistent run-state files, attach connections or skills, and configure MCP access.
The act-as workflow lets a person run later Cloud commands with an agent's permissions without changing the person's own login. bruin cloud act-as --agent-id ID starts the session. No flag reports its state. --output json exposes that state to tools. --stop ends it. A missing permission can offer a browser re-login in an interactive terminal. Structured output does not open a browser.
The request-connection action is different from normal agent administration. It runs only inside a Bruin Cloud chat run. The agent and thread IDs come from that run context, so the action cannot redirect a request with command-line IDs.
References: cmd/cloud.go• L2240-2263 cmd/cloud.go• L2790-2980 cmd/cloud.go• L4011-4276 cmd/cloud.go• L4279-4585 cmd/cloud_act_as.go• L42-235 cmd/cloud_dashboard_notes.go• L210-328 cmd/cloud_act_as_test.go• L277-444
Tool-facing and maintenance workflows
Not every command changes pipeline data. Some commands help tools inspect project state, help engineers improve definitions, or keep the CLI installation current.
Structured and assisted access
The hidden internal commands return structured data for parsing assets and pipelines, listing variants and templates, reading glossary data, inspecting connection schemas, and reporting asset metadata. They can also convert plain SQL or Python files into Bruin assets and lock Python dependencies.
ai enhance proposes improvements to asset metadata and quality checks. mcp starts a long-running JSON-RPC server for tools that need Bruin context.
References: cmd/internal.go• L64-190 cmd/internal.go• L766-825 cmd/internal.go• L1625-1789 cmd/internal_test.go• L122-227 cmd/internal_test.go• L241-432 cmd/enhance.go• L31-109 cmd/…/mcp.go• L39-100
CLI maintenance
version reports the installed version, commit, and latest release. upgrade checks or installs a requested release. curl renders connection fields in a caller-supplied request and preserves curl's output and exit code.
References: cmd/version.go• L22-59 cmd/upgrade.go• L504-622 cmd/curl.go• L28-85
Change checklist
When these files or sections are changed, remember to consider these:
- A new top-level command must be registered in main.go and placed in the matching command-family description.
- Changes to project or asset path discovery affect
validate,run,render,unit-test,lineage, import, patch, and hidden structured commands together. - Changes to environment or connection resolution affect validation, execution, query, import, schema fetch, local connection management, and cloud credential transfer.
- Changes to variant or variable handling must keep rendering, validation, execution, unit testing, query, lineage, and import behavior aligned.
- Changes to plain or JSON output must keep standard output clean for scripts, editor integrations, and MCP clients.
- Changes to production confirmation or force controls must be checked across every command that can modify data or remote state.
- Changes to cloud credential precedence must keep explicit keys, environment keys, act-as sessions, repository logins, global logins, status output, and logout behavior aligned.
- Changes to login or logout scope must keep interactive selection, non-interactive flags, worktree config paths, tracked-file protection, existing-login preservation, and token revocation behavior aligned.
- Changes to cloud identifiers, default team selection, or explicit team selection must keep all team-scoped cloud resource families consistent.
- Changes to act-as sessions must preserve agent permissions, team pinning, API destination checks, renewal, stop behavior, and API-key precedence.
- Changes to split cloud runs must preserve the relationship between trigger options, backfill records, and individual run inspection.
- Changes to streaming run validation must keep the single-asset rule, normal-run exclusion, open-ended timeout behavior, and refresh rules aligned with the executor.
- Changes to bundled
inittemplates must preserve the files, project metadata, local configuration, and entry points that make each generated project usable.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A project or asset path is outside a discoverable pipeline | The command cannot resolve its pipeline context | Pass a path inside a pipeline or a supported standalone Python script |
A pipeline declares variants but no --variant is supplied | The CLI cannot choose values for the run or inspection | Pass one explicit variant name |
| A production-like environment is selected without confirmation or force | A data-changing workflow stops before it starts | Confirm the environment and use force only for an approved operation |
| A connection is absent or does not support the requested action | The workflow cannot reach or inspect the service | Select the correct environment and test the connection |
| A cloud command has no usable credential or required identifier | The remote request cannot start or may address no object | Use cloud login, an API key, and the required identifiers |
| An act-as session is pinned to another team or Cloud API destination | Cloud commands reject the session instead of silently changing scope | Stop the session before selecting another team or destination |
| An act-as session expires and renewal is refused | The command stops and returns an explicit recovery path | Re-authenticate with agent permission or run bruin cloud act-as --stop |
| A tracked .bruin.yml is selected for repository login | The CLI refuses to save a token to a risky file | Use --global or stop tracking the file |
| Login or logout runs without a scope in a non-interactive terminal | The CLI cannot safely choose a destination | Pass --repo or --global |
--split is used without a valid unit or chunk size | The intended backfill cannot be created | Use a supported time unit and a chunk size of at least one |
--stream targets more than one asset or combines with a finite-run control | The CLI refuses to start an invalid long-running workflow | Pass one streaming asset and omit incompatible controls |
| An internal fetch command targets a connection without the needed capability | No database, table, or column metadata is returned | Use a connection type that supports the catalog operation |
import database --ingestr has no destination | The import cannot create the requested asset form | Pair --ingestr with a supported destination |
| A semantic layer uses both inline and file state | The create or update request is rejected | Provide one valid object definition |
Key files
| File | Why to read it |
|---|---|
| main.go | Defines the root command, global flags, and command registration. |
| cmd/helpers.go | Defines shared environment safety checks and output helpers. |
| cmd/run.go | Defines local path resolution, filtering, streaming, execution, cancellation, and summaries. |
| cmd/unittest.go | Defines the read-only SQL unit-test workflow. |
| cmd/lint.go | Defines the validation entry point and project or asset targets. |
| cmd/render.go and cmd/render_ddl.go | Define local SQL and DDL inspection. |
| cmd/fetch.go and cmd/query_stream.go | Define schema discovery, query workflows, streaming output, exports, and query logs. |
| cmd/import.go and cmd/import_database_tui.go | Define database catalog intake and selection. |
| cmd/internal.go | Defines hidden structured parsing, conversion, dependency, schema, and tool commands. |
| cmd/environments.go and cmd/connections.go | Define local environment and connection management. |
| cmd/cloud_auth.go, cmd/login.go, and cmd/auth.go | Define credential precedence, login scope, status, logout, and revocation. |
| cmd/cloud_act_as.go | Defines the agent-permission session used by later Cloud commands. |
| cmd/cloud.go | Defines Cloud resource families, team scope, remote runs, and resource actions. |
| cmd/cloud_dashboard_notes.go | Defines dashboard note context and creation. |
| cmd/cloud_test.go, cmd/login_test.go, cmd/auth_test.go, and cmd/cloud_act_as_test.go | Show contracts for cloud scope, authentication, act-as sessions, and resource behavior. |
| cmd/init.go and cmd/init_template_test.go | Define project initialization and generated-template contracts. |