AGENTS.md template for Node.js and TypeScript
A ready AGENTS.md for a Node.js service or library written in TypeScript. It pins down module format, the build and test commands, and the type-safety shortcuts agents take when a type gets hard.
# AGENTS.md A Node.js service written in TypeScript (ES modules), tested with Vitest. ## Commands - `npm run dev`: run with reload (tsx watch) - `npm run build`: compile to `dist/` with tsc - `npx tsc --noEmit`: type-check only - `npm test`: Vitest in run mode - `npm run lint`: ESLint ## Project structure - `src/index.ts`: entry point - `src/`: application code, grouped by domain rather than by file type - `test/`: tests that cross module boundaries; unit tests sit next to the code - `dist/`: build output. Never edit by hand ## Rules for agents - No `as any`, no `as unknown as T`. If a type is hard, narrow it or write the type. - This is an ES modules project: `import` only, and relative imports end in `.js`. - Never swallow an error. Handle it, or rethrow it with context. - Ask before adding a dependency. ## Conventions ### Node.js - Node 20+ features are fair game (top-level await, fetch, test runner). - ESM only for new code. If the repo is CJS, match it — don't mix. - Never block the event loop. Long work goes to workers or a queue. - Env vars via `process.env.X` — validate at startup (Zod or `envsafe`). Fail fast on missing config. ### TypeScript - Prefer `type` for object shapes, `interface` only when extending third-party types. - Never use `any` — use `unknown` and narrow, or write a proper type. - No non-null assertions (`!`) except in tests or when a type guard just ran. - Use `readonly` for props, return types, and array params that don't mutate. - Prefer discriminated unions over enums. Enums only for stable public APIs. - Import types with `import type { ... }` to avoid runtime import cost. ### Vitest - Co-locate test files (`*.test.ts`) with the code they test. - Prefer `describe` only when grouping helps. Flat tests are fine. - Mock at the boundary (network, fs, clock) — never mock the unit under test. ## Avoid - Declaration-merging global namespaces. - Using `Function`, `Object`, or `{}` as types. ## Guardrails - Never commit secrets, API keys, or credentials. If you spot one in a diff, stop and flag it. - Do not invent dependencies. If a package is not already in the manifest, confirm before adding it. - When a command fails, read the actual error. Do not retry blindly or bypass with `--force`. - Prefer editing existing files over creating new ones. - Run the tests and the linter before saying a task is done, and say what you ran.
The commands and folders are the common defaults for Node.js and TypeScript. Change them to match your project before you commit the file: an agent will run exactly what is written here.
How to use it
Save the file as AGENTS.md in the root of your repository and commit it. Then check each tool you use:
| Tool | What to do |
|---|---|
| Claude Code | Reads AGENTS.md only when no CLAUDE.md exists in or above the folder. If you have a CLAUDE.md, put @AGENTS.md on its first line. |
| Cursor | Reads AGENTS.md from the project root, in the desktop app and the terminal. In the app, rules in .cursor/rules must be .mdc files. The terminal reads only plain .md files there. |
| Codex | Reads AGENTS.md from the root down to the folder you are in, with a shared 32 KiB limit across all of them. |
| GitHub Copilot | Reads AGENTS.md on some surfaces only. Keep a .github/copilot-instructions.md as well if your team relies on Copilot. |
Details and sources: the AGENTS.md compatibility matrix.
What agents get wrong in Node.js and TypeScript projects
These are the reasons the “Rules for agents” section says what it says.
Casting instead of typing
When a type is awkward, agents write as any or as unknown as T and move on. The compiler goes quiet and the bug ships. The template bans it and tells them what to do instead.
CommonJS in an ESM project
Models mix require and import, or forget the .js extension that Node ESM needs on relative imports. State the module format once.
Swallowed errors
catch (e) {} and catch { return null } are an agent’s favourite way to make a failing test pass. The Guardrails section rules them out.
Unpinned new dependencies
Agents add a package for a ten-line job. The template makes them ask first.
Questions
Where does AGENTS.md go in a Node.js and TypeScript project?
In the root of the repository, next to your manifest file. Tools read it from the folder you start them in and, for most tools, from parent folders too.
Does Claude Code read AGENTS.md?
Only when there is no CLAUDE.md in or above the working folder. If you already have a CLAUDE.md, keep it and make its first line @AGENTS.md so both tools read the same rules.
How long should the file be?
Short enough that every line is something the agent would get wrong without it. Codex shares a 32 KiB budget across all the AGENTS.md files it loads, and long files get followed less closely by every tool.
Should a library and a service use the same file?
Mostly. For a library add a line about the public API: what is exported, and that changing it is a breaking change needing a version bump.