2027 planning guide · Evidence checked 20 November 2026

LLM-friendly code: how to make a repository legible to agents

LLM-friendly code is not code written in a special dialect. It is code a coding agent can navigate without guessing: a predictable layout, explicit contracts, a command that returns pass or fail, and a short instruction file that records only what the repository cannot show. This guide turns that idea into conventions you can adopt in an afternoon.

Short answer. LLM-friendly code is code a model can navigate without guessing: a predictable layout, explicit types and errors, tests it can run, and a short instruction file that records only what the code cannot show. The aim is not to write for a model instead of people. It is to remove ambiguity that costs both of them time.

What LLM-friendly code actually means

The phrase sounds like a style guide, but the useful definition is narrower. A repository is LLM-friendly when an agent can answer four questions quickly: where does this behaviour live, what contract does it expose, how do I know a change is correct, and what local rules must I not break. Every convention below serves one of those questions.

This is different from “AI-generated code”, and it is not a benchmark. A codebase can be friendly to agents and still be unpleasant for humans if the conventions are eccentric. The durable wins usually make the repository better for new engineers too, because both readers need the same things: names that mean something, boundaries that are visible, and a fast feedback loop.

The properties that matter

Seven properties do most of the work. None requires a new framework, and each can be adopted incrementally.

Seven properties of an LLM-friendly repository and the failure each one prevents
PropertyWhat it looks likeFailure it prevents
Predictable layoutFeature folders, colocated tests, one obvious entry point per moduleThe agent searches five directories for the same concept
Explicit contractsTyped function signatures, JSON schemas, request and response typesThe agent invents a field or passes the wrong shape
Errors that name the fixMessages include the input, the violated rule and the next stepThe agent retries the same broken call
One runnable checkmake check runs lint, typecheck and tests with a clear exit codeThe agent says “done” without evidence
Small modulesOne reason to change per file; no 2,000-line service filesAn edit breaks an unrelated behaviour
Short instruction fileCommands, conventions and gotchas, kept under a couple of pagesThe agent rediscovers the same fact every session
Docs with examplesREADME, architecture notes, OpenAPI, an llms.txt index for docs sitesThe agent guesses from stale or missing prose

Start with a short instruction file

Several major coding agents now look for repository instructions. GitHub Copilot reads a repository-wide .github/copilot-instructions.md, path-specific .github/instructions/NAME.instructions.md files, and AGENTS.md files anywhere in the tree, with the nearest file taking precedence. It also accepts a single root CLAUDE.md or GEMINI.md. Anthropic's Claude Code loads CLAUDE.md into every session.

The temptation is to paste the whole onboarding document. Resist it. Every line in that file consumes attention on every task, including tasks where it is irrelevant. Anthropic's guidance is to write down only what the agent cannot find by reading the repository, and to keep the file under about 200 lines. GitHub asks for generated repository instructions no longer than two pages.

# AGENTS.md

## Commands
- Install: pnpm install
- Run one test file: pnpm vitest run path/to/file.test.ts
- Typecheck: pnpm tsc --noEmit
- Full check before you finish: make check

## Conventions
- Use the error helpers in src/lib/errors.ts; never throw raw strings.
- New API routes need an entry in openapi.yaml; CI fails without it.
- src/legacy/ is still live. Do not copy its patterns into new code.

## Gotchas
- Integration tests need DATABASE_URL; see .env.example.
- The generated client in src/gen/ is written by codegen. Do not edit it by hand.

Three sections are enough: how to verify work, what the local conventions are, and which traps are invisible from the code. If a rule must hold every time, do not rely on the instruction file. Put it in a hook, a deny rule, CI or branch protection, because a model can decide that a guideline does not apply.

Give the agent a check that returns pass or fail

The single highest-leverage change is a command the agent can run that tells it whether the work is done. Tests, a typecheck, a linter, a build exit code or a fixture diff all qualify. The command should run locally, need no production credentials, and fail loudly.

# Makefile
.PHONY: check
check:
	pnpm lint
	pnpm tsc --noEmit
	pnpm vitest run

Then use the same command in CI. An agent that can run make check can read a compiler error, fix the type and try again without you in the loop. An agent that has to guess which of six test commands is authoritative will either run all of them or none.

Keep the check fast enough to run after every edit. If the full suite takes twenty minutes, provide a targeted command for one file and reserve the full suite for the end. Document both, and say which one counts as evidence.

Name and structure files for a stranger

An agent navigates by names and imports. A file called utils2.ts is a dead end; src/billing/invoice-totals.ts tells the reader what it owns before it is opened. Prefer one concept per file, colocate the test next to the implementation, and expose a small public entry point instead of letting every internal module be imported from anywhere.

  • Use domain names, not technical layers: billing/, auth/, search/.
  • Keep file names stable. A date suffix or a version suffix forces every caller to change.
  • Avoid deep barrel files that hide where a symbol is defined. If you use a barrel, keep it to the public surface.
  • Prefer explicit imports over globals, service locators and magic environment reads.
  • Put generated code in a clearly named directory with a header that says how to regenerate it.

Write contracts and errors that explain themselves

A type signature is documentation the compiler enforces. So is a JSON schema. When a function accepts data and a boolean, the agent has to read the body to learn what either means. When it accepts pdf_bytes: bytes and returns InvoiceTotals, the call site is legible without the body.

# Before: the shape and the failure mode are invisible.
def process(data, flag=True):
    ...

# After: the contract and the error are part of the interface.
class InvoiceParseError(ValueError):
    """Raised when a PDF has no readable totals table."""

def extract_invoice_totals(pdf_bytes: bytes) -> InvoiceTotals:
    """Return invoice number, date and total from a text-based PDF.

    Raises:
        InvoiceParseError: if no totals table is found.
    """

Error messages deserve the same care. “Invalid input” tells an agent nothing. “Field currency must be one of AED, EUR, USD; received USD$” tells it exactly what to change. Put the offending value in the message when it is not sensitive, and name the rule that failed.

Documentation that agents can consume

A README that explains what the project is, how to install it, how to run the tests and how to deploy covers most of what an agent needs on day one. Architecture decision records help with the “why” that code cannot carry. An OpenAPI file is better than a prose description of an endpoint, because it is machine-checkable and can be diffed.

For a documentation site, the llms.txt proposal adds a curated markdown index at the site root or at a subpath such as /docs/llms.txt. It lists the pages an agent should read, with short descriptions, and can point to markdown versions of each page so the agent does not have to strip navigation and scripts. The proposal also recommends rel="alternate" type="text/markdown" links to those versions. Treat it as an index, not a substitute for the docs; the live guide to llms.txt generators covers the tooling side.

# Project docs

> Reference for the billing API, SDK and deployment guides.

## Start here
- [Quickstart](https://example.com/docs/quickstart.md): install, key, first request
- [API reference](https://example.com/docs/api.md): endpoints, errors, rate limits
- [Deployment](https://example.com/docs/deploy.md): VPC and on-premises options

## Optional
- [Changelog](https://example.com/docs/changelog.md): dated releases

What makes a repository hostile

The opposite of the list above is easy to recognise. Giant files with several responsibilities, hidden environment reads, a custom DSL with no grammar, generated code with no regeneration note, tests that need production data, and docs that describe a previous architecture all force the agent to guess. Guessing is expensive because a wrong guess produces a confident patch that fails review.

Stale comments are a special case. A comment that contradicts the code is worse than no comment, because the agent may trust it. Delete it or update it in the same change.

A 30-minute audit

  1. Clone the repository into a fresh directory and ask an agent to make one small, real change without any help.
  2. Record every question it has to ask and every file it opens before the first edit.
  3. Run the check command from a clean environment. If it fails for an undocumented reason, fix the setup before writing more instructions.
  4. Read the first 40 lines of the instruction file. Delete anything the agent could have learned from the code.
  5. Pick the three largest files and write down the concept each one owns. If you cannot, split or rename them.
  6. Ask the agent to explain the change it made and the evidence that it works. If it cannot, the check is not observable enough.

Measure the effect on your own repository

Do not adopt conventions because a post promised a percentage. Measure four things before and after: time to first correct edit, tool calls or file reads per task, first-attempt test pass rate, and review comments per pull request. Add onboarding time for a human engineer if you want the business case, because most of these changes help both readers.

Keep the measurement small. Five representative tasks, run twice, are enough to show whether a change helped. A controlled benchmark across many repositories is a research project, not a prerequisite for cleaning up a README.

What we did not verify

  • We did not run a controlled study of agent performance on any repository, and we report no percentage improvement from these conventions.
  • We did not test every coding agent or every instruction-file convention. The file names and precedence rules described here are the ones documented by Anthropic and GitHub on 20 November 2026.
  • We did not verify how any specific model weights instruction files against repository code, or how often it ignores a guideline.
  • We did not audit the security of running an agent with write access to a repository. Use least-privilege tools, review diffs and keep secrets out of the workspace.
  • We did not test llms.txt adoption or crawler behaviour; the proposal is a convention, not a standard enforced by a vendor.

Frequently asked questions

What is LLM-friendly code?

LLM-friendly code is code a model can navigate without guessing: a predictable layout, explicit types and errors, tests it can run, and a short instruction file that records only what the code cannot show. It is a legibility property, not a benchmark or a coding style.

Do I need an AGENTS.md file?

It helps when more than one agent or tool works in the repository. GitHub Copilot reads AGENTS.md files anywhere in the tree, with the nearest file taking precedence, and also supports .github/copilot-instructions.md and a root CLAUDE.md or GEMINI.md. Keep whichever file you choose short and specific.

How long should an instruction file be?

Short enough that every line is worth its context cost. Anthropic recommends keeping CLAUDE.md under about 200 lines, and GitHub asks for generated repository instructions no longer than two pages. Write commands, conventions and gotchas, not a copy of the directory tree.

Why does a runnable check matter more than a longer prompt?

A check gives the agent a pass or fail signal it can act on without you. Tests, a typecheck, a linter or a build exit code let it close the loop, read the error and try again. A longer prompt adds context but does not tell the agent whether the change worked.

Should documentation be written for agents or for people?

For people first. Clear headings, runnable examples and stable anchors already help agents. If you publish a documentation site, add an llms.txt index and markdown versions of pages so an agent can fetch a smaller, cleaner version without scraping navigation.

Can I prove that LLM-friendly code improves agent output?

Only with a controlled test on your own repository. Track time to first correct edit, tool calls per task, first-attempt test pass rate and review comments before and after a change. Published claims about percentage gains rarely transfer across codebases.

Related pages

Give the agent one endpoint, not five

Use an OpenAI-compatible API with 39 public model IDs, so the same client works across coding models and regions.

Start Free → See pricing

Sources

Each source was checked on 20 November 2026. Agent instruction formats and precedence rules change; recheck before standardising across a team.

Official documentation used for this article
SourcePage checkedChecked
Anthropicanthropic.com/engineering/claude-code-best-practices20 Nov 2026
GitHubdocs.github.com — repository custom instructions20 Nov 2026
llms.txtllmstxt.org20 Nov 2026
Plugskyplugsky.com/docs20 Nov 2026

Last checked 20 November 2026. For canonical product numbers, see /facts; for the API shape, see /docs.