Skip to content

Conversation

aryasaatvik
Copy link

Support markdown response for coding agents like Claude Code and OpenCode.

Inspired by:

Summary

Adds content negotiation middleware to automatically serve markdown when AI agents request documentation via the Accept header. No changes needed for browser users - HTML remains the default.

Changes

  • Middleware: Detects Accept: text/markdown header and rewrites /docs/* to /llm/*
  • Dependencies: Upgrade fumadocs-core to 15.8.3 for negotiation API
  • Backward Compatible: Existing .md extension routes still work, browsers unaffected

How It Works

// middleware.ts
if (isMarkdownPreferred(request)) {
  // Rewrite /docs/components/button → /llm/components/button
  return NextResponse.rewrite(new URL(result, request.nextUrl))
}

For AI Agents:

GET /docs/components/button
Accept: text/markdown
→ Automatically serves markdown (no .md extension needed)

For Browsers:

GET /docs/components/button
Accept: text/html
→ Serves HTML as usual

Testing

# Test with curl
curl -H "Accept: text/markdown" https://ui.shadcn.com/docs/components/button

This makes shadcn/ui docs more accessible to AI coding assistants without affecting the user experience for human visitors.

Copy link

vercel bot commented Oct 9, 2025

@aryasaatvik is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant