Skip to content

AI agent instructions ignore basePath, causing /llms.txt to 404 on subpath-hosted docs #17322

Description

@hey-august

Component

Docs

Priority

P2 - Medium (Would be helpful)

SDK Language(s)

No response

Bug Description

Summary

Fern Docs server-renders a hidden discovery hint for AI agents into every page:

<div class="sr-only" aria-hidden="true">For AI agents: a documentation index is available at the root level at /llms.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.</div>

On docs hosted under a custom domain subpath (like ours, signalwire.com/docs), the "root level at /llms.txt" statement is wrong. Fern only serves under /docs, and the domain root belongs to a separate site. An agent that follows the hint gets a 404 and concludes no index exists, which is worse than having no hint at all, since this div exists precisely so non-JS fetchers (Claude, GPT crawlers, etc.) can discover llms.txt.

Reproduction

$ curl -sL https://signalwire.com/docs/swml/ -A "Mozilla/5.0" | grep -o 'For AI agents[^<]*'
For AI agents: a documentation index is available at the root level at /llms.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.

$ curl -s -o /dev/null -w '%{http_code}\n' https://signalwire.com/llms.txt
404

$ curl -s -o /dev/null -w '%{http_code}\n' https://signalwire.com/docs/llms.txt
200

The other two statements in the div work fine on subpath instances: <page-url>/llms.txt and <page-url>.md both resolve. Only the root-level pointer is broken.

Expected behavior

The directive should point to the instance's actual llms.txt location. In other words, it should be basePath-aware: …available at /docs/llms.txt.

Alternatively (or additionally), let docs.yml override the div text. agents.page-directive already customizes the directive prepended to .md/markdown output. We already set it to the correct absolute URL, which works great there:

agents:
  page-directive: >-
    For a complete index of all SignalWire documentation pages, fetch
    https://signalwire.com/docs/llms.txt

Either honoring page-directive in the HTML div or adding a sibling key would solve this too.

Impact

Fern customers hosting sites on subpaths of custom domains are misdirecting AI agents on every page. At SignalWire, we noticed because Claude was consistently failing to locate SignalWire docs content. Pointing it manually at /docs/llms.txt fixes it.

Versions

5.67.1

Workaround

No response

Are you interested in contributing a fix?

No

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions