Command line#
Everything c4studio does is available from the c4 command. Every command takes a .dsl or workspace .json file. The commands that report on a model exit non-zero on a problem, so any of them can gate a CI job.
c4 --help
c4 <command> --help| I want to… | Command |
|---|---|
| Start a new workspace | c4 new |
| Edit a model and see it | c4 webapp |
| Know whether a file parses | c4 check |
| Hold a model to standards | c4 lint |
| See what a change did to the model | c4 diff |
| Know what a change to one element touches | c4 impact |
| Get SVG files | c4 render |
| Get a website | c4 publish |
| Get Mermaid | c4 generate |
| Get Structurizr JSON | c4 export |
| List views or perspectives, for scripts | c4 list-views, c4 list-perspectives |
c4 render, c4 publish and the VS Code preview draw what the Studio draws: the same layout, box sizes, shapes, lines, labels and legend. Where the two ever differ, the Studio is right and the renderer is the bug.
Lint rules#
c4 lint asks whether a model is a good model, where c4 check only asks whether it parses. Every finding is a warning, because a model that breaks a house style still renders, so the exit code is what gates CI: 1 on any finding, or 0 with --exit-zero.
| Rule | What it reports |
|---|---|
orphan-element | An element with no relationships. A system whose containers have relationships is not an orphan, because a view lifts those relationships to it. |
missing-description | An element with no description. |
missing-technology | A container or component with no technology. People and systems have none by design. |
duplicate-relationship | The same relationship declared twice. |
unused-style | A style whose tag nothing carries. It is invisible otherwise, because the legend only lists the styles in use. Tags that come from a theme are not reported. |
invalid-badge-colour | A c4studio.badge value that is not a hex colour. |
invalid-icon-tint | A c4studio.iconTint value that is not true, false or a hex colour. |
naming-convention | A name that does not match the pattern configured for its element type. Off until you configure a pattern. |
Configure the rules in c4studio.lint.json beside the workspace, or pass --config:
{
"ignore": ["missing-technology"],
"naming": {"container": "^[A-Z]", "softwareSystem": "^[A-Z]"}
}ignore skips rules and select runs only the rules listed. naming maps an element type to a regular expression its names must match. --json emits the same diagnostic shape the editors read, so findings land in the Studio's problems list and in the VS Code Problems panel.
Diffs between revisions#
c4 diff compares the model at two git revisions, and resolves !include fragments at the older revision too:
c4 diff architecture.dsl # working tree against HEAD
c4 diff architecture.dsl --from main --to HEAD # two revisions
c4 diff architecture.dsl --from v1.0 --json # for a script or PR commentIt reports elements and relationships added, removed and changed, and the views a reviewer has to look at again. A comment-only edit produces nothing. An element's identity comes from its DSL identifier, so renaming an element that has one is a change. Renaming an element without one reads as a removal plus an addition, and when the two share a name the pair is flagged as a possible rename rather than assumed: a diff that invents a rename can hide a deletion.
Environment#
| Variable | Used by | Purpose |
|---|---|---|
C4STUDIO_NODE | render, publish | Path to a node binary when it is not on PATH, for example under nvm or conda. |
ANTHROPIC_API_KEY | webapp --assistant | The key for the optional assistant. Read when it is used, never stored. |
Reference#
Generated from the commands themselves, so it always matches the installed version.
c4 check#
c4 check [OPTIONS] INPUT_FILEReport problems in INPUT_FILE without generating anything.
INPUT_FILE may be - to read DSL from stdin, which is how an editor checks a buffer that has not been saved. Pass --path with it so diagnostics name the real file and relative directives resolve.
Exits 1 when the file has errors (or, with --strict, warnings), so it can gate a CI job. Warnings cover DSL the parser understood but did not implement — those constructs are skipped, and this is where that becomes visible.
| Option | What it does |
|---|---|
--path | File the source on stdin belongs to. Diagnostics are reported against it, and relative !include/!docs/!adrs targets resolve next to it. |
--json | Emit diagnostics as JSON, for editors and other tools. |
--strict | Exit non-zero on warnings as well as errors. |
c4 diff#
c4 diff [OPTIONS] INPUT_FILEWhat changed in INPUT_FILE between two revisions.
Elements and relationships added, removed and changed, and the views a reviewer has to look at again. Compares the working tree against HEAD by default, which is the question you ask before opening a pull request.
A renamed element with no alias reads as a removal and an addition — its id comes from its name, and nothing ties the two together. Such a pair is flagged rather than guessed at: a diff that invents a rename hides a deletion.
| Option | What it does |
|---|---|
--from | Revision to compare from — a branch, a tag or a SHA. Default: HEAD. |
--to | Revision to compare to. Defaults to the working tree. |
--json | Emit the diff as JSON, for a PR comment or a script. |
c4 export#
c4 export [OPTIONS] INPUT_FILEExport INPUT_FILE (DSL or JSON) as Structurizr workspace JSON.
The output round-trips with structurizr.com, Structurizr Lite, and this package's own JSON parser.
| Option | What it does |
|---|---|
--output, -o | Output file (default: print to stdout). |
c4 generate#
c4 generate [OPTIONS] INPUT_FILEGenerate diagrams from INPUT_FILE (DSL or JSON).
| Option | What it does |
|---|---|
--output, -o | Output directory (default: print to stdout). |
--view, -v | Only generate for this view key. |
--format, -f | mermaid: Mermaid C4 syntax (C4Context/C4Container/C4Component). flowchart: Mermaid flowchart + subgraph — renders more reliably on GitHub and dense models, and covers dynamic, deployment and filtered views too. Default: mermaid. |
c4 impact#
c4 impact [OPTIONS] INPUT_FILE IDENTIFIERWhat else is involved when IDENTIFIER changes.
Answers the change-advisory question of the model rather than of whoever remembers: what depends on this element, what it depends on, and which diagrams to look at.
Containment counts in both directions — changing a software system changes what is inside it, and a relationship declared against a container is one its system takes part in, which is the same rule the views apply when they lift an edge to the nearest visible ancestor.
| Option | What it does |
|---|---|
--json | Emit the answer as JSON, for scripts and tickets. |
--depth | Stop after this many relationships (default: the whole graph). |
c4 lint#
c4 lint [OPTIONS] INPUT_FILECheck INPUT_FILE against the model standards.
Where check asks whether the file parses, this asks whether it is a good model: elements nothing relates to, missing descriptions and technologies, relationships declared twice, styles that match nothing, badge colours that are not hex.
Every finding is a warning — a model that breaks a house style still parses and still renders — so the exit code is what makes CI care: 1 when anything is found, unless --exit-zero.
Rules are configured in JSON, by default c4studio.lint.json beside INPUT_FILE::
{"ignore": ["missing-technology"], "naming": {"container": "^[A-Z]"}}
| Option | What it does |
|---|---|
--json | Emit findings as JSON, for editors and other tools. |
--config | Rule configuration. Defaults to c4studio.lint.json beside INPUT_FILE when that exists. |
--ignore | Rule code to skip. Repeatable; adds to any configured ignores. |
--select | Run only these rule codes. Repeatable. |
--exit-zero | Report findings but exit 0, for a first run on an existing model. |
c4 list-perspectives#
c4 list-perspectives [OPTIONS] INPUT_FILEList the perspective names used anywhere in INPUT_FILE.
The same set the Studio's perspective picker offers and that c4 render --perspective accepts, from the same function, so a caller cannot be offered a name the renderer would refuse. Its own command rather than a field on list-views --json: perspectives belong to the model, not to a view, and that JSON is an array whose shape other tools already read.
| Option | What it does |
|---|---|
--json | Emit the names as a JSON array, for tools rather than people. |
c4 list-views#
c4 list-views [OPTIONS] INPUT_FILEList all views defined in INPUT_FILE.
--json emits the same index the web app serves from GET /api/views — the same function, so the two cannot drift — including which views are renderable and which one the DSL marks default. The VS Code extension reads it to populate its view picker; the table above it is for reading.
| Option | What it does |
|---|---|
--json | Emit the view index as JSON, for tools rather than people. |
c4 new#
c4 new [OPTIONS] [OUTPUT]Write a starter workspace to OUTPUT (default: workspace.dsl).
| Option | What it does |
|---|---|
--template | Which starter workspace to write. Default: minimal. |
--name | Workspace name. Defaults to the template's own. |
--list | List the available templates and exit. |
--force | Overwrite OUTPUT if it already exists. |
c4 publish#
c4 publish [OPTIONS] INPUT_FILEWrite INPUT_FILE as a self-contained HTML site.
Every view becomes a page, with the !docs prose and the ADRs beside them and navigation between. One page per view rather than one page with a switcher, so a link to a diagram survives being pasted into a ticket.
The result has no external references — diagrams are inlined SVG and theme icons are embedded as data: URIs — so it works from a file:// path, on an air-gapped machine, or on any static host.
| Option | What it does |
|---|---|
--output, -o | Directory to write the site into. Default: site. |
--perspective | Draw every diagram with this perspective shown. |
--no-layout | Ignore the layout sidecar and lay every diagram out afresh. |
--clean | Delete the output directory first. |
c4 render#
c4 render [OPTIONS] INPUT_FILERender diagrams from INPUT_FILE as standalone SVG.
No browser and no server: the diagrams are laid out and painted by the same code the web app runs, bundled for Node. The layout sidecar beside INPUT_FILE is honoured when there is one, so a rendered diagram matches the arrangement you made in the Studio; --no-layout ignores it. This is the only command that needs Node.js installed; set C4STUDIO_NODE if it is not on PATH. Views the renderer cannot draw (custom, image) are skipped.
| Option | What it does |
|---|---|
--output, -o | Output directory (default: print to stdout). |
--view, -v | Only render this view key. |
--padding | Blank margin around the diagram, in pixels. Default: 24. |
--no-title | Omit the heading above the diagram (the SVG <title> stays). |
--no-legend | Omit the legend of element styles used by the view. |
--no-layout | Ignore the layout sidecar and lay the diagram out afresh. The sidecar is per-user state, so this is what makes the output the same on any machine. |
--perspective | Show one perspective: fade what does not carry it, badge what does, and list its values in the legend. |
c4 webapp#
c4 webapp [OPTIONS] PATHLaunch the React web application backend for PATH.
PATH may be a directory (browsed as the source root) or a single source file (loaded eagerly, with its parent directory as the root).
Serves the full Studio by default. --viewer serves Viewer instead: the DSL cannot be edited, though diagrams can still be arranged — layout is per-user UI state in a gitignored sidecar either way.
--assistant additionally enables the DSL assistant, which is the one feature that sends your workspace source to an external API. It is off unless you ask for it.
| Option | What it does |
|---|---|
--assistant | Enable the DSL assistant. OFF BY DEFAULT: it is the one feature that sends your workspace source to an external API. Needs ANTHROPIC_API_KEY in the environment and the optional extra (pip install 'c4studio[assistant]'). |
--dynamic-perspectives | Let the server read a perspective's url for its live value. OFF BY DEFAULT: the addresses come from the workspace file, so opening someone else's model would otherwise make this machine call their hosts. Only http and https are followed. |
--port | Port to listen on. Default: 8090. |
--host | Default: 127.0.0.1. |
--no-browser | Do not open a browser window automatically. |
--viewer | Serve read-only: the DSL cannot be edited in the browser. |