ast_edit is the first AI coding tool to edit TypeScript and JavaScript through the AST instead of text matching. It addresses symbols by kind and name, mutates them structurally, and writes the result back. Micro-edits cost a handful of tokens and never fail on whitespace.
You don’t invoke ast_edit directly. The agent picks it automatically for TypeScript and JavaScript files. This page is a reference for what it can do.
Origin
The AST-first approach comes from my own Master’s thesis in Computer Science, Typed vs Untyped Programming Languages (co-authored with Artur Matusiak, 2022), and its reference implementation JS Typer. The thesis demonstrated that programmatic JavaScript-to-TypeScript conversion could be done entirely through ts-morph AST mutations rather than string manipulation.ast_edit is the direct descendant of that work, applied to AI coding.
Examples
Change a function’s return type:Targets
| Target | Addressed by |
|---|---|
function, class, interface, type, enum, variable, constant | name |
method, property | "ClassName.member" or "member" |
arrow_function | name (targets const fn = () => {}) |
constructor | ClassName |
Action reference
Tier 1 — Micro-edits (1-10 tokens)
Tier 1 — Micro-edits (1-10 tokens)
| Action | Effect |
|---|---|
set_type | Variable/property/parameter type annotation |
set_return_type | Function return type |
set_initializer / remove_initializer | Variable initializer |
set_value | Enum member value |
set_async / set_generator | Toggle async / function* |
set_export / set_default_export | Toggle export modifiers |
set_abstract / set_static / set_readonly / set_scope / set_optional / set_overrides / set_ambient | Class-member modifiers |
set_const_enum / set_declaration_kind | Misc modifiers |
rename | Declaration-only rename |
remove | Delete the declaration |
add_parameter / remove_parameter | Function/method parameters |
Tier 2 — Body surgery (10-100 tokens)
Tier 2 — Body surgery (10-100 tokens)
| Action | Effect |
|---|---|
set_body | Replace function/method body |
add_statement / insert_statement / remove_statement | Statement-level |
add_property / remove_property | Interface/class properties |
add_method / remove_method / add_constructor / add_getter / add_setter | Class members |
add_member / remove_member | Enum / type-literal members |
add_decorator / remove_decorator | Decorators |
add_overload | Function overload signatures |
set_extends / add_extends / remove_extends / add_implements / remove_implements | Inheritance |
add_type_parameter | Generic type parameters |
add_jsdoc / remove_jsdoc | JSDoc blocks |
unwrap, set_structure, extract_interface | Structural rewrites |
Tier 3 — Full replacement
Tier 3 — Full replacement
| Action | Effect |
|---|---|
replace | Replace a whole symbol |
replace_in_body | AST-anchored substring replace (unique match only) |
File-level
File-level
| Action | Effect |
|---|---|
create_file | New file (pass newCode as content) |
add_import / remove_import / add_named_import / remove_named_import | Imports |
set_module_specifier | Change import path |
add_export_declaration / add_named_reexport | Re-exports |
add_namespace | Namespace declarations |
organize_imports / fix_missing_imports / fix_unused | Cleanup |
add_function / add_class / add_interface / add_type_alias / add_enum / add_variable | Append top-level declarations |
insert_text | Insert at an anchor ("after-imports", "before-exports", index) |
Supported files
.ts, .tsx, .js, .jsx, .mts, .cts, .mjs, .cjs. For other files the agent falls back to edit_file / multi_edit.
Safety
- File snapshotted before the edit — rejects if changed on disk mid-flight.
- Atomic batches: all or none.
undo_editreversesast_editthe same asedit_file.- Pre/post diagnostics — new type errors flow back to the agent immediately.

