Code comment
The reason for one line, right above it.
Decision record
The reason for a choice that spans files.
AGENTS.md file
Rules every agent reads before it edits.
Test
Fails loudly if the behaviour changes.
Before you start
- A repository indexed in Graphify, with your coding agent connected to the hosted MCP server. The open-source Graphify CLI works too.
- Access to your git history and issue tracker.
Why AI coding agents “fix” code that isn’t broken
Agents read the code, not the history behind it. A line that’s odd on purpose, like a status mapped the “wrong” way to work around a provider, reads like a bug. Without the reason next to it, the agent cleans it up. To find the reason, rungit blame on the odd lines, then read the commit, pull request and ticket behind them.
Write code comments that explain why
A good comment says why the code works this way, not what it does. Put it right above the code, keep it to the reason, and link the ticket or decision record.PENDING → SUCCESS looks like a bug.
Record big choices in an architecture decision record
When the reason spans files, teams or trade-offs, write a short architecture decision record (ADR) indocs/adr/ and link it from the comment. This template is enough:
Put team rules in an AGENTS.md file
An AGENTS.md file at the root of your repo holds rules your coding agents read before they work. Add one line:Lock the behaviour in with a test
Add a test that asserts the deliberate behaviour and points back to the reason. If anyone, person or agent, changes it, CI fails.Find the risky spots first with Graphify
You don’t need to document everything. Start where a wrong “fix” would hurt most.- Coupling hot spots from your PR reviews. Every Graphify review has an Impact & health section under Analysis details. When a change makes coupling worse, it says so, for example: Health — this change adds coupling hotspots: worse:
load_cached()— 66 callers, 10 callees. Those functions are your first candidates. - The most-called code. Open Graph explorer and check Most connected, or select a node and read What a change could affect.
graphify_callers and graphify_impact tools. With the CLI, run graphify explain "<name>" and check the degree, or use the god_nodes MCP tool.
Hot spots here come from how code connects, not from how often files change. Graphify doesn’t rank files by git churn.
When it goes wrong
The blame points to a huge refactor commit
The blame points to a huge refactor commit
Run
git log --follow -p on the file, or git blame --ignore-rev <commit> to skip formatting and move-only commits.No ticket explains the reason
No ticket explains the reason
Ask the people in the commit history. If nobody knows, write what you found, mark it unconfirmed, and still lock the current behaviour with a test.
A caller you expected is missing
A caller you expected is missing
Graphify shows the connections it can see. Code called dynamically or by string name may not appear. See Check impact.
You want a CI check
You want a CI check
Once the habit sticks, add a CI step that flags changes to files with WHY comments when the matching test or decision record didn’t change. Pair it with test impact analysis to run the tests a change touches.
FAQ
What is a code comment, and when should it explain why?
What is a code comment, and when should it explain why?
A code comment is a note in the source that the program ignores but people and agents read. Explain why whenever the code does something deliberate that looks wrong, such as a workaround, an odd mapping or a hard limit.
What is an architecture decision record?
What is an architecture decision record?
A short file that records one decision: the context, the choice and its consequences. Teams keep them in
docs/adr/ so the reason outlives the people who made it.What goes in an AGENTS.md file?
What goes in an AGENTS.md file?
Project-wide rules for coding agents: how to build and test, conventions, and instructions like “read WHY comments before editing”. Keep line-specific reasons in comments, not here.
What are code documentation best practices for AI agents?
What are code documentation best practices for AI agents?
Put the reason next to the code, link bigger decisions to a record, give agents rules in AGENTS.md, and lock deliberate behaviour with tests. Start with the most-connected code.
Next steps
Make agents use the graph
Tell your agent when to ask Graphify first.
Plan a refactor
List callers and tests before a change.
Review a pull request
See where coupling hot spots come from.
Try it in Graphify
We build and host the graph for you. The Free plan (up to 3 repositories) needs no card. Pro and Teams start with a 14-day trial, card required.