Project-scoped hooks fire on files edited outside the project directory

Resolved 💬 3 comments Opened Feb 11, 2026 by loganrosen Closed Mar 12, 2026

Description

PostToolUse hooks defined in a project's .claude/settings.json fire on all Edit/Write/MultiEdit tool uses, regardless of which file is being edited. This means project-specific linters/formatters get applied to files in completely different repositories.

Reproduction

  1. Open Claude Code with working directory /path/to/project-a/
  2. In /path/to/project-a/.claude/settings.json, define a PostToolUse hook:
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write|MultiEdit",
        "hooks": [
          {
            "type": "command",
            "command": ".venv/bin/ruff format --force-exclude"
          },
          {
            "type": "command",
            "command": ".venv/bin/ruff check --fix --force-exclude"
          }
        ]
      }
    ]
  }
}
  1. Use an additional working directory or just edit a file in a different repo, e.g. /path/to/project-b/src/main.py
  2. The hook fires, applying project-a's ruff config/venv to project-b's file

Impact

In my case, a Python monorepo's ruff hooks (with its own pyproject.toml config for quote style, import sorting, type annotation modernization, etc.) were applied to a file in a completely separate CLI tool repo. This caused ~500 lines of unwanted reformatting (quote style changes, Optional[X]X | None, import reordering, etc.) in the other repo.

Expected Behavior

Hooks defined in <project>/.claude/settings.json should only fire for files whose paths are within <project>/. If I edit /path/to/project-b/src/main.py, hooks from project-a should not apply.

Environment

  • Claude Code (CLI)
  • macOS

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗