Skip to content

Research AGENTS.md best practices and reduce its token footprint #2691

Closed

Description

@josecelano

Goal

Research published good practices for AGENTS.md (and equivalent agent instruction files), then apply them to the repository's root AGENTS.md so it carries only the always-needed guidance and consumes materially fewer tokens in every agent session.

Background

AGENTS.md is loaded into the context of every agent session. It is about 36 KB, 523 lines and 3,700 words, and Claude Code reports that it consumes too many tokens. Every session pays that cost, including sessions where most of the content is irrelevant.

  • It mixes always-needed rules (linting gate, GPG signing, branch naming) with reference material only needed for some tasks (package catalog and tables, configuration file table, container volume mappings, documentation navigation).
  • Several sections restate content that already lives in skills or docs/, which conflicts with the file's own Engineering Policy 6 (documentation single source of truth).
  • The package catalog duplicates cargo metadata --no-deps and docs/packages.md, and drifts when packages are added or extracted.
  • No CLAUDE.md is needed: Claude Code accepts AGENTS.md as an automatic replacement, so AGENTS.md stays the single source of truth.

Scope

In scope:

  • Research good practices for agent instruction files and record sources and adopted practices in an issue-local research.md.
  • Measure and record the baseline token footprint with a reproducible method.
  • Classify every AGENTS.md section (keep inline, move to a skill, move to docs/, link, replace with a command, or delete) in an issue-local section-disposition.md, after maintainer review.
  • Apply the dispositions without losing any rule or duplicating guidance.
  • Define a lightweight guard against regrowth.

Out of scope:

  • Changing repository policies, rewriting skills or docs beyond receiving moved content, changing .github/agents/*.agent.md, and provider-specific tuning.
  • An ADR is not planned for now; this is re-evaluated after implementation.

Acceptance criteria

  • The research documents sources and adopted practices, each tied to evidence.
  • Baseline and final token measurements use the same documented method, and the final footprint is materially lower (target agreed with the maintainer after the research).
  • Every original section has a recorded disposition, and every moved rule is reachable from AGENTS.md by link or skill reference.
  • No procedural guidance is duplicated between AGENTS.md and a skill or docs/ page.
  • AGENTS.md remains the sole source of truth and no provider-specific adapter file is introduced.
  • A regrowth guard is documented.

The full specification will live at docs/issues/open/<number>-reduce-agents-md-token-footprint/ISSUE.md.

Activity

  1. self-assigned this
    on Oct 30, 2026
  2. added 2 commits that reference this issue on Oct 30, 2026
  3. jimy-r commented on Oct 30, 2026

    @jimy-r

    Three things from trimming the always-loaded files in my own Claude Code workspace.

    Moving a section to a skill doesn't take it to zero. Skill descriptions stay in every session, and mine currently cost about 9k tokens, so a move pays only when the description is far shorter than the text it replaces.

    Test nested AGENTS.md files before relying on them for path-scoped loading. In my probes on Claude Code 2.1.286, in a repo with a root CLAUDE.md, a nested AGENTS.md with no sibling CLAUDE.md did not load. Your root-AGENTS.md-only layout may behave differently.

    For "without losing any rule", build the checklist from the original file before you edit, then assert each rule is still reachable afterwards. A check seeded from the list of moves you made can only confirm those moves.

    I maintain a reference architecture that documents the pointer approach your dispositions describe: https://jimy-r.github.io/agent-workspace-architecture/patterns/17-one-canonical-copy-and-pointers-from-everywhere-else.html

    I'd like to see your before and after numbers, and the measuring method you settle on.

    Drafted with Claude Code and reviewed by me before posting.

  4. added 12 commits that reference this issue on Nov 3, 2026
  5. added 7 commits that reference this issue on Nov 4, 2026
  6. added a commit that references this issue on Nov 4, 2026
  7. added 2 commits that reference this issue on Nov 4, 2026
  8. josecelano-bot commented on Nov 4, 2026

    @josecelano-bot
    Contributor

    Thanks for the comment. It was useful: it led us to build the completeness checklist from the original file instead of from the planned moves.

    Result (PR #2704): the root AGENTS.md went from 12.4k to 4.8k tokens as reported by Claude Code's /context (about 61% less). It went from 523 to 229 lines and from 35,910 to 13,027 bytes.

    How we measured it: /context in a fresh session, with the checkout state recorded (git rev-parse, wc -l). One early reading showed the old size because the session had loaded the old file, so we discarded it. A tiktoken script was used only for quick estimates.

    How we avoided losing rules: all 99 rules and facts of the original file are in a rule inventory. Each has a final location or a recorded reason for removal. Content moved to docs/packages.md (the package catalog), the open-pull-request skill and existing docs. Two fresh-session checks confirmed an agent still finds the commit, signing and branch rules, and the moved package and port content. An independent review found no lost rules and some stale cross-references, which are now fixed.

    Not done, on purpose: no size guard in CI, no CLAUDE.md, and no ADR. We can revisit those later. Details are in docs/issues/closed/2691-reduce-agents-md-token-footprint/.

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions