Start with the instructor quickstart. Commands below assume an installed code-visualizer; in a checkout, prefix commands with uv run.
For the meaning of frames, boxes, IDs, and arrows, see reading diagrams. For palette contrast levels and SVG/PNG text alternatives, see accessibility.
code-visualizer Main.java -o main.png
code-visualizer -i Main.java -o main.png
code-visualizer < Main.java > main.png
code-visualizer Main.java -a -o steps.pngUse one source per single-program invocation. Without an input path, source is read from standard input. Without -o, a single image is written to standard output. -a requires -o and produces numbered images plus the last image at the requested path.
Single-program mode creates parent directories and replaces existing files. Batch overwrite protection, output templates, and rollback apply only to batch mode.
Use --class-path PATHS to make compiled classes and JAR dependencies available
during both compilation and execution of the Java program:
code-visualizer Main.java --class-path build/classes --class-path 'lib/*' -o main.png
code-visualizer --batch --input-dir sources --class-path build/classes --out-dir diagrams
code-visualizer --batch -i manifest.ndjson --class-path 'lib/*.jar' \
--out-dir diagrams --output-pattern '{id}.png'Repeat the option to add entries in order, or supply a native class-path list
(: on macOS/Linux, ; on Windows). Quote values containing spaces or wildcards
so the tracer receives them unchanged. The tracer expands wildcards and validates
the selected directories/JARs; missing entries or unmatched patterns fail tracing.
Empty path-list components select the current directory, following Java class-path
conventions. Relative dependency paths use the directory where you invoke the
command, including when the source or manifest is in another directory.
The option applies to every job in a batch command, including directory scans and
manifests. It is a command-level setting; manifest jobs do not add or override
class-path entries. Batch commands with this option reuse rendering browsers but
start a one-shot tracer for each job; --workers does not pool these tracer jobs.
Omitting the option retains the existing persistent batch tracing behavior.
Annotation processors do not run during guest compilation. Supply generated declarations as source; adding processor JARs to the class path does not enable annotation processing. Neighboring source directories support source discovery but do not implicitly supply compiled dependencies.
| Option | Behavior |
|---|---|
-b N, --breakpoint N |
Select a source line; repeat to request multiple lines. |
-a, --all-steps |
Trace and render all execution steps. |
--format PNG |
Select a raster encoding, standalone SVG, or a shared HTML sequence; default is PNG. Match explicit filename extensions to the encoding. |
--string-style compact|default|inline |
Choose string presentation; default: separate heap objects. |
--theme light|dark|auto |
Select a palette; omit for host-adaptive inline SVG. Auto follows the system. |
--dpi 2 |
Scale raster resolution or SVG display dimensions; default is 1. |
--no-types |
Hide type tags. |
--text-memory-labels |
Replace reference arrows with text labels. |
--strip-type-prefix PREFIX |
Strip a type-name prefix; repeat as needed. |
--array-orientation horizontal|vertical |
Set base array orientation. |
--alternate-array-orientations |
Alternate layout with array dimensionality. |
--array-orientation-for ID=ORIENTATION |
Override a heap object's orientation; repeat as needed. |
Without -a, single-program mode emits one image, even when several breakpoints are supplied. Batch mode also emits one image per job without -a. Use the Python API for explicit line-to-image mappings. Source lines and execution step indices are distinct.
See the array guide for override precedence and examples. code-visualizer --help is the installed version's complete option list.
Exports crop unused outer space by default, retaining text, borders, and reference arrows with 4 CSS pixels of padding. Bounds round outward to protect fractional edges. Spacing inside the diagram is unchanged.
A single image fits its selected state. With --all-steps, every image uses the
same crop enclosing all exported states, so dimensions and framing stay fixed.
A small state can therefore have more whitespace in a sequence than when exported
alone. Sequences require an additional pass to measure their shared bounds.
PNG and SVG use the same crop. --dpi scales output dimensions without changing
the layout used to measure it. These defaults intentionally change image dimensions
from earlier releases; documents that depend on the old dimensions may need updating.
Reference arrows may take outside routes, increasing image bounds while preserving text size. See reference routing for attachment rules, placement repair, and a runnable example.
code-visualizer Main.java --format HTML -o main.html
code-visualizer --batch --input-dir sources --format HTML --out-dir sequences--format HTML creates one self-contained, experimental SVG sequence player per
Java input. It implies --all-steps; you do not need -a. Open the HTML file in a
browser to move forward, backward, or directly to a step. Download SVG saves
the selected state as an independent SVG with its definitions and description.
Single-file mode requires -o; it writes only that file, without numbered siblings.
Batch mode defaults to {dirname}/{basename}.html; a custom --output-pattern
does not need {step}. Existing batch collision and --force rules still apply.
The usual theme, DPI, array, string, and labeling options apply to every state.
Format names are case-insensitive; an explicit filename does not select the
format. Use --format SVG -a when you need separate SVG files for every step.
The HTML shares identical SVG subtrees and mounts only the selected state. It contains the player code and needs no server or network resources, although fonts are not embedded. JavaScript is required for playback. The exporter still renders all states before sharing them, so this option does not promise faster generation or smaller files for every trace. It retains the complete shared sequence in memory for random access. This is a packaged version of the shared-sequence prototype.
Generate a fragment for direct inclusion in another HTML page:
code-visualizer Main.java --format HTML --html-fragment -o main.fragment.htmlInclude the fragment verbatim through your static-site template, server-side
include, or raw HTML facility. It contains one player host and its initialization
script, without document-level markup. --html-fragment requires --format HTML
and also works in batch mode. Each player mounts in its own Shadow DOM, isolating
SVG identifiers, styles, and controls from the page and other sequences. Multiple
fragments can coexist and navigate independently; an iframe is not required.
The player has compact wrapping controls, responsive SVG sizing, and print styles
that omit the controls. Its width follows its container. Generate with --theme
to choose the diagram palette; host CSS selectors do not cross the shadow boundary.
Fonts may still be substituted by the viewing browser.
The host must permit the included inline script and styles under its content
security policy and preserve them during sanitization. Insert fragments through
HTML parsing with script execution, such as a page template. Assigning a fragment
to innerHTML does not execute its script and will not initialize the player.
The complete document output remains suitable for opening directly in a browser.
code-visualizer Main.java --format SVG -o main.svg
code-visualizer Main.java --format SVG -a -o steps.svg
code-visualizer --batch --input-dir sources --format SVG --out-dir diagramsSVG exports contain editable text, shapes, and reference paths, with no embedded HTML or raster screenshots. Format names are case-insensitive. Single images, all execution steps, batch jobs, and the Python image APIs support SVG with the same array and labeling options as PNG.
The SVG uses the browser's diagram layout. --dpi 2 doubles its declared width and height while leaving the viewBox, geometry, and proportions unchanged. SVG text remains selectable and editable when opened directly in a browser or embedded inline in HTML. An HTML <img> displays the SVG as an image and does not allow selecting its internal text. Fonts are not embedded: browsers and Inkscape may substitute fonts, and unsupported glyphs such as emoji can differ or be absent. Text is fitted to the measured label bounds to preserve layout; exact glyph appearance is not guaranteed.
Each export includes an accessible summary and a full text description of the rendered state. The description lists stack frames and variables before heap objects, names reference targets, and lists each object once, including cycles and shared references. It follows the selected step and visible labels; hidden fields are omitted. The comparison gallery provides the same information in an expandable Text description panel with headings and lists. VoiceOver with Safari still requires manual acceptance testing.
Use .svg for explicit SVG output paths. An explicit -o path or custom pattern is used exactly as supplied; its extension does not select or override the encoding. See the SVG comparison gallery instructions for reproducible visual checks.
code-visualizer --batch Main.java Other.java --out-dir diagrams
code-visualizer --batch --input-dir sources --out-dir diagrams
code-visualizer --batch -i manifest.ndjson --out-dir diagrams --output-pattern '{id}.{step}.png'Each input is traced independently. Directory scans recurse through .java files and preserve paths relative to the scan root. Positional files retain their supplied parent path for templates. Absolute output paths bypass --out-dir; use relative inputs or an explicit pattern to keep outputs under that directory.
A manifest has one JSON object per nonblank line:
{"id":"lesson-one","source":"class Main { public static void main(String[] args) { int n = 1; System.out.println(n); } }"}Supported job fields are id, source, breakpoints (an array of line numbers), array_orientation, alternate_array_orientations, array_orientations, theme, and string_style. Omitted IDs use job_ plus the zero-based manifest line index. Empty or omitted breakpoints inherit CLI breakpoints. Array settings inherit CLI defaults; per-object maps merge with job entries taking precedence. A job’s theme overrides the CLI theme; an omitted field inherits it, while null restores the default host-adaptive behavior. Invalid theme or array settings reject the manifest before any job executes. A job’s string_style overrides the CLI choice; omission inherits it. Invalid string styles also reject the manifest before execution. Supply a manifest file: batch mode currently does not read a manifest from -i -.
--output-pattern controls batch image names and --trace-pattern saves intermediate trace JSON. Relative destinations are placed under --out-dir when supplied.
| Placeholder | Value |
|---|---|
{id} |
Manifest job ID or source stem. |
{dirname} |
Source parent directory; empty for manifest jobs. |
{filename} |
Source filename, including extension; empty for manifest jobs. |
{basename} |
Source stem, or job ID for manifest jobs. |
{ext} |
Source extension, usually java. |
{step} |
Image index, or final for a single image. |
{line} |
Source line prefixed with L; requires frame metadata. |
{format} |
Lowercase output format, or json for traces. |
The default image pattern is {dirname}/{basename}.{format}, or {dirname}/{basename}.{step}.{format} for all steps or CLI breakpoints. Thus --format SVG produces .svg filenames and the default PNG format still produces .png. Manifest jobs should use an explicit {id} pattern to distinguish programs.
code-visualizer --batch -a Main.java --out-dir diagrams \
--output-pattern '{basename}.step{step}.png' \
--trace-pattern '{basename}.json'Multiple images require {step} or {line} in the image pattern. Loops can repeat line numbers, so use {step} to distinguish occurrences. Duplicate destinations within a job are rejected even with --force. Use unique job IDs and patterns across jobs; --force permits later jobs to replace earlier files.
--workers Nconfigures tracer workers (default 1);--browsers Nconfigures the browser pool (default 2). The CLI currently iterates jobs in order; these settings do not promise parallel execution of all input files.--keep-goingattempts later jobs after a handled job failure. The command still exits unsuccessfully if any job fails.--forcepermits overwriting batch destinations. Without it, existing outputs cause a job failure.- Parent directories are created automatically. Outputs are staged beside their destinations and published using per-file atomic replacement. Publication failure rolls back earlier replacements within the job; this is not a crash-atomic transaction across files or jobs. Rollback errors report retained recovery backups.
| Symptom | Next step |
|---|---|
| Command not found | Run uv tool update-shell, restart the shell, and check the wheel installation. |
| Initial download failure | Check network access and retry. A verified tracer cache can work offline; an invalid cache cannot. |
| Browser startup failure | Check Chrome installation and driver compatibility; inspect the underlying Selenium error. |
| Missing selected state | Select an executable, reached source line, or render all steps to inspect the trace. |
| Existing batch destination | Choose another output directory or intentionally pass --force. |
| Repeated template destination | Include {step}; {line} alone is insufficient for loops. |
generate_trace < Main.java > trace.json
generate_visualization < trace.json > trace.png
list_breakpoints < Main.java
render_image < Main.java > rendered.png
render_html < trace.json > embed.htmlThese utilities have their own options and defaults; use each command's --help. For example, program input (--stdin or --stdin-file) is available through the lower-level tracing/rendering tools and Python APIs, not the unified CLI. HTML embedding and bundle options are described in the array guide.
Use --theme light, --theme dark, or --theme auto with code-visualizer, generate_visualization, render_image, or render_html.
code-visualizer Main.java --theme dark --format SVG -o main-dark.svg
code-visualizer Main.java --theme light -o main-light.png
code-visualizer Main.java --format SVG -o main-adaptive.svgWith no theme option, standalone exports use light colors and inline SVG markup follows an ancestor's data-theme attribute. Explicit light/dark choices override that attribute. Explicit Auto follows the system preference rather than the page's manual selection. Raster images retain the palette used at render time; use explicit light/dark choices for reproducible build output.
Batch mode accepts the same flag. A manifest job can override it with "theme": "light", "dark", or "auto". Omit the field to inherit the CLI choice; set it to null to restore the default host-adaptive choice. Invalid values reject the manifest before any job runs.
See the theme guide for light/dark examples, an inline HTML recipe, inactive-frame arrows, and Auto troubleshooting. See Python integration for the corresponding API options.
All rendering commands accept --string-style compact|default|inline, including
batch rendering and the lower-level image and HTML commands. For example:
code-visualizer Main.java --string-style compact --format SVG -o main.svgManifest jobs can set "string_style": "compact" independently. The deprecated
inline_strings job field maps true to inline and false to default; supplying
both job fields is an error. See the string style guide
for Python migration and legacy trace compatibility.