beetlebug

The ztcl program

This page has each form of the command line of ztcl: the subcommands, and each flag of the runner. It comes from the help texts of the program (ztcl --help and ztcl SUBCOMMAND --help), through tools/cli-doc.tcl.

A script gets no host access by default. --allow turns on capabilities, and Limits and Quick start tell how. A program with the name tclsh, tclsh9.1, or tclsh8.6 acts as tclsh: see Run as tclsh.

The runner and its flags

usage: ztcl [flags] script.tcl [flags] [script.tcl ...]
       ztcl --tclsh [flags] script.tcl [arguments]   the words after the script are its arguments
       ztcl version                                  the version (also --version)
       ztcl env [-json | NAME ...]                   the settings of the host and of the build
       ztcl code [SCRIPT | COMMAND ARG ...]          the tools of ztcl::code with short output
       ztcl debug [options] script.tcl               run with probes and write a report
       ztcl build [options] -o OUT script.tcl ...    make one program file from scripts
       ztcl compile [options] -o OUT ...             compile to WebAssembly
       ztcl bench [options] [FILE ...]               run benchmarks
       ztcl doc NAME | -all                          the synopsis and the options of a command
       ztcl bug [--print]                            start a bug report
A subcommand prints its own usage: ztcl SUBCOMMAND --help

Capabilities and limits:
  --allow LIST          turn on capabilities, such as file,channels,clock (default: none)
  --root DIR            keep file and channels inside DIR (default: the paths of the host)
  --net POLICY          the network policy of socket (default: loopback)
  --compute N           the compute limit, in compute units
  --mem BYTES           the memory limit
  --tensor-threads N    the most threads of one ztcl::tensor kernel (default: 1)
  --exec-allow A,B      the programs that exec can run
  --exec-allow-root A,B the files below the root folder that exec can run
  --exec-env NAME=VALUE one variable of the environment of each program (give it again for more)
  --exec-timeout MS     the longest run time of a pipeline (0: no limit)
  --threads N           the most threads
  --thread-compute N    the compute limit of one thread
  --thread-mem BYTES    the memory limit of one thread
  --threads-compute N   the compute limit of all threads
  --threads-mem BYTES   the memory limit of all threads
  --registry-allow K,K  the registry keys of ztcl::win::registry (Windows)
  --credential-allow S,S the services of ztcl::win::credential (Windows)
  --keychain-allow S,S  the services of ztcl::mac::keychain (macOS)
  --defaults-allow D,D  the domains of ztcl::mac::defaults (macOS)

The run:
  --tcl 8.6|9.1         the Tcl release that the script follows (default 9.1, or ZTCL_TCL)
  --tclsh               the next word is the script, and the words after it are its arguments
  --cwd DIR             with --tclsh and --root: the current folder, a folder below the root
  --library DIR         the value of tcl_library
  --keep-going          run each command of the file: an error does not stop the file
  --verbose             with --keep-going, print each error
  --time                print the run time of each script: the best run of --repeat
  --repeat N            run each script N times
  --report              print the compute units and the memory at the end

The collector and the JIT:
  --gc on|off           turn the collector on or off
  --gc-stress N         start a collection at each Nth allocation
  --no-jit              turn the JIT off
  --jit-threshold N     the calls of a proc before it compiles
  --no-jit-tier2        turn tier 2 off
  --jit-tier2-count N   the passes of a loop before tier 2 compiles it
  --jit-stats           print what compiled
  --jit-dump DIR        write the code of each compiled function to DIR
  --jit-aot-check       compare the code of tier 1 with the code of the AOT target
  --jit-stress N        the stress modes of the JIT, for its tests
  --jit-stress-alloc N  the number of the allocation of the compiler that fails first, for its tests

  --help, -h            print this text
  --version             print the version

Docs: https://beetlebug.org/ztcl/

ztcl debug

Run a script with probes, a debugger, or the MCP tools of an agent. See Debugging.

Use: ztcl debug [options] [runner options] script.tcl
     ztcl debug --mcp [runner options]
     ztcl debug --dap [runner options] [script.tcl]

Runs the script with probes and writes a report: the status, the
error with the stack and the locals, the probes, and the records.

  --probe SPEC, -p SPEC  adds a probe: the words of ztcl::probe add,
                         such as "-proc parse -line 4 -capture i"
  --explain              after an error, runs the script again with a
                         probe on each line of the proc of the error,
                         and gives the last changes of its variables
  --json                 writes the report as one JSON object
  --budget N             the most bytes of the report (default 4000)
  --detail PART          summary, stack, changes, records, or all
  --last N               the count of records (default 10)
  --record FILE          writes the inputs of the run to FILE: the
                         clock, the event loop, and each read of a
                         channel
  --replay FILE          runs again with the inputs of FILE, also
                         with new probes
  --who-set VAR          gives the last write of a global variable,
                         with its value, its time, and the stack
  --when VAR VALUE       gives the first write of VALUE to VAR
  --mcp                  serves the tools on stdin and stdout (MCP)
  --dap                  serves a debugger on stdin and stdout (DAP),
                         with breakpoints, steps, and the stack

ztcl build

Make one program file from scripts. See Build a program.

usage: ztcl build [--target T] [--runtime FILE] [--allow LIST] [--root PATH] [--no-jit]
                  [--tcl 8.6] [--compress] [--embed PATH]... -o OUT script.tcl...
       ztcl build --strip [--keep LIST] [--drop-module LIST] [--trust-scan] [--check] [--profile]
                  [--test FILE]... [--strip-manifest FILE] [--src DIR] [other options] -o OUT script.tcl...
       ztcl build --wasm [--base ztcl.wasm] [--tcl 8.6] [--embed PATH]... -o OUT.wasm script.tcl...
       ztcl build --component [--base ztcl.component.wasm] [--allow LIST] [--root PATH]
                  [--compress] [--embed PATH]... -o OUT.wasm script.tcl...

ztcl compile

Compile the procs of a script to WebAssembly. See WebAssembly.

usage: ztcl compile --wasm [--no-inline] [--runtime FILE] [--record FILE]... -o OUT [SCRIPT]...
usage: ztcl compile FILE -proc NAME -o OUT.wasm ?-simd on|off? ?-max-mem BYTES? ?-features a,b,...? ?-manifest FILE?

ztcl code

The tools of ztcl::code for a coding agent. See ztcl::code.

usage: ztcl code 'SCRIPT'         run the script and print each result
       ztcl code COMMAND ARG ...  run one command with the words as they are
       ztcl code                  run the script of stdin
       ztcl code claude ?OPT ...? ?-- ARG ...?
                                  run Claude Code in a harness, with each ARG for it
The commands:
grep PAT ?PATH..? ?-re -w -i -glob G -c N -n MAX -files?  search; literal unless -re
def NAME ?PATH..?  ?-show?    definitions of NAME (a.b = b inside a)
outline FILE ..   ?-full?     definitions with line ranges
show FILE ?A-B|A+N|A|-N|NAME ..?   lines with numbers
files ?PATH..? ?-glob G?      the files of the tree (git ls-files)
tree ?PATH? ?-depth N?        folders with counts of files
replace FILE OLD NEW ?-all?   change one exact text
edit FILE {OLD NEW ..}        several changes, all or none
lines FILE A B TEXT ?-expect T?   replace lines A-B (TEXT "" deletes)
insert FILE LINE|end TEXT     insert before LINE
write FILE TEXT               make or replace a file
sub OLD NEW ?PATH..? ?-re -w -i -glob G -dry?   change in many files
run ?-keep RE -c N -tail N -all -ask Q -cd DIR? CMD ..  run; short output, log
digest ?-q QUESTION? ?-words N? TEXT   ask a cheap model about TEXT
A change prints FILE:A-B +ADDED -REMOVED. A command error stops the script.

ztcl bench

Run the bench procs of *_bench.tcl files.

usage: ztcl bench ?runner flags? ?-run PATTERN? ?-count N? ?-time DURATION? ?-json? ?-compare OLD.json? ?FILE ...?

ztcl doc

Print the synopsis, the subcommands, and the options of a command.

usage: ztcl doc NAME | -all

ztcl env

Print the settings of the host and of the build.

usage: ztcl env ?-json | NAME ...?

ztcl bug

Start a bug report with the output of ztcl env.

usage: ztcl bug ?--print?

ztcl version

Print the version, the Tcl release, the target, and the build mode.

usage: ztcl version