{
  "id": "agents-md-for-astro-static-site",
  "type": "rules",
  "category": "rules",
  "locale": "de",
  "url": "/de/rules/agents-md-for-astro-static-site",
  "title": "AGENTS.md-Regeln für eine statische Astro-Site",
  "description": "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.",
  "tools": [
    "Cursor",
    "Claude Code",
    "Codex",
    "Windsurf"
  ],
  "stack": [
    "Astro",
    "TypeScript",
    "Tailwind"
  ],
  "tags": [
    "agents-md",
    "astro",
    "typescript",
    "tailwind",
    "conventions",
    "seo"
  ],
  "difficulty": null,
  "updated": "2026-06-08",
  "markdown": "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.\n\n## AGENTS.md\n\n```md title=\"AGENTS.md\"\n# Project Rules — Astro Static Site\n\n## Stack\n- Astro 5 (static output, `output: \"static\"`). No SSR adapter unless explicitly requested.\n- TypeScript strict mode. All `.astro` component scripts are TypeScript.\n- Tailwind CSS v4. No CSS-in-JS. No inline `style` attributes unless value is truly dynamic.\n- Content managed via Astro Content Collections (Zod schemas in `src/content.config.ts`).\n\n## Hard rules\n- Never switch `output` to `\"server\"` or `\"hybrid\"` — this is a static build.\n- Never add `client:load` to a component that does not require browser interactivity.\n  Prefer `client:idle` or `client:visible` when a client directive is genuinely needed.\n- All content files live in `src/content/<collection>/`. Do not create ad-hoc markdown\n  files outside a defined collection.\n- Frontmatter must match the Zod schema in `src/content.config.ts`. Validate before\n  writing — wrong field names cause build failures, not runtime errors.\n- Images must go through Astro's `<Image />` component or `getImage()` helper.\n  Never use bare `<img>` tags — they bypass optimisation and break CLS scores.\n- Never read environment variables with `import.meta.env` inside a `.ts` utility that\n  may be imported on the client; mark those files with a `// server-only` comment and\n  import them only from `.astro` files or API endpoints.\n- Do not add a dependency without stating the reason. Prefer Astro-native solutions\n  (content collections, view transitions, image optimisation) before reaching for npm.\n\n## Conventions\n- Components live in `src/components/`. Page layouts live in `src/layouts/`.\n  One component per file; file name matches the exported component name.\n- Route pages live under `src/pages/`. Dynamic routes use bracket notation:\n  `src/pages/[slug].astro`. Static paths are generated via `getStaticPaths()`.\n- Shared TypeScript utilities live in `src/lib/`. Import with the `@/` alias\n  (configured in `tsconfig.json`).\n- Tailwind classes follow mobile-first order: base → `sm:` → `md:` → `lg:`.\n  No arbitrary values unless a design token does not exist.\n- Every page component must export a `<meta>` block via the layout that includes\n  `title`, `description`, and Open Graph tags.\n\n## SEO conventions\n- Every `src/pages/*.astro` page must render a canonical `<link rel=\"canonical\">`.\n- Blog / content pages must include `datePublished` and `dateModified` in\n  JSON-LD structured data.\n- Do not create two pages that share the same `<title>` or `<meta name=\"description\">`.\n\n## Definition of done\n- `astro check` passes with zero errors.\n- `astro build` completes without warnings.\n- Lighthouse performance score ≥ 90 on a representative page (run `unlighthouse`).\n- No new `any` types. No unused imports.\n- All new content frontmatter passes the Zod schema (`bun run typecheck`).\n```\n\n## Warum diese Regeln\n\n- **\"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.\n- **\"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.\n- **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.\n\n## Gut geeignet\n\n- Marketing-Seiten, Blogs, Dokumentationsseiten und SEO-fokussierte Content-Seiten, die mit Astro und einem festen statischen Ausgabeziel erstellt wurden.\n\n## Nicht geeignet\n\n- 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."
}