Observed Signal · Aug 9, 2026 · Technical Release · Source: DEV Community · Impact: 2/5 · Sentiment: Positive
Large Language Models (LLM) & AI Market: Stop Claude Code agent writing outside directory
The article explains two complementary guardrails for preventing unattended Claude Code agents from writing files outside an intended directory: declarative permission rules in settings.json (permissions.deny) and a programmatic PreToolUse hook that inspects pending tool calls and can deny writes. It details how deny/allow precedence makes an allow-list impossible with permissions.deny alone, shows a Node.js hook implementation that defers on malformed payloads and denies out-of-scope writes, and warns that hooks cannot see writes from Bash commands, subagents, or generated build artefacts. As a post-hoc check, the author recommends running a git-status diff against an allow-list before committing to catch any changes the hook missed. The piece clarifies these measures are not an OS sandbox and outlines trade-offs such as failing-open behavior.
Practical developer guidance for safely running unattended AI/code agents; useful for engineering teams building agent tooling but not an industry-shifting platform or policy change.
Key Takeaways & Evidence Grounding
- Claude Code uses permission rules in settings.json with Tool(specifier) entries and precedence: deny > ask > allow.
- permissions.deny is a block-list and cannot be used to construct an allow-list for fine-grained in-project write scoping.
- A PreToolUse hook can intercept tool calls (Write, Edit, MultiEdit, NotebookEdit) and return structured JSON with permissionDecision (allow/deny/ask/defer).
- PreToolUse hooks do not see writes originating from Bash command strings, subagents, or generated build artefacts; a git-status diff against an allow-list is recommended as a complementary post-hoc check.
- The author provides example Node.js code that resolves paths safely (using path.relative) and deliberately fails open on malformed payloads.
Connected Companies & Entities
1 Entity mappedOntology Mapping & Concepts
Track Real-Time Market Signals & Shifts
Set up custom watchlists to receive automated, evidence-grounded executive digests whenever material signals or shifts occur across your tracked landscape.
