# astro

Guidelines for Claude Code to generate server-side pages and endpoints in Astro. Ensures type safety, middleware handling, and request validation.

- rule · `type=rule` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline · ★ 267 repo stars
- Author: przeprogramowani
- License: AGPL-3.0 · policy=link-only · description only; the file stays with the author
- Source: https://github.com/przeprogramowani/ai-rules-builder/tree/HEAD/.cursor/rules/astro.mdc
- Updated: 2026-02-20
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/rules/przeprogramowani-astro

## What it does

This rule teaches Claude Code how to structure Astro projects with hybrid rendering and server-side endpoints. The assistant enforces uppercase method names such as `GET` and `POST`, marks API handlers with `export const prerender = false`, and verifies incoming payloads using Zod schemas.

Content collections receive strict TypeScript schemas for documentation or blog posts. Environment flags read from `import.meta.env`, while cookie operations route through `Astro.cookies`. For unprotected routes, the assistant must edit `src/middleware/index.ts` so anonymous traffic does not get blocked.

## Install

### Cursor (native platform)

**Manually: put the files in place**
- File: `.cursor/rules/astro.mdc` — Frontmatter: description, globs, alwaysApply

### Claude Code

**Manually: put the files in place**
- File: `.claude/rules/astro.md` — The paths frontmatter field limits the files: move globs from the source into paths

### Codex

**AGENTS.md**
- Codex reads AGENTS.md: paste the rule text there

### GitHub Copilot

**Manually: put the files in place**
- File: `.github/instructions/astro.instructions.md` — The applyTo field sets which files it applies to: move globs from the source into applyTo

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/rules/astro.md`

### Cline

**Manually: put the files in place**
- File: `.clinerules/astro.md`

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/przeprogramowani/ai-rules-builder/tree/HEAD/.cursor/rules/astro.mdc

## When to use it
- validate API route payloads using Zod schemas
- configure server endpoints with disabled prerendering
- build type-safe content collections for markdown articles
- read and write server cookies with `Astro.cookies`

## Example prompts
- Create a POST server endpoint to accept feedback with Zod schema validation.
- Set up a type-safe content collection for the documentation section.
- Update `src/middleware/index.ts` to allow anonymous access to the landing page.

## Similar
- [astro-sites-manager](https://affpapa.org/en/nevibecode/skills/astro-sites-manager.md) — skill · ★ 141 repo stars
- [clerk-astro-patterns](https://affpapa.org/en/nevibecode/skills/clerk-astro-patterns.md) — skill · 15000 installs
- [integration-astro-ssr](https://affpapa.org/en/nevibecode/skills/integration-astro-ssr.md) — skill · 109 installs
- [astro-framework](https://affpapa.org/en/nevibecode/skills/astro-framework.md) — skill · 2200 installs
- [astro-expert](https://affpapa.org/en/nevibecode/agents/astro-expert.md) — subagent · ★ 1029 repo stars
- [custom-pages-and-apis](https://affpapa.org/en/nevibecode/skills/custom-pages-and-apis.md) — skill · 488 installs

## Other versions with the same name
- [astro · github](https://affpapa.org/en/nevibecode/rules/astro.md) — ★ 41430 repo stars
- [astro · sanjeed5](https://affpapa.org/en/nevibecode/rules/sanjeed5-astro.md) — ★ 3589 repo stars

From the same set: [przeprogramowani/ai-rules-builder](https://affpapa.org/en/nevibecode/by/przeprogramowani/ai-rules-builder.md) — 24 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
