anvil init to scaffold a new Anvil project, or add Anvil to an existing one. It writes package.json (creating or merging into an existing file), tsconfig.json, .gitignore, and a starter route or two from a template you choose.
Usage
dir is the target directory. Defaults to the current directory. It’s created if it doesn’t exist.
Flags
Template to scaffold:
basic, mcp, or agent. Skips the interactive prompt.Skip the interactive prompt without specifying
--template — defaults to the basic template. Useful for scripting and CI.--template or --yes, and when stdin is a TTY, anvil init prompts you to pick a template interactively.
Templates
basic
A minimal REST API: one static route and one dynamic
[id] route.mcp
The same routes, with the dynamic route exposed as an MCP tool, plus a standalone tool in
server/tools/.agent
A streaming agent route at
/chat using MockDriver, so it runs immediately with no API key.What it writes
package.json
If one doesn’t exist, creates a minimal one with
"type": "module". If one exists, it’s merged, not overwritten: type is forced to "module" (Anvil is ESM-only), the dev/build/start/lint scripts are added (your existing scripts are preserved and take precedence on name conflicts), and anvil/zod are added to dependencies — without clobbering a version you’ve already pinned for either.Example: non-interactive, for scripting
Example: adding Anvil to an existing project
Runanvil init in a directory that already has a package.json — it merges in the Anvil scripts and dependency instead of creating a new project:
anvil init only writes files — it does not run npm install for you, and it doesn’t assume a package manager. Run npm install (or your equivalent) yourself afterward.