llms-txt-php
CLAUDE.md33 starsChanged 3 months agoMITView on GitHub
stolt/llms-txt-php is a dependency-free PHP library (only ext-dom/ext-libxml) for writing, reading, and validating llms.txt Markdown files. It targets v2 of the specification. The public API surface is documented in detail in the README — keep both in sync when changing it. A complementary console package lives in a separate repository: llms-txt-php-cli. Run composer pre-commit-check before committing or opening a pull request. CI runs the test suite on PHP 8.3, 8.4, and 8.5 (composer.json still allows >=8.1), and lints on 8.4.
The file
We split this CLAUDE.md into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 31
Run composer pre-commit-check before committing or opening a pull request.
- Very specific: line 76
All classes are final and declare(strict_types=1).
- Very specific: line 87
Keep CHANGELOG.md and the repository's own llms.txt current alongside user-facing changes.
≈ “Common” is an estimate: at least 1 in 5 of the 29,248 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project
stolt/llms-txt-php is a dependency-free PHP library (only ext-dom/ext-libxml) for writing, reading, and
validating llms.txt Markdown files. It targets v2 of the
specification. The public API surface is documented in detail in the README — keep both in sync when changing it.
A complementary console package lives in a separate repository: llms-txt-php-cli.
Commands
composer test # PHPUnit (stops on first failure, see phpunit.xml.dist)
vendor/bin/phpunit --filter itParsesLlmsTxtFile # single test method
vendor/bin/phpunit tests/DiscoveryTest.php # single test file
composer test-with-coverage # HTML coverage into coverage-reports/ (sets XDEBUG_MODE)
composer cs-lint # php-cs-fixer dry run, fails on violation
composer cs-fix # php-cs-fixer fix in place
composer static-analyse # PHPStan level 5 over src/ and tests/
composer spell-check # peck (needs aspell + aspell-en)
composer validate-gitattributes # lean-package-validator
composer dependency-analyse # composer-dependency-analyser
composer pre-commit-check # test + cs-lint + static-analyse + spell-check + gitattributesRun composer pre-commit-check before committing or opening a pull request. CI runs the test suite on PHP 8.3, 8.4,
and 8.5 (composer.json still allows >=8.1), and lints on 8.4.
Architecture
Six classes under Stolt\LlmsTxt (src/, PSR-4), each covering one concern of the specification:
LlmsTxt— the aggregate root. Holds title, description, details, and an ordered list ofSections; renders (toString,toFile,asScriptTag), parses (parse), and validates (validate).Section/Section\Link— the## Headingblocks and their- [title](url): detailslines. Both render themselves viatoString, which is howLlmsTxt::toStringcomposes output.Discovery— v2 link relations (rel="describedby",rel="alternate" type="text/markdown"). Renders and parses them as HTML<link>elements and as HTTPLinkheader values, plus the two URL rules of the spec (markdownUrls,coveringUrls/coveringUrl). Pure string/DOM work, no network.LlmContext— expands the linked documents of a parsed file into an XML context file (<project>/ section tag /<doc>). Reached throughLlmsTxt::toLlmContext()/toLlmContextFile().Extractor— pulls<script type="text/llms.txt">blocks out of HTML, optionally parsing each into anLlmsTxt.Validation\ValidationResult/ValidationError— errors vs. warnings container returned byvalidate(true).
Discovery and LlmsTxt are designed to compose: Discovery locates files and Markdown page versions, LlmsTxt
reads them. tests/DiscoveryIntegrationTest.php is the reference for those combinations.
Behaviours that are easy to get wrong
parse()returns a new instance, not$this— always use the return value. It is also the only thing that sets the privatehasBeenParsedflag.validate()throws anExceptionon an instance that wasn't produced byparse().- Validation severity follows the spec: a missing title is the only error, because the title is the only required element. Missing description, details, sections, and section links are warnings. Don't promote a warning to an error without a spec change to point at.
parse()accepts a path or raw content, discriminated inextractContent(): content must start with#, a path must end intxtormd, anything else throws.- v2 dropped the mechanical meaning of the
Optionalsection. It is now just a convention for secondary links, sotoLlmContext()expands all sections by default;$skipOptionalis opt-in.LlmsTxt::optional()/getOptional()name and find that section viaLlmsTxt::OPTIONAL_SECTION_NAME. addSection()appends and de-duplicates by name;addSections()/sections()replaces the whole list.- Network access is injectable: pass a
callable(string $url): string$fetchertotoLlmContext()/toLlmContextFile()/LlmContext::expand(). Tests must use this instead of hitting the network; the defaultLlmContext::fetch()reads local files, then falls back to PHP streams.
Conventions
- Fluent setters are bare nouns (
title(),description(),name(),url()), getters are prefixed (getTitle(),getLinks()), and severaladdX()methods have a singular alias (section()/addSection(),link()/addLink()). Follow that pairing when adding to the API. - All classes are
finalanddeclare(strict_types=1). php-cs-fixer enforcesfinal_internal_class— the one exception,tests/TestCase.php, opts out with a@not-fixdocblock annotation. native_function_invocationis enforced for internal functions, hence the\-prefixed calls (\count,\file_get_contents, …) throughout. New code must match.- Tests use PHPUnit attributes (
#[Test]) with camelCaseitDoesSomethingmethod names, extendStolt\LlmsTxt\Tests\TestCase, and read fixtures fromtests/fixtures/.TestCaseprovidessetUpTemporaryDirectory()with automatic teardown for tests that write files. - Commits follow Conventional Commits; contributions go on feature branches.
- New domain vocabulary that
peckflags belongs in theignore.wordslist ofpeck.json. .gitattributesis an export-ignore-everything allowlist (lean dist package) — a new directory that must ship in the Composer dist needs a matching-export-ignoreentry, whichcomposer validate-gitattributeschecks.- Keep
CHANGELOG.mdand the repository's ownllms.txtcurrent alongside user-facing changes.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

