Guides

How to Build an Astro Website with Codex

A practical Codex and Astro workflow built around AGENTS.md, bounded implementation tasks, static output, validation, and reviewable evidence.

Codex works best when the repository has opinions

Codex can inspect files, make edits, and run project commands. In an Astro codebase, that means it can move from content schema to component to built HTML without leaving the implementation context.

Do not confuse that range with a reason to assign the entire website as one task. The useful pattern is staged autonomy. Give Codex enough authority to finish a bounded change, and put hard boundaries around commercial facts, credentials, deployment, design direction, and architecture changes whose effects spread beyond the task.

The repository should carry those boundaries before work begins.

Build an AGENTS.md instruction chain

Codex reads AGENTS.md files as project guidance. Instructions can exist at broader and narrower levels, with files closer to the working directory refining the rules for that area.

Use the root file for rules that apply across the site:

# Website contract

## Architecture
- Preserve Astro static output.
- Add no database, SSR adapter, or client framework without approval.

## Design
- Reuse existing tokens, containers, and primitives.
- A missing editorial pattern must extend the current system.

## Content
- Use American English.
- Do not invent evidence, customer claims, prices, or authors.

## Completion
- Run the repository's check, content validation, and production build.
- Report changed files, results, and unresolved caveats.

If the editorial directory needs more detailed sourcing and index rules, place another AGENTS.md there. Keep instructions relevant to their scope. A giant root file that explains every possible task makes the critical rules harder to find.

The AGENTS.md website-development article covers precedence, task routing, and the difference between durable instructions and a one-off prompt.

Confirm which instructions actually apply

Instruction scope matters in a repository with nested projects. Before a substantial change, ask Codex to name the applicable AGENTS.md chain for the files it expects to touch. A root rule can define static output and release safety, while src/content/AGENTS.md can define sources, voice, and index thresholds. The closer file refines that part of the tree.

Keep mandatory commands and prohibitions near the beginning. Use links to detailed documentation for editorial rationale and design examples. Codex has a finite project-instruction budget; duplicating a long handbook across nested files wastes it and makes conflicts harder to diagnose.

Test the instruction system with a small request. Ask Codex to summarize the applicable rules for one content file and one shared component without editing. If it misses a boundary, fix the hierarchy before trusting it with a large batch.

Let Codex inspect before it proposes

A production task should begin with directed reconnaissance. Ask Codex to inspect package.json, Astro configuration, content collections, layouts, global styles, design tokens, current routes, deployment files, and validation scripts. It should summarize the existing conventions and identify uncertainty before changing shared code.

This prevents a common failure mode: implementing a reasonable generic Astro pattern that ignores the project’s actual helpers or visual language.

The request can be explicit:

Inspect the current implementation before editing. Identify:
1. how routes are generated;
2. where metadata and structured data are assembled;
3. which tokens and components define the design system;
4. which commands validate production;
5. which files your proposed change must touch.

Do not implement until the findings are grounded in repository files.

For a small codebase, this takes little time and avoids a second system growing beside the first.

Ask for a route model before route code

Astro can create pages from files, dynamic paths, content collections, or a mixture. Codex should identify the existing model and explain how the new route fits it. For a content family, request a short mapping:

ConcernDecision to locate
URLSource of slug and trailing-slash policy
DataCollection, loader, and schema
RenderingShared layout and Markdown component behavior
MetadataCanonical origin and page-level fields
DiscoveryHub, breadcrumb, related links, sitemap
PublishingDraft, review, index, and noindex treatment

This catches architecture drift early. If five agent articles are represented by five hand-written page templates, the content family cannot scale cleanly. If every route comes from one generic data file with identical prose slots, editorial quality will flatten. The right design shares mechanical structure while leaving room for different writing forms.

Have Codex implement the schema and one route first. Build it. Inspect the output. Only then authorize the rest of the family.

Split work by decision boundary

Good Codex tasks have a clear owner and an observable end state. For example:

  • define a content schema and make sample data validate;
  • build the editorial layout using existing primitives;
  • add three sourced agent entries within the approved schema;
  • create a content-link checker without changing the route model;
  • diagnose a build failure without implementing unrelated cleanup.

When several tasks can proceed independently, assign non-overlapping file ownership. Shared files such as the content configuration, global stylesheet, or package scripts need one owner. Parallel speed disappears quickly when agents overwrite the same foundation.

For parallel work, give each worker a self-contained brief: owned paths, valid relationship slugs, required sources, word-depth expectation, prohibited claims, and the command that validates its output. Tell workers they are not alone in the codebase and must not revert changes they did not make.

Keep architecture and integration in one place. Separate agents can research official sources or draft independent content clusters, but one owner should reconcile the schema, route generator, global styles, and validation script. That is where local choices become sitewide behavior.

Keep Astro components serverless in the literal sense

Astro components render their script section at build time or on the server, depending on output mode. In a static project, page output is generated ahead of deployment. Ordinary Astro component code is not shipped as a browser runtime.

That makes a content card straightforward:

---
interface Props {
  href: string;
  title: string;
  description: string;
}

const { href, title, description } = Astro.props;
---

<article class="content-card">
  <h2><a href={href}>{title}</a></h2>
  <p>{description}</p>
</article>

No client directive is required. If Codex proposes React state for the same card, the task or constraints are unclear.

Reserve hydrated islands for real interaction. Ask what state exists, when the code loads, how the control works with a keyboard, and what readers receive before JavaScript runs.

Model editorial state explicitly

Astro content collections can validate entries before a route is built. Use that capability for fields with production consequences:

const article = defineCollection({
  loader: glob({ pattern: '**/*.md', base: './src/content/editorial' }),
  schema: z.object({
    title: z.string(),
    description: z.string(),
    status: z.enum(['draft', 'review', 'index', 'noindex']),
    parent: z.string().optional(),
    related: z.array(z.string()),
  }),
});

This example is deliberately incomplete. A real schema should reflect the site’s canonical paths, dates, sources, editorial voice, and quality gate. Do not copy a large schema merely because it appears comprehensive. Add fields that drive rendering, validation, or editorial decisions.

Codex can then create entries and run the content check. Broken references and missing fields become build feedback rather than production surprises.

Separate automatic validation from editorial judgment

Codex is good at implementing deterministic checks. It can compare slugs with file paths, find exact duplicate titles, verify date order, resolve related entries, scan internal links, and confirm that a quality total equals its components. These are objective properties.

Near-duplicate content, search-intent overlap, evidence quality, and professional voice need a more careful gate. A similarity warning can direct review; it should not be treated as proof that two pages are equivalent. A word minimum can flag a thin draft; it cannot make padding useful.

Ask Codex to output errors for conditions that should block production and warnings for editorial review. Keep the messages actionable:

ERROR guides/example.md: related entry agents/example does not exist
WARN  problems/example.md: 642 words; confirm this page earns a route

Do not let a generated quality score approve generated writing. The score records a review. It does not replace one.

Wire technical SEO through the Astro layout

Codex should establish one canonical URL function based on the configured production origin and route path. Feed it validated content data. The layout can then render the title, description, canonical, robots directive, Open Graph properties, and any page-type schema.

For article routes, require visible breadcrumbs and a matching BreadcrumbList. Use Article only when the page is genuinely editorial. Use the real brand or founder attribution. Keep draft and research placeholders out of the production sitemap. Do not add rating or review schema without visible, substantiated data.

Ask Codex to check the built files for outcomes. Source templates may look typed while producing an empty description because the wrong property crossed a component boundary. A short Node script can parse all generated HTML and report missing or duplicate critical elements.

Internal links need validation at the content layer and output layer. The content checker verifies relationships point to known entries. A built-link check verifies the generated route exists and catches links introduced directly in Markdown or components.

Review accessibility as behavior

Static Astro markup creates a good starting point, not automatic compliance. Require native interactive elements, clear landmarks, logical heading order, visible focus, descriptive link text, table headers, and a keyboard path through navigation and controls.

Codex can audit component semantics and find suspicious patterns such as click handlers on non-interactive elements, positive tabindex, or images without useful alternative text. It cannot determine every visual contrast or whether an alt description communicates the right information without context.

Use real content in the review. Long technical terms, code blocks, comparison tables, and mobile navigation expose failures that a simple home page does not. Honor reduced-motion preferences when adding transitions. If an effect is decorative, the page should remain understandable without it.

Keep the static build observable

A production command should expose the route count and asset profile. Ask Codex to report which pages were generated, which entries were excluded by status, how much client JavaScript representative routes load, and whether the expected robots.txt, sitemap, headers file, and 404 document reached dist.

Avoid inventing a universal budget. Establish a baseline for this repository. A change that adds a client runtime to every article deserves investigation even if the absolute bundle still looks modest. A large lead image may be justified on an example page but not on a text guide.

For a Cloudflare target, the Astro deployment guide continues from built artifacts to edge behavior. Keep those layers distinct during diagnosis.

Ask for evidence in the completion report

Require command output and built artifacts, not a general assurance. A useful report includes:

EvidenceWhat it establishes
Framework/type checkTemplates and content types are valid
Content checkRoute, metadata, source, and link rules pass
Production buildStatic generation completes
Output inspectionExpected metadata and body exist in HTML
git statusScope is visible; secrets and artifacts can be excluded
Representative route testAssets, links, and status codes work after deployment

Automated success does not settle content quality or design judgment. Review those separately. The AI website SEO diagnosis explains why a technically valid route can still be the wrong search result.

Treat high-impact actions as gates

Codex may be able to access a Git remote, hosting API, or environment variables. Capability is not authorization. State in the project rules which actions require explicit approval: production deploys, DNS changes, credential edits, payments, mass deletion, history rewriting, and publishing to a protected branch are common examples.

Resolve the target with read-only checks first. A deployment task should name the project, account, branch, domain, and verification routes. Do not substitute a new repository or hosting project because authentication is missing.

Improve the repository after every correction

When Codex repeats an error, locate the missing system. A vague instruction may need a concrete acceptance test. A recurring metadata omission may belong in a layout helper. A broken related link should be caught by content validation. A visually inconsistent callout may need a documented component variant.

This is where the workflow compounds. Each reviewed project leaves clearer constraints for the next one. Codex becomes more useful because the environment becomes less ambiguous, not because one conversation grows without limit.

Troubleshooting common Codex and Astro failures

Codex edits generated files

Identify the source and output directories in AGENTS.md. Generated .astro types, framework caches, and dist should normally be regenerated, not hand-edited. Revert only the files created by the current task and preserve unrelated work. Add missing output paths to .gitignore when that reflects the repository’s intended policy.

Content exists but no page is generated

Check that the collection loader includes the file extension and base directory, the entry passes the status filter, and getStaticPaths() returns the expected params. Compare the returned parameter with the dynamic filename. Then inspect the built route under the configured directory or file format.

Astro reports a schema error with a valid-looking date

YAML parsers and Zod coercion can produce different runtime types. Inspect the actual parsed value instead of changing the schema blindly. Decide whether dates are strings with a strict YYYY-MM-DD contract or coerced Date objects, and keep the custom validator consistent with Astro’s schema.

A component works locally but fails during static generation

Look for browser globals such as window, document, or localStorage in code that runs at build time. Move browser-only access behind an intentional hydrated component or client-side script. Do not switch the entire site to SSR to accommodate one browser-dependent widget.

Astro can emit a page even when a hand-written internal link points nowhere. Check the canonical slash normalization and whether the destination is intentionally noindex or unpublished. Fix the relationship or link. Do not weaken the check simply because the framework compiler does not own navigation integrity.

The task reaches deployment without a remote

Stop at the validated local commit if that action was authorized. Report the missing remote or authentication precisely. Do not create a new public repository, switch Cloudflare accounts, or publish from an unrelated project to manufacture completion.

If Claude Code is also under consideration, read the Claude Code versus Codex comparison. The practical choice can depend on workflow preference. The production standard should remain in the repository either way.

Sources

Primary documentation was checked on the dates below. Product behavior can change; follow the source for the current implementation.

  1. Custom instructions with AGENTS.md OpenAI Accessed
  2. Codex documentation OpenAI Accessed
  3. Astro components Astro Documentation Accessed
  4. Content collections Astro Documentation Accessed