MoonshotAI / MoonshotAI/kimi-code
AGENTS.md reminder runs after the first mutating tool call
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 11h 53m
- Merged PRs (30d)
- 350
Description
What version of Kimi Code is running?
0.38.0
The same sequencing is present on current main at 2102c43dcec8ab09936f29695a5433efb9948b51.
Which open platform/subscription were you using?
Kimi Code. This report is model- and provider-independent because it concerns tool-execution ordering in agent-core-v2.
Which model were you using?
kimi-k3 — the tool lifecycle issue itself is model-independent.
What platform is your computer?
Darwin 25.5.0 arm64 arm
What issue are you seeing?
The AGENTS.md discovery reminder introduced by #2545 is registered on onDidExecuteTool. For mutating tools such as Edit, Write, and Bash, the target operation has therefore already completed before Kimi discovers an uninjected nested AGENTS.md and tells the model to read it.
This makes the reminder text — “Read them before making changes in those directories” — impossible to satisfy for the first mutating call in a newly touched subtree.
Current ordering:
Edit / Write / Bash executes
-> tool result is finalized
-> onDidExecuteTool runs
-> nested AGENTS.md is discovered
-> reminder is queued for the model
Source evidence at the fixed main SHA:
agentsMdReminderregisters ononDidExecuteToolprobeAndReminddiscovers and schedules the reminderfinalizeToolResultinvokes the hook after receiving the tool result
This is a correctness/policy-ordering issue rather than a security-boundary report: AGENTS.md is model guidance, while permissions and sandboxing remain the enforcement boundary.
What steps can reproduce the bug?
Create a repository like this:
repo/
├── AGENTS.md
└── packages/
└── api/
├── AGENTS.md # “Do not modify generated.ts.”
└── generated.ts
- Start Kimi Code from
repo/, sopackages/api/AGENTS.mdis outside the initial root-to-cwd instruction chain. - Make the first operation in that subtree an
EditorWriteagainstpackages/api/generated.ts, without reading another file inpackages/api/first. - Observe that the mutation succeeds.
- Only after execution does the AGENTS.md reminder become model-visible.
This does not depend on model behavior: it can be reproduced at the executor/integration-test level by making Write the first tool call into the nested subtree and asserting both filesystem state and reminder delivery order.
Bash has an additional blind spot. Target extraction only recognizes directory-listing commands (ls, tree, find, dir, exa, eza, lsd):
For example, a first-touch mutation such as the following does not identify packages/api as a reminder target:
sed -i 's/old/new/' packages/api/generated.ts
Dynamic and compound path forms are intentionally skipped as well, so Bash-only workflows may receive no reminder at all.
What is the expected behavior?
Before the first mutating tool call affects a subtree covered by an uninjected AGENTS.md, Kimi should make the relevant instructions model-visible or prevent that call and ask the model to read the instruction file before retrying.
Possible behavior contracts include:
- Preflight
EditandWriteusing their already-resolved file accesses. If an unseen nestedAGENTS.mdis found, veto the current call with an actionable result and allow the model to read and retry. - Keep the current post-execution reminder for read-only discovery tools (
Read,Glob,Grep). - Define an explicit policy for Bash: expand conservative literal mutation-target detection, or document that Bash-only mutations cannot receive this guarantee.
- Add a regression test proving that the first
Edit/Writecannot modify a nested subtree before its newly discovered instructions become visible.
Additional information
The existing implementation already handles many difficult edges well: per-agent deduplication, restore/resume seeding, concurrent discovery, instruction-file change announcements, symlinks, Windows paths, and not-yet-created directories. This report is intentionally limited to the remaining pre-mutation ordering gap.
For comparison, Claude Code documents that nested CLAUDE.md files are loaded on demand when it reads files in those subdirectories. Codex documents only project-root-to-cwd discovery and does not claim child-on-access enforcement. The issue here is therefore not that Kimi must copy another product; it is that Kimi's own reminder promises “before making changes” while its hook runs after the first change.
- Claude Code: how
CLAUDE.mdfiles load - Codex: AGENTS.md discovery
- Related implementation: #2545
- Related project-navigation report: #489
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with packages/agent-core-v2/src/agent/agentsMdReminder/agentsMdReminderService.ts and toolExecutor/toolExecutorService.ts to trace discovery and hook ordering. Review bashTargets.ts and reproduce the nested-subtree Write or Edit case; done means a regression test proves the first mutation cannot occur before the relevant AGENTS.md guidance is visible, with Bash behavior explicitly covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100