Instruction precedence in Claude Code is the order in which layered instruction files are read and applied, so a more specific local file can override broader repository guidance. In practice, CLAUDE.md, .claude/CLAUDE.md and CLAUDE.local.md represent different scopes that need clear ownership, review and conflict handling so the agent follows the intended rule set.
How layered instruction files are resolved in Claude Code
Claude Code applies instructions by scope, so the agent reads broader guidance first and then layers on more specific local guidance. The practical effect is that a repository-level rule can be refined or overridden by a closer file when both address the same behaviour. That makes placement, naming and ownership of instruction files part of the control surface.
The useful mental model is precedence, not duplication. If two files say different things, the more specific context should win for the work happening in that repository or subdirectory. If they say the same thing, the repetition adds little, so teams should keep shared rules in one place and local exceptions as narrow as possible.
Because the mechanism is hierarchical, the question is not just what the agent can read, but which instruction should govern a given action. That is why teams should treat What Is Claude Code? Features, Plans, Surfaces and History as the baseline reference for understanding the tool’s surfaces, including the instruction files and settings that shape its behaviour.
Where precedence breaks down in practice
Precedence problems usually come from ambiguity, not from the mechanism itself. If a broad repo rule and a narrow local rule both try to control the same action, the agent may appear to “ignore” one rule when it is actually following the more specific one. That is a governance problem as much as a tooling problem, because unclear ownership makes it hard to prove which instruction should have applied.
Another common failure mode is hidden drift. Local overrides accumulate over time, especially when teams add quick fixes in subfolders or personal settings, and the resulting rule set becomes difficult to review. In agentic coding environments, that can produce inconsistent decisions across branches, services or contributors, which is why AI Coding Agents Security Guide is a useful companion for understanding how instruction files, permissions and sandboxing interact.
A second control issue is that instruction precedence can affect security posture just as much as developer workflow. If a more local file relaxes a safeguard, the agent can inherit a less restrictive operating mode than the team intended. The same pattern is why AI IDE and Coding Agent Security Guide matters for this topic, because it focuses on managed settings, allow and deny lists, and the practical boundary between repository policy and local override.
How teams should manage instruction ownership
Instruction precedence works best when ownership is explicit. Repository-wide guidance should cover the default rule set, while subdirectory or local files should exist only when there is a clear reason to deviate. That keeps the hierarchy understandable and makes it easier to review changes without guessing which file is authoritative.
Teams should also decide which instructions are normative and which are convenience settings. When an instruction changes the agent’s behaviour in a way that affects code quality, approvals, tool use or safety checks, it needs the same review discipline as code. For the broader pattern of securing coding assistants and agents, AI Coding Tools Hub is a useful navigation point for comparing surfaces and lifecycle choices across tools.
The most reliable practice is to keep exceptions narrow and documented. If a local rule exists to support one workflow, name that workflow clearly and avoid letting the exception become the new default. If the agent’s behaviour has to differ across directories, make that difference intentional, reviewable and easy to remove when the need passes.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP ASVS, NIST SP 800-53 Rev 5 and NIST CSF 2.0 set the technical controls, while ISO/IEC 27001:2022 defines the regulatory obligations.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP ASVS | V15 — Secure Architecture | Instruction hierarchy affects agent behavior design and override boundaries. |
| Recommendation — Define and review layered instruction precedence so local overrides cannot undermine intended agent behavior. | ||
| NIST SP 800-53 Rev 5 | CM-3 — Configuration Change Control | Local instruction files change operational behavior and need controlled review. |
| Recommendation — Treat instruction-file changes as controlled configuration changes with review and approval. | ||
| NIST CSF 2.0 | GV.PO-01 — Policies, processes, and procedures are established, communicated, and maintained | Repo instructions function as policy artifacts that need ownership and maintenance. |
| Recommendation — Maintain clear, versioned instruction policies with defined ownership for each scope. | ||
| ISO/IEC 27001:2022 | A.5.15 — Access control | Scoped instructions act as governing controls over what the agent may do. |
| Recommendation — Limit and document local instruction overrides to the minimum required scope. | ||
Practitioner Guidance
What to verify: Confirm which file is supposed to govern the exact directory or task before you troubleshoot the agent’s output. If the behaviour seems wrong, check for a closer instruction file before assuming Claude Code ignored the broader one.
Common mistake: Teams often treat precedence as a convenience feature and then let local overrides multiply. That creates silent policy drift, especially when contributors add “temporary” exceptions that are never removed.
Decision rule: If the instruction changes safety, permissions, review requirements or tool behaviour, it should be owned and reviewed like policy, not improvised like a personal preference.
Practitioner takeaway: Instruction precedence is only safe when hierarchy and ownership are clear, because the local rule that solves one edge case can quietly become the rule the agent follows everywhere nearby.
Related resources from NHI Mgmt Group
- How should security teams handle credential precedence when routing Claude Code through an AI gateway?
- What breaks when malicious instructions are embedded in a Claude Code project file?
- What breaks when Claude Code hooks are left as local developer settings?
- What signals show that Claude Code or similar tools are operating outside governance boundaries?
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 25, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org