ztcl
Modern Tcl for the AI era. ztcl is an alternative implementation of Tcl in Zig, built to be the fastest and most complete one. It runs Tcl 9.1 scripts, and Tcl 8.6 scripts with --tcl 8.6, with exact compute and memory limits, a JIT compiler that is on by default, real threads, microVM isolation, and a WebAssembly build for the browser. The current release is 1.0.0-beta.1.
Docs: https://beetlebug.org/ztcl/ · Playground: https://beetlebug.org/ztcl/playground/
- Designed with AI in mind.
ztcl::agentruns an LLM agent loop in an isolated thread with tools that are Tcl commands. A thread can run in its own microVM.ztcl debugserves MCP tools to an agent. - Measured on real tasks. On 9 real-world tasks, ztcl is 1.8 times as fast as
tclsh8.6.16 at the median, and slower on one (base64 end to end). It is faster than Python 3.14 on 6 of 11 tasks, and slower on base64, CSV, a regex over a web log, and word frequency. Go is faster on 7 of 11, and Zig on all 11. bench/compare has the programs, and Performance has the charts. A 50 times speedup overtclshholds only for a narrow micro benchmark: an integer loop in one proc. - Safe by default. A script has no file, socket, or process access until your program turns on a capability. The compute limit and the memory cap are exact.
- Small. One static binary. Its one dependency outside the Zig standard library is libghostty-vt, which the build compiles from source into the binary for
ztcl::vt. - Portable. Linux, macOS, Windows, WebAssembly in the browser, and Node.js.
- One binary for your program.
ztcl buildputs the runtime and your scripts in one static binary for Linux, macOS, or Windows. - Made for code from an agent. The Learn course teaches Tcl to review agent code, and the command reference and its
api.jsongive an agent each synopsis, error, and capability.
Coming, each in an open issue: the isolation levels wasm and vm-confidential for threads (#209), ztcl as a host of wasm modules (#202), and https and an HTTP/2 server (#27).
Install
brew install beetlebugorg/tap/ztcl # macOS and Linux
npm install @beetlebug/ztcl # WebAssembly, for the browser and Node.js
Install has the release binaries and the build from source.
Example
proc fib {n} {
if {$n < 2} { return $n }
expr {[fib [expr {$n - 1}]] + [fib [expr {$n - 2}]]}
}
puts [fib 20]
$ ztcl fib.tcl
6765
$ ztcl --compute 1000 fib.tcl
fib.tcl:2: compute limit reached
Documentation
- Quick start and the language
- Limits and capabilities, threads, and the JIT
- Isolated threads, Linux guests with
ztcl::vm, and sandboxed agents - Debugging, Tcl 9.1 and Tcl 8.6, and TLS 1.3
- Build a program: one native binary for Linux, macOS, or Windows, from any host, with
ztcl build - Strip a program: a runtime with only the commands, capabilities, and modules that the scripts use, with
ztcl build --strip - Embed in Zig and WebAssembly
- libztcl: build C programs and Tcl extensions against ztcl, as libtcl8.6
- Performance and the FAQ
- For contributors: docs/dev/ has the plans, the task lists, and the test results.
Status
ztcl is experimental, and its APIs can change in any release. It passes 38,054 of the 47,133 tests of the Tcl 8.6.16 suite, so it is not yet a drop-in replacement for Tcl. The code and the docs were written largely with AI coding agents, under human direction. Review the code before you depend on it. The issues and the milestones have the roadmap.
Contact
Write to opensource@beetlebug.org about ztcl. Open an issue for a bug or a request, and report a security problem as SECURITY.md says.
License
BSD-2-Clause. See LICENSE. References credits Tcl and the other sources.