Safely move TypeScript files and folders — and keep your imports working.
tsmv src/Button.tsx src/components/Every file that imported Button is repointed to its new location, the moved
file's own relative imports are recomputed, and (by default) relative imports are
converted to absolute alias imports using your tsconfig.json.
- Move, rename, and reorganize single files, multiple files, or whole
directories (
-r). - Updates inbound imports — every importer of a moved file is rewritten.
- Recomputes the moved file's own imports for its new location.
- Real parser, not regex — handles static imports/exports, side-effect
imports, dynamic
import(),require(), andjest/vimocks, and never touches import-looking text in comments or strings. - Absolute-import conversion driven by
tsconfig.jsonbaseUrl/paths(toggle with--no-absolute-imports). - Dry-run (
-n) to preview every change before touching disk. - Circular-dependency warnings and empty-directory cleanup.
- Shell completions for bash, zsh, fish, elvish, and PowerShell.
- Single static binary, no Node.js runtime required.
sh -c "$(curl -fsSL https://raw.githubusercontent.com/avidianity/tsmv/master/install.sh)"This downloads the right prebuilt binary for your platform, verifies its
SHA-256 checksum, and installs it to ~/.local/bin. Override the location with
TSMV_INSTALL_DIR, or pin a version with TSMV_VERSION=v1.0.0.
cargo install --path .
# or build a release binary:
cargo build --release # → target/release/tsmvPrefer to do it by hand? Download the archive for your platform from the
Releases page (Linux, macOS, and
Windows, with SHA-256 checksums), unpack it, and put tsmv on your PATH.
tsmv self-update # replace the running binary with the latest release
tsmv self-uninstall # remove the installed binary (asks first; -y to skip)# Move a file into a folder and fix all imports
tsmv src/Button.tsx src/components/
# Rename a file (destination ends in a TS/JS extension)
tsmv src/utils.ts src/helpers.ts
# Move a directory recursively, preserving its structure
tsmv -r src/legacy src/modern/
# Preview the plan without changing anything
tsmv --dry-run -r src/legacy src/modern/
# Move but keep imports relative
tsmv --no-absolute-imports src/Button.tsx src/components/The last argument is always the destination; everything before it is a source.
-
usage.md — full usage guide: every flag, behaviour, and example.
-
usage.llm.md — the same reference, condensed and structured for LLM/agent consumption. Print it straight from the binary:
tsmv --usage-llm
tsmv is designed to be scriptable by LLMs and coding agents. Ship the
structured reference doc into the agent's context so it can construct correct
commands without guessing:
tsmv --usage-llmThis prints usage.llm.md — a condensed, machine-oriented reference with:
- Exact invocation grammar and flag table
- Semantic invariants (rename vs. move, inbound vs. self-rewrite rules)
- Every supported specifier form and what is deliberately not rewritten
- Decision rules for common agent scenarios (dry-run first, when to add
-r/-f/--no-absolute-imports, etc.) - Command → outcome examples
How to wire it into your agent: pipe tsmv --usage-llm into the system
prompt or a tool description whenever tsmv is available in the environment.
If the binary isn't installed yet, read usage.llm.md directly from the repo.
The doc is self-contained — no other files are needed to use tsmv correctly.
- Discover the source files (expanding directories with
-r, filtered by--extensions). - Plan destinations — directory moves preserve structure; a single source onto a
.ts/.tsx/.js/.jsxpath is a rename. - Move the files on disk.
- Rewrite inbound imports across the project, then recompute the moved files' own relative imports.
- Optionally convert relative imports to absolute alias imports via
tsconfig. - Clean up emptied directories and warn on circular dependencies.
Module references are found by parsing each file with a real TypeScript/TSX
grammar (tree-sitter) — not regular
expressions. That means look-alike text in comments and strings is never
touched, and dynamic import(), require(), and jest/vi mock calls are
rewritten just like static imports. The only specifiers left alone are those
whose path is computed at runtime (a variable or interpolated template literal);
see Notes.
GNU Affero General Public License v3.0 (AGPL-3.0-only).