Skip to content

Add AGENTS.md / CLAUDE.md#23275

Open
ndellosa95 wants to merge 3 commits into
pantsbuild:mainfrom
ndellosa95:add-claude-md
Open

Add AGENTS.md / CLAUDE.md#23275
ndellosa95 wants to merge 3 commits into
pantsbuild:mainfrom
ndellosa95:add-claude-md

Conversation

@ndellosa95
Copy link
Copy Markdown
Contributor

@ndellosa95 ndellosa95 commented Apr 20, 2026

I think we can all agree that AI coding is here to stay at this point. Even as someone who was resistant for a long time, I've now been using Claude more and more and admittedly it can be extremely effective with surgical prompts and some light editing. I used it fairly extensively for this PR and generating the AGENTS.md / CLAUDE.md, which I had it generate from the Pants docsite, made it much more effective at navigating the repo and using pants correctly.

@ndellosa95 ndellosa95 added the release-notes:not-required [CI] PR doesn't require mention in release notes label Apr 20, 2026
@ndellosa95 ndellosa95 changed the title Add CLAUDE.md Add AGENTS.md / CLAUDE.md Apr 20, 2026
@cburroughs
Copy link
Copy Markdown
Contributor

Are these all things things you have had to tell a LLM? That is things it could not figure out from the existing context?

To be concrete, I use Claude Code with Opus and don't recall having to tell it to pants test instead of pytest or have it get stuck thinking it could run mypy in a venv. Did you have an issue with non-frozen dataclasses?

@ndellosa95
Copy link
Copy Markdown
Contributor Author

Are these all things things you have had to tell a LLM? That is things it could not figure out from the existing context?

To be concrete, I use Claude Code with Opus and don't recall having to tell it to pants test instead of pytest or have it get stuck thinking it could run mypy in a venv. Did you have an issue with non-frozen dataclasses?

Also using claude with opus and yeah, without the CLAUDE.md it would try and globally pip install stuff that it should be running with pants. Idk if my org has something setup with a bunch of Python context baked in already or what, but it was hugely frustrating.

@sureshjoshi
Copy link
Copy Markdown
Member

Interesting, I've been experimenting with Composer2 and haven't had to tell it any of this stuff. I just told it to first look at the actions to figure out what to do and sent it off to make a bunch of experimental, mid, changes.

@sureshjoshi
Copy link
Copy Markdown
Member

Also, you should strip out the CLAUDE.md from your other PR so it's not conflated.

@ndellosa95
Copy link
Copy Markdown
Contributor Author

I supposed it's not as extensive as what I've got here but the bazel repo also has an AGENTS.md with some details on how to use bazel so I swear I'm not crazy. The additional context could also be potentially helpful for poor souls who try to make a go at making changes with less powerful models. Happy to amend or remove anything from the doc though.

@cburroughs
Copy link
Copy Markdown
Contributor

To be clear, I don't think you are crazy! I just have no idea how to test this sort of thing and 'best practices' are in wild flux. At DAYJOB we have a wide spread between "LLMs can't work with pants unless we repeat --no-dynamic-ui at least 150 times in instructions" and "eh, it mostly just works".

Comment thread AGENTS.md Outdated
)
```

All BUILD files must have the copyright header:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have seen LLMs use the literal year (2024 in this case) from these kinds of instructions instead of updating it to the current year. Maybe a nudge to update the year will teach them to be sensible.

Comment thread AGENTS.md Outdated
| Run a single test function | `pants test path/to/file_test.py -- -k test_function_name` |
| Debug a test (interactive) | `pants test --debug path/to/file_test.py` |
| Debug with specific test | `pants test --debug path/to/file_test.py -- -k test_name` |
| Lint changed files | `pants --changed-since=HEAD lint` |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to --changed-since=main ? If you're stacking commits and you don't run this on every commit.

Comment thread AGENTS.md

```bash
# Run tests matching a pattern
pants test path/to/file_test.py -- -k "test_foo or test_bar"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can point out that everything after -- is passed through to pytest, and tell the LLM to go learn the pytest cli?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth mentioning the passthrough behavior, so that the LLM doesn't go off on a tangent trying to learn those options from Pants when they are actually pytest options.

Comment thread AGENTS.md Outdated
pants test --output=all path/to/file_test.py

# Force re-run (skip cache)
pants --no-local-cache test path/to/file_test.py
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifically for tests you can test --force which forces the test to rerun but allows everything up to that point to use the cache.

Comment thread AGENTS.md
Comment thread AGENTS.md Outdated

### File headers

All source files must have the copyright header:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we not already say this above?

Comment thread AGENTS.md Outdated

### Test function naming

- Test files: `*_test.py` (NOT `test_*.py`)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, why repeat above?

Comment thread AGENTS.md Outdated
### Integration vs unit tests

- Unit tests: `*_test.py` - run in normal test target
- Integration tests: `*_integration_test.py` - get their own BUILD target with longer timeouts
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

integration tests typically run an instance of Pants, whereas unit tests run individual functions or rules.

Comment thread AGENTS.md Outdated

PEX is special - update both:
1. The `pex-cli` subsystem in `src/python/pants/backend/python/util_rules/pex_cli.py`
2. The requirement in `3rdparty/python/requirements.txt` and regenerate lockfile
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not true any more. Pex is no longer consumed as a requirement, only as a CLI tool.

If this is still mentioned in the docs somewhere then that needs fixing.

@ndellosa95
Copy link
Copy Markdown
Contributor Author

To be clear, I don't think you are crazy! I just have no idea how to test this sort of thing and 'best practices' are in wild flux. At DAYJOB we have a wide spread between "LLMs can't work with pants unless we repeat --no-dynamic-ui at least 150 times in instructions" and "eh, it mostly just works".

I've had a lot of success getting LLMs to do what I want by threatening them with things that would probably get me flagged by HR 😆

@ndellosa95 ndellosa95 requested a review from benjyw April 22, 2026 17:16
@sureshjoshi sureshjoshi requested review from cburroughs and tdyas April 22, 2026 20:17
@sureshjoshi
Copy link
Copy Markdown
Member

Just a heads up, I have no decent opinions on any of this nor any good feedback.

@tdyas @cburroughs added you two as reviewers, as I think you both have more experience (definitely more than me, anyways) re: approving this kind of PR

I don't even know what a metric would be for this kinda thing 🤷🏽 My (EXTREMELY limited) experience with AGENTS.md and stuff is copied from some random Github repo that seemed to align with my mentality of "write as little code as possible, don't try to be too clever, ask when you don't understand" - seems to work 🤷🏽

Comment thread AGENTS.md
pants fmt src/python/pants/backend/python/goals/pytest_runner.py
pants check src/python/pants/backend/python/goals/pytest_runner.py

# WRONG - never do this
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It hurts my soul that it's not enough to show just the positive approach, but you need to show the negative as well 🤦🏽

Comment thread AGENTS.md

### Running Pants from source

In this repo, `./pants` is a special bootstrap script that runs Pants from the local source tree. Use `pants` (which resolves to the `./pants` script) for all operations. The first run compiles the Rust engine and may take several minutes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For anything non-performance, until a certain upcoming PR gets done, it may be smarter to run:
MODE=debug pants to save on compilation time, and to re-use the same compiled objects for tests.

Comment thread AGENTS.md
@@ -0,0 +1,555 @@
# Pants Build System Contributor Guide

This is the Pants build system repo -- a self-hosting build system where `./pants` runs Pants from source. Follow the conventions, architecture, and workflows specific to this codebase.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later on, the script says to use pants not ./pants

Comment thread AGENTS.md

Every directory with source code needs a `BUILD` file. Common patterns:

```python
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use tailor - but I think running a tailor check would ensure this rule.

Comment thread AGENTS.md
| Show target info | `pants peek path/to/target` |
| Generate BUILD files | `pants tailor` |
| Validate BUILD files | `pants lint --only=ruff-format '**BUILD'` |
| Run pre-push checks | `build-support/githooks/pre-push` |
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there value in also showing the merged forms? e.g. fix fmt lint check test?

Comment thread AGENTS.md
Comment on lines +290 to +294
def rules():
return [
*collect_rules(),
*FooTestRequest.rules(),
]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def rules():
return [
*collect_rules(),
*FooTestRequest.rules(),
]
def rules() -> Iterable[Rule | UnionRule]:
return (
*collect_rules(),
*FooTestRequest.rules(),
)

Comment thread AGENTS.md
- Must be complete sentences ending with a period
- Max 100 characters per line
- Explain **why**, not **what**
- TODOs must reference a GitHub issue: `# TODO(#1234): Description.`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this. Is the expectation that we'd get new issues for a TODO that the machine creates?

@tdyas
Copy link
Copy Markdown
Contributor

tdyas commented Apr 22, 2026

What are people's thoughts on the fact that AGENT.md / CLAUDE.md are loaded unconditionally into the context window? There is a cost (in tokens) to always having the instructions loaded into the context window.

A trend I have been seeing is using SKILLs.md and let the agent choose how much to load into the context. A set of "Pants maintainer skills" would also let Pants developers choose whether they want the pollute their context window with the instructions. Moreover, we could build a more comprehensive set of "Pants maintainer skills" (for actions like adding new third-party dependencies) which we would not want in a general AGENT.md.

Comment thread AGENTS.md
async def my_rule(request: MyRequest) -> MyResult:
...

def rules():
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def rules():
def rules() -> Iterable[Rule | UnionRule]:

Comment thread AGENTS.md
python_tests(
name="integration",
sources=["*_integration_test.py"],
timeout=240,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only necessary if it times out

Comment thread AGENTS.md
- Be concise but descriptive
- Reference GitHub issues where applicable

## Maintenance Tasks
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not have any PRs for lockfiles/tooling updates. I've got some PRs I'm working on to deterministically automate that stuff, so we don't need to burn down a rainforest to update a sha256.

Also, they're basically impossible to review for supply chain concerns.

Comment thread AGENTS.md
result.assert_success()
```

## PR and Contribution Workflow
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a section for the PR message itself, but full disclosure about LLM generation is important.

@sureshjoshi
Copy link
Copy Markdown
Member

What are people's thoughts on the fact that AGENT.md / CLAUDE.md are loaded unconditionally into the context window? There is a cost (in tokens) to always having the instructions loaded into the context window.

A trend I have been seeing is using SKILLs.md and let the agent choose how much to load into the context. A set of "Pants maintainer skills" would also let Pants developers choose whether they want the pollute their context window with the instructions. Moreover, we could build a more comprehensive set of "Pants maintainer skills" (for actions like adding new third-party dependencies) which we would not want in a general AGENT.md.

I was literally just joking about this with a friend after seeing some "Claude Code not available on $20 plan anymore" comments on the interwebs. Can only burn so much cash, and having to maintain some long Agents files may not be ideal.

I don't know what the state-of-the-art is here, but if we had a slimmed down Agents, I would like to see some of the "never do this" cases that we've discussed over the past few weeks/months. As always, ghostty seems to have some good ideas: https://github.com/ghostty-org/ghostty/blob/main/AGENTS.md

@sureshjoshi
Copy link
Copy Markdown
Member

Question on this - what are the tangible next steps? There is a lot of (really good) content in the file, but there is also the question of what kind of need this has, token budgets, skills, etc.

For a tangible next step, personally as a maintainer (again - LLMs are not really my thing), I would prefer what I've seen in some other repos I use, where AGENTS is used a bit more for HOW a clanker should interact with the repo/issues/PRs, rather than enumerating everything about the repo.

Short and sweet, and with the intention of making our lives a bit easier with PRs we don't want to see, what we expect/don't, etc.

Something more like:

As I say this, I guess that could also just be a CONTRIBUTING.md that this calls out to...

@tdyas
Copy link
Copy Markdown
Contributor

tdyas commented May 9, 2026

For a tangible next step, personally as a maintainer (again - LLMs are not really my thing), I would prefer what I've seen in some other repos I use, where AGENTS is used a bit more for HOW a clanker should interact with the repo/issues/PRs, rather than enumerating everything about the repo.

Yes this. Models are getting better all the time and can just read code to discover information about the code itself. AGENTS.md files should encode conventions that the AI cannot discover.

Moreover, I still have an objection to imposing large AGENTS.md files on other developers where our AI usage is going to have to include those files in our context windows and either eat up our rate limits faster and/or cost us money in tokens.

Comment thread AGENTS.md
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should have a single large AGENTS.md or CLAUDE.md file in the root of this repo. A small one? Yes. But not a large one like this. Most of the guidelines in here could be broken down into smaller "skills" (.claude/skills) that the agent would load when it needs them.

Guidelines for BUILD files? Make a build files skill that loads when working with BUILD files.

Guidelines for running tests? Make a tests skill that loads when working with tests.

etc

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

Labels

release-notes:not-required [CI] PR doesn't require mention in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants