# For AI agents

> How an AI coding agent should use trimtest safely, with an AGENTS.md snippet, a Claude Code skill, exit-code handling and the machine-readable surfaces.

If an AI agent edits code in a repository that uses trimtest, this page is the contract: when to trust a selection,
what the exit codes mean, and how to fall back to the full suite.

## Machine-readable access to these docs

| URL | What it is |
|---|---|
| [`/llms.txt`](/llms.txt) | index of the docs with a short description of each page |
| [`/llms-full.txt`](/llms-full.txt) | every page concatenated as markdown |
| `<any page URL>.md` | that page as plain markdown, for example `/start/quick-start.md` |
| [`/schema/trimtest.schema.json`](/schema/trimtest.schema.json) | JSON Schema for `trimtest.toml` |
| [`/skill/SKILL.md`](/skill/SKILL.md) | a Claude Code skill that wraps the rules below |

## The rules

1. **Select, then run.** After a change, `trimtest run` runs only the tests the change can reach. In a pull request
   or a fresh clone use `trimtest run --base origin/<base-branch>`; it needs no recorded map.
2. **Read the exit code** ([reference](/reference/exit-codes/)):
   - `0` passed (or nothing was selected): proceed.
   - `1` a test failed: fix it, then run again. Failed tests always run first next time.
   - `2` trimtest itself failed: read the message, run `trimtest check`.
   - `3` selection is uncertain: **run the full suite** with `trimtest run --full`.
3. **Trust the conservatism, not a green subset alone.** trimtest runs everything when it cannot trace a change.
   A green subset means the selected tests passed, not that the whole suite would. Before declaring a task done, or
   before merging, make sure the project's scheduled full run (or `trimtest run --full`) is green.
4. **Do not skip the nightly full run** or remove it from CI to save time.
5. **Set a timeout** so a hung runner cannot stall you: `trimtest run --timeout 600 --total-timeout 1800`.
6. **Never edit `.trimtest/`** by hand. It is a cache; delete it and run `trimtest record` if it looks wrong.

## Reading a selection

```bash
trimtest select --json                 # structured: changed files, unobserved changes, selected tests with reasons
trimtest select --paths                # just the test paths, one per line
trimtest explain tests/test_core.py    # why one test was, or was not, selected
```

The [JSON shape](/reference/json-output/) is stable; new fields may be added. A non-empty `unobserved` list means a
changed file is not known to reach any test, so consider `trimtest run --strict` or a full run.

## When a test you expected is missing

1. `trimtest explain <test>` prints every reason and the evidence tier.
2. If a dependency is invisible to imports (reflection, string-based access), record coverage:
   `trimtest record --coverage`.
3. For suites with no import link (end-to-end), add a `[map]` entry to `trimtest.toml`.

## Drop-in `AGENTS.md` snippet

Paste this into the `AGENTS.md` (or `CLAUDE.md`) of a repository that uses trimtest:

````markdown
## Running tests

This repo uses [trimtest](https://trimtest.dev) to run only the tests a change can reach.

- After a change: `trimtest run` (or `trimtest run --base origin/main` on a branch or fresh clone).
- Exit codes: 0 pass, 1 test failed (fix and rerun), 2 trimtest error (`trimtest check`),
  3 selection uncertain (run `trimtest run --full`).
- `trimtest explain <test>` says why a test was or was not selected. `trimtest select --json` is machine-readable.
- A green subset is not a green suite: run `trimtest run --full` before you call a task finished or open a PR,
  and never remove the scheduled full run from CI.
- Use `--timeout 600 --total-timeout 1800` for long suites. Do not edit `.trimtest/`.
- Docs for agents: https://trimtest.dev/llms.txt
````

## Claude Code skill

Save [`/skill/SKILL.md`](/skill/SKILL.md) as `.claude/skills/trimtest/SKILL.md` in a repository (or in
`~/.claude/skills/trimtest/` for every repository) and Claude Code will use these rules whenever it runs tests.
