AGENTS.md template for Astro
A ready AGENTS.md for an Astro site with TypeScript. It covers pages, layouts and content collections, the commands that check a change, and the habit agents have of turning a static site into a JavaScript app.
# AGENTS.md An Astro site written in TypeScript and styled with Tailwind CSS. Static by default, with interactive islands only where needed. ## Commands - `npm run dev`: start the dev server on http://localhost:4321 - `npm run build`: build the site into `dist/` - `npm run preview`: serve the built site locally - `npx astro check`: type-check `.astro` files and content schemas ## Project structure - `src/pages/`: one file per route - `src/layouts/`: page shells - `src/components/`: `.astro` components and framework islands - `src/content/`: content collections (Markdown and MDX) - `src/content.config.ts`: collection schemas - `public/`: files served as-is ## Rules for agents - Ship no JavaScript by default. Add a `client:` directive only to a component that needs interaction, and prefer `client:visible` or `client:idle` over `client:load`. - Code between the `---` fences runs at build time or on the server. No hooks, state or event handlers in `.astro` files. - Read content through `getCollection` and `getEntry`. A new frontmatter field must be added to the collection schema first. - Never rename a secret to `PUBLIC_` to make it readable in the browser. ## Conventions ### Astro - Static by default. Add `client:load` / `client:visible` / `client:idle` only where interactivity is needed. - Content Collections (`src/content/`) for structured content — use Zod schemas. - Prefer Astro components for layout and static UI; reach for React/Vue/Svelte islands only when needed. ### 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 Astro. 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 Astro projects
These are the reasons the “Rules for agents” section says what it says.
Hydrating everything
Agents add client:load to every component they touch, and a site that shipped no JavaScript now ships a framework on every page. The template asks for the lightest directive that works, and none by default.
Treating .astro files like React
Hooks, state and onClick props do not work in an .astro component. The code between the fences runs once, at build time or on the server. Agents write React there and nothing happens in the browser.
Skipping the content schema
Agents read Markdown with import.meta.glob or add frontmatter fields the schema does not know. Then the build fails, or a field is silently dropped.
Leaking environment variables
Only variables prefixed PUBLIC_ reach the browser. An agent that needs a key in an island tends to rename the secret so it becomes readable.
Questions
Where does AGENTS.md go in a Astro 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.
Does this cover server-rendered Astro?
It assumes a static build. If you use an adapter and on-demand rendering, add a line naming the adapter and which routes are rendered per request, so the agent knows where cookies, redirects and request data are available.