AGENTS.md template for SvelteKit
A ready AGENTS.md for a SvelteKit app on Svelte 5 with TypeScript. It tells coding agents where data loading and server code go, which commands prove a change works, and the Svelte 4 syntax they keep writing.
# AGENTS.md A SvelteKit app on Svelte 5 (runes) written in TypeScript and styled with Tailwind CSS. ## Commands - `npm run dev`: start the dev server on http://localhost:5173 - `npm run build`: production build - `npm run check`: `svelte-check`: type and template errors. Run this before saying a change is done - `npm run lint`: Prettier and ESLint checks - `npm test`: run the test suite ## Project structure - `src/routes/`: pages and endpoints. `+page.svelte`, `+page.server.ts`, `+layout.svelte`, `+server.ts` - `src/lib/`: shared components and helpers, imported as `$lib/...` - `src/lib/server/`: server-only code. Cannot be imported by client code - `src/hooks.server.ts`: request hooks: auth, session, headers - `static/`: files served as-is ## Rules for agents - This project uses Svelte 5 runes: `$state`, `$derived`, `$props`, `$effect` and `onclick`. Do not write `export let`, `$:` or `on:click`. - Load data in a `load` function, never with `fetch` in the component script or `onMount`. - Secrets come from `$env/static/private` and are used only in `+page.server.ts`, `+server.ts`, hooks or `$lib/server/`. - Forms that change data use form actions with `use:enhance`. Do not add a `+server.ts` endpoint for a form post. ## Conventions ### SvelteKit - Load data in `+page.server.ts` / `+page.ts` — never fetch in the component `<script>` block. - Form actions for mutations. Use progressive enhancement (`use:enhance`). - Stores (`writable`, `readable`) for shared state; prefer `$state` runes in Svelte 5. - Put server-only code in `$lib/server/` so it can't leak to the client bundle. ### 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. ### Tailwind CSS - Use utility classes; extract to a component only when a class list repeats 3+ times. - Use design tokens (`tailwind.config.ts`) — no magic `#hex` values in markup. - Use `clsx` / `cn()` for conditional classes. Don't build class strings with template literals. - Prefer `@apply` in global CSS only for truly reused primitives (buttons, inputs). ## 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 SvelteKit. 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 SvelteKit projects
These are the reasons the “Rules for agents” section says what it says.
Writing Svelte 4 syntax
Agents still write export let, $: and on:click. In a runes project that mixes two reactivity models in one codebase, and some of it fails to compile. The template names the Svelte 5 forms to use.
Fetching data in the component
A fetch inside the component script or onMount skips server rendering and shows an empty page first. Data belongs in a load function.
Leaking secrets to the browser
A universal +page.ts load runs in the browser too. Agents read a private key there, or import a server module into a component. The template keeps secrets in $env/static/private and $lib/server/.
Building API routes for form posts
Agents write a +server.ts endpoint and a client-side fetch for every form. A form action does the same job with less code and works without JavaScript.
Questions
Where does AGENTS.md go in a SvelteKit 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.
My project is still on Svelte 4. Can I use this?
Yes, with one change. Replace the runes rule with a line saying the project uses Svelte 4 syntax and must not be migrated file by file. What matters is that the file names one version, so the agent stops mixing them.