-
Identify the target feature
If the user did not clearly specify the feature, use the AskUserQuestion tool to ask what feature they want documented.
If the user provided only a loose name, search the repo to find the most likely feature folder.
Prefer the narrowest cohesive directory that represents the feature.
Good signals:
- A dedicated directory in
packages/*/src/
- A group of files sharing a clear feature name
- Tests colocated with the feature
If multiple candidate folders match, stop and ask the user to choose.
Do not guess when the choice is ambiguous.
-
Confirm the write location
The output file must be <feature-folder>/AGENTS.md.
If the user named a feature that is implemented across scattered files without an obvious folder:
- Find the nearest cohesive feature directory
- If there still is no clear home for
AGENTS.md, ask the user where they want it stored
Do not create an arbitrary new feature structure just to place the document.
-
Read the feature thoroughly
Read the code in the feature folder first.
Then read nearby tests, public exports, and adjacent supporting files that define how the feature behaves.
You should understand:
- What the feature exposes
- What responsibilities belong to it
- What is core behavior vs helper implementation detail
- What the feature appears to optimize for or protect against
-
Capture the feature's role in the product
Decide how this feature contributes to the end product so you can explain its purpose and use cases accurately.
One useful lens is whether it is primarily public or internal:
- A public feature directly adds, changes, configures, or exposes behavior that an end user can intentionally use
- An internal feature mainly supports other features and does not itself add a direct public interface
This distinction is not the goal by itself. Use it only to sharpen the explanation of:
- Why the feature exists
- How it is used
- Which public behavior it adds, changes, or enables
Examples:
soft-delete is best explained through the user-visible behavior it adds: configuration, query behavior changes, and related query methods
mutative-queries-select-relations is best explained through the public features it enables: selecting relations from create/update/delete flows
If the feature looks mixed, focus on the dominant purpose and mention the secondary role only if it helps understanding.
-
Map dependencies
Inspect imports and direct usage inside the feature to identify what it depends on.
Focus on meaningful dependencies:
- Other internal features
- Public/internal package entry points
- Important utility layers the feature relies on for its behavior
Avoid listing every trivial helper unless it is essential to understand the feature.
-
Map dependents
Search for usages of the feature outside its own folder to learn what depends on it.
Look for:
- Imports from the feature
- Public exports that expose it
- Other features that call into it
- Tests that demonstrate real usage patterns
Prefer feature-level dependents over raw file lists. Group related callers into a single feature when possible.
Also identify which user-visible functionality is affected by this feature, whether directly or indirectly.
-
Distill intent
Before writing, explicitly decide:
- Why this feature exists
- What problem it solves
- Which distinct use cases it serves
- Whether calling it
public or internal helps clarify its role
The Purpose section must capture intent, not mechanics.
Work backwards from code, tests, names, and call sites to infer the real reason this feature exists.
If the feature is public or internal in an important way, mention that as part of the explanation, but do not let that replace the explanation.
If intent is still unclear after investigation, ask a targeted clarifying question instead of writing vague filler.
-
Ask clarifying questions when needed
You must stop and ask if any of these are unclear:
- Which folder is the feature
- The feature boundary
- The intended audience or naming
- Whether two similarly named features should be treated separately or together
- Whether an existing
AGENTS.md should be replaced when the situation is ambiguous
Ask only the minimum questions needed to proceed.
-
Write AGENTS.md
Create or replace <feature-folder>/AGENTS.md with a concise, factual document.
Use this structure:
# <Feature Name>
## Purpose
<Explain why this feature exists, what problem it solves, and the intent behind it. Mention whether it is primarily public or internal when that helps clarify its role.>
## Use cases
<List the real ways this feature is used or matters in the product.>
<If it is public, focus >
:
Example:
How:
:
How:
-
Sanity check the document