Summary
Claude Code contained an input validation flaw that allowed directory changes into protected folders (such as .claude) to be combined with write operations, bypassing the usual write protection and user confirmation requirements.
If an attacker could inject untrusted commands or content into a Claude Code context window, they could cause the tool to create or modify files in sensitive directories without explicit user approval.
Affected context
This vulnerability appears in Claude Code's handling of filesystem operations when acting as an agentic coding tool that can run commands like cd and perform write actions on behalf of the user.
It becomes relevant when:
- The tool is configured to allow file system edits and command-like interactions.
- Protected or special-purpose directories (e.g.,
.claude) exist and are intended to be guarded by confirmation prompts or policy checks. - User or external content in the context window can influence sequences of navigation (
cd) and write operations.
Exploit preconditions
- Attack surface: Claude Code's command and file-edit interface, including automated or semi-automated agent actions.
- Required access: Ability to introduce untrusted content or instructions into the Claude Code context window (e.g., via shared code snippets, pasted instructions, or collaborative inputs).
- Trigger point: A sequence where the tool executes a
cdinto a protected directory followed by a write or file-creation operation that should normally be blocked or confirmed. - Why exploitation is possible: The protection logic validated write operations in isolation but did not robustly validate or re-check the effective directory context after
cd, allowing write policies to be bypassed in certain navigation-plus-write sequences.
Why this happens
The core issue is improper input validation (CWE-20) around directory changes and subsequent write operations.
The system treated navigation commands (cd) and file writes as loosely coupled, validating write operations against expected paths without consistently enforcing or re-evaluating the actual working directory and its protection status.
This created a gap where an attacker-controlled instruction flow could move into a protected directory and then perform writes that bypassed the intended protection or confirmation mechanisms.
While CWE-78 (OS Command Injection) is related at the platform level, the specific behavior here is best characterized as insufficient validation and enforcement of path and directory constraints in the agent's command execution pipeline.
Potential impact
- Creation of new files inside protected or internal configuration directories.
- Modification of existing files in sensitive folders without user confirmation.
- Potential alteration of Claude Code's local configuration, state, or cache files, which may influence future behavior.
- Indirect integrity issues, such as poisoning project metadata or internal tool artifacts stored under protected paths.
- In some environments, possible escalation of the tool's capabilities by modifying scripts or helper files it later executes or reads.
General mitigation guidance
Mitigation generally focuses on strictly enforcing directory and path safety across all file-related operations and ensuring consistent validation of the effective working directory:
- Treat navigation (
cd) and filesystem write operations as part of a single security boundary, and re-validate the actual target path at the time of every write, rename, or delete. - Maintain an explicit allowlist or denylist of directories, and enforce policies using normalized, absolute paths (e.g., resolving symlinks,
..segments, and environment variables before checking). - Require explicit, context-rich user confirmation for any operation targeting protected or internal directories, regardless of how the working directory was reached.
- Design file APIs as higher-level, safe operations (e.g., "edit this known project file") instead of raw shell-like command streams where possible.
- Run tooling with the principle of least privilege, ensuring that the effective account and process do not have broader filesystem access than necessary for normal operation.
How teams detect issues like this
Detection can focus on both source-level patterns and behavioral signals:
- Static analysis / code review:
- Look for places where the working directory is updated separately from path validation, especially where security decisions depend on a presumed location.
- Identify direct use of shell-style commands (
cd,touch,echo > file) that are not wrapped by a central, policy-enforcing file API. - Flag logic that checks directory permissions only at the start of a sequence, without re-checking at the time of the actual write.
- Runtime and logging:
- Enable detailed logging of file operations in protected directories, including when they occur, what command sequence caused them, and whether a user confirmation was recorded.
- Monitor for anomalous writes to internal folders (e.g.,
.claudeand similar) initiated via automated agent actions. - Policy enforcement:
- Use centralized helpers or middleware that intercept all file operations, enforcing directory protections irrespective of higher-level tool logic.
- Integrate automated security tests that attempt navigation plus write sequences to confirm that protections cannot be bypassed.

