Tcl — 128 Operations for AI Agents
Tcl runs the tooling behind chips and infrastructure: EDA flows, synthesis scripts, test automation. act101 exposes procs and namespaces as navigable structure, so agents work inside decades-old scripts with confidence.
This page is the canonical reference an AI coding agent uses to refactor, query, and analyze Tcl code through the act MCP server. 128 operations available: 54 refactor, 18 query, 42 analysis, 14 verification. Each operation is callable from Claude Code, Cursor, Codex, OpenCode, or any MCP-compatible agent host. Click any operation for a stable anchor link suitable for citation.
Premium language. Operations on Tcl require an Elite license or above. See pricing.
Worked Tcl examples
act101 parses Tcl with the tree-sitter grammar and edits proc bodies, command lines, and control structures as syntax nodes, so a rewritten mapping or a wrapped command lands on the exact lines it targets. It can replace a simple switch -- $value mapping of literal cases with an equivalent dict get lookup. It can wrap a single command line in a catch guard that returns the caught error with a Tcl error code. And it can extract a line range from inside a proc body into a new top-level proc, replacing the selected lines with a call to it. Each example below is the verbatim output of the command shown, run against the file shown.
Convert a switch mapping to a dict lookup
label.tcl's label proc maps code to a name through a switch -- $code with two literal cases.
$ act refactor-lang convert_switch_to_dict --file label.tcl --params '{"line":2,"column":1}'
Before
proc label {code} {
switch -- $code {
alpha {return Alpha}
beta {return Beta}
}
}
After
proc label {code} {
return [dict get {alpha Alpha beta Beta} $code]
}
The switch statement becomes a single return [dict get {alpha Alpha beta Beta} $code] expression.
Guard a command with catch
loader.tcl's loadScript proc calls source $path with no error handling.
$ act refactor-lang add_error_handling --file loader.tcl --params '{"line":2,"error_var":"err","column":1}'
Before
proc loadScript {path} {
source $path
}
After
proc loadScript {path} {
if {[catch {source $path} err]} {
return -code error $err
}
}
The source call is wrapped in if {[catch {...} err]}, returning the caught error with -code error.
Extract commands into a new proc
demo.tcl's demo proc builds a greeting and prints it before printing done.
$ act refactor-lang extract_proc --file demo.tcl --params '{"name":"announce","start_line":2,"end_line":3,"line":2,"column":1}'
Before
proc demo {} {
set greeting "Hello"
puts $greeting
puts done
}
After
proc demo {} {
announce
puts done
}
proc announce {} {
set greeting "Hello"
puts $greeting
}
The greeting-building lines move into a new announce proc; demo now calls announce in their place.
Query
18 query tools, the same on every supported language. Descriptions live in the shared reference: /docs/query-tools.
callers control_flow data_flow definition diagnostics effect_closure effect_summary fix_auto get_type graph import_organize interface mutations references repo_outline skeleton symbols symbols_batch
Refactor
| Operation | Description |
|---|---|
add-comment |
Add a Tcl comment before a proc |
add-default-parameter |
Add a default value to a Tcl proc parameter |
add-error-handling |
Wrap a Tcl command in a catch error guard |
add-namespace-export |
Add a Tcl proc to a namespace export command |
add-package-provide |
Add a Tcl package provide declaration |
add-parameter |
Add a Tcl proc parameter and update direct call sites |
convert-class-to-procs |
Convert TclOO methods into standalone Tcl procs |
convert-dict-to-switch |
Convert a simple Tcl dict get return to a switch mapping |
convert-global-to-namespace |
Convert a Tcl global declaration to a namespace variable declaration |
convert-namespace-to-global |
Convert a Tcl namespace variable declaration to a global declaration |
convert-regexp-to-string-match |
Convert a simple Tcl regexp command to string match |
convert-return-to-upvar |
Convert a simple Tcl return value to an upvar output assignment |
convert-string-match-to-regexp |
Convert a simple Tcl string match glob to regexp |
convert-switch-to-dict |
Convert a simple Tcl switch return mapping to dict get |
convert-to-tcloo-class |
Convert namespace-style Tcl procs into a TclOO class |
convert-upvar-to-return |
Convert a simple Tcl upvar output variable to a returned value |
extract-namespace |
Extract selected Tcl procs into a new namespace |
extract-proc |
Extract selected Tcl command lines into a new proc |
extract-to-package |
Extract selected Tcl procs into a package namespace |
extract-variable |
Extract a selected Tcl word or expression into a variable |
extract_function |
Extract a code selection into a new function — automatically infers parameters, return types, and inserts the call site. Use instead of manually cutting/pasting code. Works without LSP; LSP improves type inference. Params: file (string), new_name (string), start_line (u32), start_column (u32), end_line (u32), end_column (u32) [, preview (bool), receipt (bool)] |
extract_variable |
Extract an expression into a named variable — inserts the declaration and replaces the expression with the variable name. Works without LSP. Params: file (string), new_name (string), start_line (u32), start_column (u32), end_line (u32), end_column (u32) [, preview (bool)] |
fix-eval-to-expansion |
Replace a simple Tcl eval command with {*} expansion |
fix-incorrect-quoting |
Replace incorrect Tcl expression quotes with braces |
fix-missing-braces |
Add missing braces to a Tcl expression or condition |
fix-missing-namespace |
Qualify a bare Tcl command with a namespace path |
fix-undefined-variable |
Add a Tcl global or namespace variable declaration |
gen-arg-parser |
Generate Tcl command-line arg parser |
gen-cgi-handler |
Generate Tcl CGI handler scaffold |
gen-config-reader |
Generate Tcl config reader |
gen-logging-procedure |
Generate Tcl logging procedure |
gen-namespace-scaffold |
Generate a Tcl namespace scaffold |
gen-proc-scaffold |
Generate a Tcl proc scaffold |
gen-tcloo-class |
Generate a TclOO class scaffold |
gen-test-procedure |
Generate a Tcl tcltest test scaffold |
inline |
Inline a variable, function, or method — replace every usage with its definition body, then remove the original. The inverse of extract. Works without LSP (single-file); LSP enables cross-file inlining. Params: file (string), symbol (string) [, line (u32), preview (bool), receipt (bool)] |
inline-namespace |
Inline a Tcl namespace into the top-level scope |
inline-proc |
Inline a single-use no-argument Tcl proc at its direct call site |
inline-variable |
Inline a single-use Tcl variable assignment |
insert_body |
Replace a function's implementation body with new code. AST-validated — rejects if the result has parse errors, so you can't accidentally break syntax. Use instead of manual text editing for function rewrites. Params: file (string), symbol (string), code (string) [, commit (bool)] |
modernize-syntax |
Modernize selected Tcl syntax |
move_symbol |
Move a function, class, or type to a different file and automatically update all imports across the codebase. Use instead of manually cut/paste + fixing imports. Works without LSP (single-file); LSP enables cross-file import updates. Params: file (string), symbol (string), destination (string) [, preview (bool), receipt (bool)] |
organize-imports |
Sort and deduplicate top-level Tcl package requirements |
recipe_run |
Run a codemod recipe: declarative match → transform → optional verify across modeled grammars. Preview lists matches; apply writes with optional E7 receipts and all-or-nothing rollback. Returns a per-site report. |
remove-default-parameter |
Remove a default value from a Tcl proc parameter |
remove-error-handling |
Remove a simple Tcl catch error guard |
remove-namespace-export |
Remove a Tcl proc from a namespace export command |
remove-parameter |
Remove an unused Tcl proc parameter and matching direct call arguments |
rename |
Rename a symbol and automatically update ALL references across the codebase. Safer and faster than find-and-replace — AST-aware, won't rename strings or comments. Works without LSP (single-file); LSP enables cross-file renames. Params: file (string), old_name (string), new_name (string) [, line (u32), column (u32), preview (bool), receipt (bool)] |
rename-namespace |
Rename a Tcl namespace declaration and qualified same-file references |
rename-proc |
Rename a Tcl proc declaration and direct command call sites |
rename-variable |
Rename a Tcl variable in the selected proc or namespace scope |
reorder-parameters |
Reorder Tcl proc parameters and matching direct call arguments |
wrap-if |
Wrap selected Tcl command lines in an if block |
Analysis
42 analysis tools, the same on every supported language. Descriptions live in the shared reference: /docs/analysis-tools.
analyze_api_diff analyze_chokepoints analyze_clones analyze_clusters analyze_cohesion analyze_conformance analyze_coupling analyze_cycle_risk analyze_cycles analyze_dead_code analyze_depth analyze_entry_points analyze_export analyze_extraction analyze_fan_balance analyze_features analyze_hotspots analyze_impact analyze_inconsistencies analyze_inheritance analyze_interface_bloat analyze_interfaces analyze_layers analyze_orphan_types analyze_patterns analyze_platform_deps analyze_readiness analyze_roles analyze_seams analyze_stability analyze_surface analyze_test_gaps analyze_thickness analyze_type_completeness churn_hotspots co_change_clusters coverage_overlay ownership_map profile_overlay simulate split_module trace_overlay
Verify
14 verify tools, the same on every supported language. Descriptions live in the shared reference: /docs/verification.
bisect_regression gate generate_test_harness scan secret_surface summarize_pr taint_flow unsafe_surface verify_behavioral_equivalence verify_contract_preserved verify_diff_semantics verify_port_parity verify_side_effects verify_test_impact