# AGENTS.md-Regeln für eine statische Astro-Site

> Eine einsatzbereite AGENTS.md für statische Astro-Sites, die KI-Agenten im Stack hält, SSR-Abweichungen verhindert und Konventionen für Inhaltsammlungen durchsetzt.

**Type:** Rule  
**Tools:** Cursor, Claude Code, Codex, Windsurf  
**Stack:** Astro, TypeScript, Tailwind  
**Updated:** 2026-06-08

---

Fügen Sie diese Datei als `AGENTS.md` in Ihr Repo-Root ein. Astro-zielende Agenten (Cursor, Claude Code, Codex) lesen sie automatisch beim Start und verwenden sie, um bei jeder Codegenerierungssitzung die Konventionen einzuhalten.

## AGENTS.md

```md title="AGENTS.md"
# Project Rules — Astro Static Site

## Stack
- Astro 5 (static output, `output: "static"`). No SSR adapter unless explicitly requested.
- TypeScript strict mode. All `.astro` component scripts are TypeScript.
- Tailwind CSS v4. No CSS-in-JS. No inline `style` attributes unless value is truly dynamic.
- Content managed via Astro Content Collections (Zod schemas in `src/content.config.ts`).

## Hard rules
- Never switch `output` to `"server"` or `"hybrid"` — this is a static build.
- Never add `client:load` to a component that does not require browser interactivity.
  Prefer `client:idle` or `client:visible` when a client directive is genuinely needed.
- All content files live in `src/content/<collection>/`. Do not create ad-hoc markdown
  files outside a defined collection.
- Frontmatter must match the Zod schema in `src/content.config.ts`. Validate before
  writing — wrong field names cause build failures, not runtime errors.
- Images must go through Astro's `<Image />` component or `getImage()` helper.
  Never use bare `<img>` tags — they bypass optimisation and break CLS scores.
- Never read environment variables with `import.meta.env` inside a `.ts` utility that
  may be imported on the client; mark those files with a `// server-only` comment and
  import them only from `.astro` files or API endpoints.
- Do not add a dependency without stating the reason. Prefer Astro-native solutions
  (content collections, view transitions, image optimisation) before reaching for npm.

## Conventions
- Components live in `src/components/`. Page layouts live in `src/layouts/`.
  One component per file; file name matches the exported component name.
- Route pages live under `src/pages/`. Dynamic routes use bracket notation:
  `src/pages/[slug].astro`. Static paths are generated via `getStaticPaths()`.
- Shared TypeScript utilities live in `src/lib/`. Import with the `@/` alias
  (configured in `tsconfig.json`).
- Tailwind classes follow mobile-first order: base → `sm:` → `md:` → `lg:`.
  No arbitrary values unless a design token does not exist.
- Every page component must export a `<meta>` block via the layout that includes
  `title`, `description`, and Open Graph tags.

## SEO conventions
- Every `src/pages/*.astro` page must render a canonical `<link rel="canonical">`.
- Blog / content pages must include `datePublished` and `dateModified` in
  JSON-LD structured data.
- Do not create two pages that share the same `<title>` or `<meta name="description">`.

## Definition of done
- `astro check` passes with zero errors.
- `astro build` completes without warnings.
- Lighthouse performance score ≥ 90 on a representative page (run `unlighthouse`).
- No new `any` types. No unused imports.
- All new content frontmatter passes the Zod schema (`bun run typecheck`).
```

## Warum diese Regeln

- **"Nie zum Server-Modus wechseln"** ist die wirkungsvollste Regel für statische Astro-Sites. Agenten, die eine fehlende Funktion entdecken, schlagen häufig vor, schnell einen SSR-Adapter hinzuzufügen – dies ändert stillschweigend das Deployment-Ziel, unterbricht das CDN-Caching und fügt Kaltstart-Latenz hinzu. Die Regel zwingt Agenten, Probleme innerhalb des statischen Paradigmas zu lösen.
- **"Bilder müssen über `<Image />` eingebunden werden"** beseitigt den häufigsten KI-Fehler auf Content-Seiten: nackte `<img>`-Tags, die Core Web Vitals ruinieren. Astros Bild-Pipeline übernimmt Formatkonvertierung, responsives `srcset` und Lazy Loading automatisch – Agenten umgehen sie, wenn sie nicht explizit darauf hingewiesen werden.
- **Zod-Frontmatter-Validierung** fängt Schema-Inkonsistenzen zur Typüberprüfungszeit ab, anstatt zur Build-Zeit oder schlimmer, stillschweigend falsche Daten zu rendern. Agenten, die Markdown-Dateien schreiben, halluzinieren oft Frontmatter-Feldnamen.

## Gut geeignet

- Marketing-Seiten, Blogs, Dokumentationsseiten und SEO-fokussierte Content-Seiten, die mit Astro und einem festen statischen Ausgabeziel erstellt wurden.

## Nicht geeignet

- Astro-Projekte, die `output: "server"` oder `"hybrid"` mit einem Edge-/SSR-Adapter verwenden – diese benötigen ein anderes Regelwerk, das `client:load` und serverseitige Datenabrufmuster erlaubt.