claude-code - 💡(How to fix) Fix Compound `cd && cmd` hook: `git` flagged; `uv`, `find`, `alembic` not flagged [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#56020Fetched 2026-05-05 06:00:16
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×4

The "changes directory before running git" hook intercepts cd ... && git ... patterns. Other cd && compounds with comparable characteristics -- CWD-dependent behavior, path-resolution side effects, potentially irreversible operations -- are not intercepted. Raising as a scope question: is this coverage intentional?

Root Cause

The "changes directory before running git" hook intercepts cd ... && git ... patterns. Other cd && compounds with comparable characteristics -- CWD-dependent behavior, path-resolution side effects, potentially irreversible operations -- are not intercepted. Raising as a scope question: is this coverage intentional?

Code Example

# Hook intercepts this (cd-before-git):
cd /tmp && git status

# Hook does not intercept these:
cd /tmp && uv run python -c "print(1)"
cd /tmp && find . -name "*.py" 2>/dev/null
cd /tmp && alembic upgrade head
RAW_BUFFERClick to expand / collapse

Summary

The "changes directory before running git" hook intercepts cd ... && git ... patterns. Other cd && compounds with comparable characteristics -- CWD-dependent behavior, path-resolution side effects, potentially irreversible operations -- are not intercepted. Raising as a scope question: is this coverage intentional?

Reproduction

# Hook intercepts this (cd-before-git):
cd /tmp && git status

# Hook does not intercept these:
cd /tmp && uv run python -c "print(1)"
cd /tmp && find . -name "*.py" 2>/dev/null
cd /tmp && alembic upgrade head

Expected: either (a) the hook scope is intentionally limited to git commands, in which case the behavior above is by design; or (b) other cd && patterns with similar risk profiles are also in scope for detection.

Observed: only cd && git triggers the hook. The other three forms run without a prompt, even though alembic upgrade head is an irreversible database migration that is equally sensitive to which directory it runs in.

Notes

Several existing issues discuss this hook from the opposite direction -- the prompt is too broad, or misidentifies the risky command: #28240, #30409, #28784, #30213. This report asks the inverse question: should the hook cover non-git commands where the current working directory determines behavior or outcome? No position taken; posting to learn whether the current scope is intentional before raising further.

Environment

  • claude-code version: 2.1.118
  • OS: macOS 26.4.1
  • Shell: /bin/zsh
  • Notes: heavy use of git worktrees and multiple language toolchains

extent analysis

TL;DR

The hook's scope may need to be expanded to cover non-git commands that rely on the current working directory.

Guidance

  • Review the hook's implementation to determine if its scope is intentionally limited to git commands.
  • Investigate existing issues (#28240, #30409, #28784, #30213) to understand the history and design decisions behind the hook.
  • Consider adding support for detecting other cd && patterns that may have similar risk profiles, such as irreversible operations like alembic upgrade head.
  • Evaluate the trade-offs between broadening the hook's scope and potential false positives or misidentifications.

Example

No code snippet is provided as the issue does not contain sufficient information to create a concrete example.

Notes

The issue lacks information about the hook's implementation details, making it difficult to provide a definitive solution. The guidance provided is based on the assumption that the hook's scope is currently limited to git commands.

Recommendation

Apply a workaround by manually expanding the hook's scope to cover non-git commands that rely on the current working directory, as the current behavior may not be intentional.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Compound `cd && cmd` hook: `git` flagged; `uv`, `find`, `alembic` not flagged [1 participants]