How to Ship Clean Markdown Docs for AI Coding Agents (llms.txt, llms-full.txt & Next.js Routes Without External Crawlers)
If you maintain an SDK, API, or developer tool, you've probably watched an AI coding assistant hallucinate outdated flags because it tried to parse your heavily styled HTML docsβor got tripped up by client-side hydration
If you maintain an SDK, API, or developer tool, you've probably watched an AI coding assistant hallucinate outdated flags because it tried to parse your heavily styled HTML docsβor got tripped up by client-side hydration.
Even though Google Search does not use llms.txt for ranking, publishing a clean /llms.txt index and /llms-full.txt Markdown bundle is genuinely useful for developers and coding agents pulling your docs into context.
The catch: most online llms.txt generators work by pointing a remote crawler at your public URL. That breaks immediately if:
- You're working on
localhostor a password-protected staging environment. - Your WAF/CDN rate-limits or blocks third-party scrapers.
- The scraper ingests your
<nav>,<footer>, and cookie banner into the output.
Here is a clean, local-first workflow to generate, structure, and serve /llms.txt and /llms-full.txt in a Next.js App Router project.
1. Know the Three Files (And Which Ones You Actually Need)
-
/llms.txt(Required index): A compact Markdown table of contents following llmstxt.orgβone# H1title, one> blockquotesummary, curated## H2link lists with concise factual descriptions, and an## Optionalsection for secondary pages. -
/llms-full.txt(Optional full bundle): Concatenated clean Markdown of your primary docs so an agent can ingest the entire core reference in one request. -
/llms-ctx.txt(Optional XML context): Prompt-friendly XML-wrapped context for direct LLM pasting.
2. Example Spec-Compliant /llms.txt
# AcmeSDK
> TypeScript SDK for real-time webhook verification and idempotent event queues.
## Core Documentation
- [Quickstart](https://docs.example.com/quickstart): Install the SDK and verify your first webhook signature in 5 minutes.
- [Authentication](https://docs.example.com/auth): API key scoping, rotation, and HMAC-SHA256 header verification.
## API & SDK Reference
- [Queues API](https://docs.example.com/api/queues): Enqueue jobs, configure retry backoff, and inspect dead-letter queues.
- [Error Codes](https://docs.example.com/api/errors): HTTP status codes and retryable vs. terminal error payloads.
## Optional
- [Changelog](https://docs.example.com/changelog): Release notes and migration guides.
Three mistakes to avoid: never use relative paths (always use full https:// canonical URLs), avoid vague link titles like "Click here" or "Learn more," and strip marketing superlatives from descriptions so every token carries technical signal.
3. Serve /llms.txt Cleanly in Next.js App Router
You can drop static files straight into public/llms.txt, or serve them via a route handler with explicit text/plain; charset=utf-8 headers and CDN caching:
// app/llms.txt/route.ts
import { NextResponse } from 'next/server';
const LLMS_TXT = `# AcmeSDK
> TypeScript SDK for real-time webhook verification and idempotent event queues.
## Core Documentation
- [Quickstart](https://docs.example.com/quickstart): Install the SDK and verify your first webhook signature in 5 minutes.
- [Authentication](https://docs.example.com/auth): API key scoping, rotation, and HMAC-SHA256 header verification.
## Optional
- [Changelog](https://docs.example.com/changelog): Release notes and migration guides.
`;
export async function GET() {
return new NextResponse(LLMS_TXT, {
status: 200,
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Cache-Control': 'public, max-age=3600, s-maxage=86400',
},
});
}
4. Don't Forget Your robots.txt Cross-Check
Before deploying, confirm two things in /robots.txt:
- You aren't accidentally disallowing
/llms.txtor/llms-full.txt. - If you add bot-specific
User-agent:rules (to allow search citation bots while blocking training crawlers), repeat your globalDisallow:paths (/admin/,/api/private/) inside each allowed bot block so RFC 9309 doesn't override your wildcard protections.
Generating & Linting Locally Without Writing Boilerplate
If you want to paste a local Sitemap XML or raw HTML pages (automatically stripping <nav>, <script>, and <footer>), check BPE token counts across GPT/Claude/Gemini/DeepSeek, lint both llms.txt and robots.txt together, and export ready-to-paste Next.js routes without sending private docs to an external crawler, KivaroTools' in-browser llms.txt studio handles the whole pipeline locally with no sign-up. You can also browse the main KivaroTools browser suite if you prefer local-first developer utilities.
Quick Ship Checklist
- Verify
curl -I https://yourdomain.com/llms.txtreturns200 OKandtext/plain; charset=utf-8. - Keep primary links concise and move changelogs/archive pages into
## Optional. - Check that
robots.txtallows/llms.txtand repeats protectedDisallow:routes inside any custom bot blocks.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.