Summary
Claude Code versions 2.1.63 through 2.1.83 contain a flaw in the folder trust determination logic that blindly relies on the git worktree commondir file without validating its contents.
A malicious repository can abuse this to impersonate a previously trusted path, causing Claude Code to skip its trust confirmation dialog and immediately execute hooks defined in .claude/settings.json when a victim opens the repo.
Affected context
This vulnerability affects environments where Claude Code is used inside Git repositories that may be cloned from untrusted or semi-trusted sources.
The issue appears when:
- The project is a Git worktree or otherwise contains a
commondirfile, - Claude Code uses the
commondirfile to determine the effective folder trust root, and - The user has previously trusted another directory on the same system.
In such cases, a crafted repository can cause Claude Code to incorrectly treat the current folder as already trusted and automatically execute defined project hooks.
Exploit preconditions
- Attack surface: Local developer workstation running Claude Code on cloned repositories.
- Required access: The attacker must convince the victim to clone or otherwise open a malicious Git repository containing a crafted
commondirfile. - Trigger point: The victim opens the malicious repository in Claude Code and the extension performs its folder trust determination based on the
commondirfile. - Additional knowledge: The attacker must know or reasonably guess a filesystem path that the victim has previously marked as trusted in Claude Code.
- Why exploitation is possible: Claude Code implicitly trusts the path referenced in the
commondirfile without validating that it is a legitimate worktree relationship or verifying that the current folder itself has been explicitly trusted by the user.
Why this happens
The core issue is improper input validation of metadata used in security decisions (CWE-20).
Claude Code treats the contents of the Git worktree commondir file as a reliable indicator of a previously trusted directory, without checking that:
- The path actually represents a legitimate Git worktree relationship, and
- The current repository itself has gone through the normal trust-confirmation flow.
By accepting this unvalidated, attacker-controlled path as a trust anchor, the application misapplies trust state, effectively extending trust from one folder to another unrelated one.
In this mis-trusted state, project-defined hooks in .claude/settings.json can execute without explicit user confirmation, creating a path for local code execution that bypasses intended safeguards.
Potential impact
- Claude Code may execute project hooks in
.claude/settings.jsonwithout displaying the usual trust confirmation prompt. - Attacker-controlled scripts or commands configured as hooks could run with the victim's local user privileges.
- Local files and source code could be read, modified, or exfiltrated by malicious hook logic.
- Developer tooling configuration and workflows may be silently altered, leading to longer-term supply-chain style compromise.
- Subsequent repositories or builds may be poisoned through modified configuration, tasks, or generated artifacts.
General mitigation guidance
Effective mitigations focus on treating trust metadata as untrusted input and enforcing explicit trust boundaries:
- Validate and constrain all paths read from Git metadata such as
commondirbefore using them in security-sensitive logic. - Ensure that trust decisions are based on the actual directory being opened, not merely on indirect references from files that may be attacker-controlled.
- Require an explicit trust confirmation for each distinct working directory, even if it appears related to a previously trusted path.
- Normalize and canonicalize filesystem paths before comparison to avoid path spoofing or aliasing issues.
- Reduce the power of project hooks by applying least-privilege principles, such as limiting what they can access or execute and requiring explicit user opt-in for more sensitive actions.
- Treat configuration files like
.claude/settings.jsonas untrusted until the user has clearly acknowledged and accepted the associated project.
How teams detect issues like this
Detection is most effective when combining code-level analysis with behavioral monitoring:
- Perform static analysis on the folder trust logic to flag places where external metadata (e.g., Git files like
commondir) is used without normalization, validation, or cross-checking. - During code review, look for trust decisions based on relative or indirect paths, and ensure reviewers confirm that all such inputs are validated and tied to the actual working directory.
- Introduce internal security linting rules or policies that highlight uses of Git metadata in security-sensitive features (trust prompts, hook execution, sandbox boundaries).
- Add runtime logging around trust decisions and hook execution, capturing which path was considered trusted and why, and periodically review logs for anomalous trust inheritance.
- Use automated code review or SAST tools configured with rules for CWE-20-style issues, focusing on validation of path-based inputs and trust state propagation.

