fix: prefer CLAUDE_PROJECT_DIR in block-read-outside-cwd#134
Conversation
The policy previously used ctx.session.cwd, which mirrors the live hook cwd and drifts whenever Claude cd's into a subdirectory — so reads at the project root were wrongly denied. Prefer the stable project-root variable that Claude Code sets once per session, and fall back to session.cwd when that variable is unset. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Explain that the boundary is CLAUDE_PROJECT_DIR (stable across the session) with a fallback to session cwd, so users understand reads stay allowed even after Claude cd's into a subdirectory. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 59 minutes and 7 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Summary
block-read-outside-cwdusedctx.session.cwd, which mirrors Claude Code's live hookcwdand drifts whenever Claudecds into a subdirectory. Reads at the project root were wrongly denied once Claude moved into a nested dir.CLAUDE_PROJECT_DIR(the stable project root Claude Code sets once per session) as the boundary; fall back toctx.session.cwdwhen that variable is unset (tests, non-Claude-Code harnesses).blockWorkOnMainis intentionally left onctx.session.cwd— that policy wants the live cwd to detect the current git branch.Files changed
src/hooks/builtin-policies.ts— two-line change inblockReadOutsideCwd.__tests__/hooks/block-read-outside-cwd.test.ts— addedbeforeEach/afterEachto isolate the variable across tests and 5 new cases covering precedence, sibling-dir-after-cd, outside-project denial, fallback, and the Bash tool path.docs/built-in-policies.mdx— clarified the boundary semantics for users.CHANGELOG.md— entry underUnreleased > Fixes.Test plan
bun run test:run— 965/965 unit tests pass, including 5 new casesbun run lint— clean (only a pre-existing unrelated warning)bun run build— successfulbun run test:e2e— to run in CIblock-read-outside-cwd, start Claude at project root, have itcdinto a subdir, then Read a file at the project root — expect allow.Closes the CWD-drift issue surfaced while using a
failproofai-based hook acrossagenteye-62.🤖 Generated with Claude Code