← Back to all tweets

Tweet by @cramforce

View original on X

The @bunjavascript team recently introduced a mode for their docs where if Claude Code or other agents request them, they directly return markdown. This saves tokens and increases precision from reduced "distractions". I prepared a quick template for how to do this in Next.js. It's a simple rewrite that says "If the client prefers text/markdown, then serve an alternate route that returns markdown". https://t.co/E5gnBN8dTC Vercel executes these rewrites on the Edge before accessing the edge cache, so this just works. Alternatively, you can also use dynamic responses with edge caching via the Vary header https://t.co/vxl7OeQrEG

const nextConfig: NextConfig = {
  rewrites: async () => {
    return {
      beforeFiles: [
        {
          source: "/docs/:slug",
          destination: "/markdown/:slug",
          has: [
            {
              type: "header",
              key: "accept",
              value: "(.*)text/markdown(.*)",
            },
          ],
        },
      ],
    };
  },
434
Reply