# tsx — card for AI agents

Node.js enhanced with esbuild to run TypeScript and ESM files.

Category: Languages, types and runtimes · npm package `tsx` · latest version 4.23.15 (checked 2026-11-01)
Install: `npm install tsx`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (paste into AGENTS.md or CLAUDE.md)

## tsx
- Run TypeScript files with `tsx file.ts` wherever you would use `node file.js`. Node CLI flags such as `--env-file=.env` pass through.
- Install it as a project dev dependency (`npm install -D tsx`, `pnpm add -D tsx` or `yarn add -D tsx`).
- Inside `package.json#scripts`, call `tsx` directly without `npx`, for example `"start": "tsx ./file.ts"`.
- For a one-off run without installing, use `npx tsx ./script.ts`.
- Use a maintained Node.js version. The docs say tsx targets all maintained versions, and loading ESM from CommonJS works only "on supported Node.js versions".
- When an ES module imports a CommonJS package, Node.js module semantics still apply. Check the tsx FAQ before working around legacy packages with incompatible default exports.
- Don't run `yarn global add` with Yarn 2. The docs note that Yarn 2 doesn't support global installation.

## What it is
- tsx (TypeScript Execute) runs TypeScript files in Node.js. The website calls it "a Node.js enhancement to run TypeScript" and tells newcomers to "think of tsx as an alias to `node`". You run `tsx file.ts` where you would have run `node file.js`. Node CLI flags and plain JS files work too. The repository was created on 2022-03-15 and is MIT licensed.
- The site says the idea came while the Node.js ecosystem was fragmenting over ES Modules, and projects "struggled to reconcile their CommonJS apps with ESM dependencies." It says ts-node "lacked ESM support and was quite complicated to use." The authors had seen several open-source tools using esbuild to run TypeScript in Node.js and brought those efforts into one project. The site lists CommonJS and ESM support, `tsconfig.json` paths and a Watch mode.
- The getting-started docs say tsx is designed to work with all maintained Node.js versions. Once it is a project dependency, scripts in `package.json` can call it directly without `npx`, as in `"start": "tsx ./file.ts"`.

## Caveats
- ESM importing CommonJS is not smoothed over: The ESM help covers CommonJS loading ESM. The site says Node.js module semantics still apply when an ES module imports CommonJS. For legacy packages with incompatible default exports, it points to the FAQ.
- Loader flag depends on Node version: Mehul Kar's post is inconsistent about Node 18. One passage says `--loader` does not work there but `--import` does. Another says `--import tsx` doesn't work in Node 18 and that he just bumped to Node 20. His working setup is pinned to Node v20.11.1 and tsx@4.7.2, and he notes that versions matter more in nascent technology.

## Numbers (AgentGid data)
- Gid Score: 84.2 (#45 of all tools, 2 of 70 in its category)
- Used in 953 public projects set up for AI coding agents (15.2%)
- Downloads last week: 146,175,969 (as of 2026-11-24), +45.4% over 4 weeks
- GitHub stars: 12,219 (as of 2026-11-24)
- Last push: 2026-09-25

## Often used with
TypeScript 95.3%, Zod 58.2%, dotenv 44.8%, Vitest 51.5%, React 50.8%, ESLint 53.4%

## Checked alternatives (same job)
- ts-node: https://agentgid.com/tools/ts-node/agent.md
- jiti: https://agentgid.com/tools/jiti/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/tsx/
- Homepage: https://tsx.hirok.io
- Repository: https://github.com/privatenumber/tsx
- Source: https://github.com/privatenumber/tsx
- Source: https://github.com/privatenumber/tsx/releases
- Source: https://tsx.hirok.io
- Source: https://tsx.hirok.io/getting-started


## tsx: run TypeScript files without a build step

tsx is a free command that runs TypeScript files directly with Node.js, the same way node runs JavaScript. Your assistant can write a script, a small server or a test in TypeScript and run it at once, with no separate build step. It does not check types; that stays a separate step.

### Where to use it
- Run a one-off TypeScript script: Your assistant writes a script that fills a test database or exports orders to a spreadsheet, and runs it at once with one command.
- Restart the app on every save: While you work on a small server or bot, it reruns by itself each time a file changes.
- Test TypeScript with Node's runner: Tests written in TypeScript run with Node.js's own test runner, with no extra test framework.
- TypeScript config files in your tool: People who use your tool or plugin system write its settings file in TypeScript, and your tool loads it.
- A small backend without a build: A small internal app runs from its TypeScript files on the server, if tsx is installed there as a normal package.
- Run a local helper for your AI assistant: A small TypeScript helper, such as a local tool server your assistant connects to, starts with one tsx command. (idea, not from the official pages)

### How to start
- Install tsx in your project as a development package.

```
npm install -D tsx
```

- Run a TypeScript file where you would run node.

```
npx tsx ./script.ts
```

- Check types separately with the TypeScript compiler.

```
npx tsc --noEmit
```


### License
Free to use in any product, paid or closed, under the MIT license. Keep the copyright and license notice with copies of its files.

### Good to know
- It does not check types. Code with type errors still runs, so add a separate check before you ship.
- The package installs on Node.js 18 and newer, but some features need Node.js 20.6 or newer.
- Watch mode ignores hidden files such as .env and anything in node_modules unless you include them.
- Newer Node.js versions run simple TypeScript on their own, but stop at enums and ignore tsconfig.json; tsx handles both.
- Libraries and command-line tools you publish for others should be built to JavaScript first, so their users do not need tsx.

Checked 2026-11-11 against: https://tsx.hirok.io/, https://tsx.hirok.io/getting-started, https://tsx.hirok.io/installation, https://tsx.hirok.io/compatibility, https://tsx.hirok.io/node-enhancement, https://tsx.hirok.io/watch-mode, https://tsx.hirok.io/testing, https://tsx.hirok.io/typescript, https://tsx.hirok.io/modules, https://tsx.hirok.io/compilation, https://tsx.hirok.io/dev-api/, https://tsx.hirok.io/faq, https://github.com/privatenumber/tsx/blob/master/README.md, https://github.com/privatenumber/tsx/blob/master/LICENSE, https://nodejs.org/api/typescript.html, https://registry.npmjs.org/tsx, https://registry.npmjs.org/tsx/4.23.15

### Mistakes to avoid
- Don't: Treating "it ran with tsx" as "the types are correct" → Do: Add "type-check" with tsc (noEmit) to package.json scripts and run it in CI or before commits (tsx strips types without checking them; in our run const seats: number = 'three' ran and printed three.)
- Don't: Replacing tsx with plain node file.ts on Node.js 22.18+ or 24 for code with enums or tsconfig paths → Do: Keep tsx for such code, or rewrite it to erasable syntax only (no enums, no namespaces with code, no paths) (Node's built-in type stripping errors on enums; in our run Node.js 24.22.2 failed with ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX: TypeScript enum is not supported in strip-only mode.)
- Don't: npx tsx ./file.ts --tsconfig ./tsconfig.custom.json (tsx flags after the file) → Do: npx tsx --tsconfig ./tsconfig.custom.json ./file.ts --name Ada (Everything after the file path goes to your script, not to tsx or Node.js.)
- Don't: Top-level await in a .ts file of a package without "type" "module" → Do: Rename the file to .mts or set "type" "module" in package.json; or wrap the code in an async function (Top-level await needs ES module mode, and the import syntax alone does not choose it.)
- Don't: Installing tsx with -D and starting the production server with tsx after npm ci --omit=dev → Do: Install tsx as a normal dependency for that server, or build to JavaScript and run node on the output (Production installs that skip development packages will not have tsx.)

### Questions
- Does it check my types? No. Run tsc --noEmit separately; in our run a file assigning a word to a number still ran.
- Node.js can run .ts files now. Do I still need tsx? Node.js only strips types; enums, namespaces with code and tsconfig paths fail there. In our run Node.js 24 stopped at an enum that tsx ran.
- Can I use it in production? Yes, if tsx is installed as a normal package there; the other option is to build JavaScript first and run that.
- How is it different from ts-node? tsx uses esbuild and needs no TypeScript compiler to run code; ts-node uses the compiler and can check types while it runs.
- Can I use it in a paid product? Yes. tsx is under the MIT license.

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
