Skip to content

fix(hooks): resolve a relative CLAUDE_CONFIG_DIR against CLAUDE_PROJECT_DIR - #4719

Open
gaurav0107 wants to merge 1 commit into
rtk-ai:developfrom
gaurav0107:fix/4676-hook-claude-a-relative-claude-config-dir
Open

gaurav0107 wants to merge 1 commit into
rtk-ai:developfrom
gaurav0107:fix/4676-hook-claude-a-relative-claude-config-dir

Conversation

@gaurav0107

Copy link
Copy Markdown
Contributor

Summary

Fixes #4676

  • Claude Code resolves a relative CLAUDE_CONFIG_DIR (.claude-work, or a literal ~/.claude no shell expanded) against the directory it was launched from, and keeps reading that file after the agent cds. Each PreToolUse hook starts in the agent's current directory, so the permission loader resolved the same value against a different base. After cd sub, rtk hook claude and rtk rewrite found no settings.json, missed the user's deny rules, and rewrote denied commands (the deny turned into an approval prompt).
  • get_settings_paths now passes the resolved Claude dir through anchor_to_launch_dir, which joins a relative value onto CLAUDE_PROJECT_DIR. That is the launch directory Claude Code passes to hooks (as the issue notes, it is not the git root).
  • Unchanged: an absolute or unset CLAUDE_CONFIG_DIR, and any run without an absolute CLAUDE_PROJECT_DIR, such as rtk discover from a shell. Only permission loading changes. resolve_claude_dir and its other callers (rtk init, hook status, telemetry, discover's history lookup) still resolve against the process's directory, matching Claude Code there, per init: CLAUDE_CONFIG_DIR is used as given when relative or holding a literal ~ #4247.

Test plan

  • New unit tests in src/hooks/permissions.rs:
    • test_anchor_to_launch_dir_joins_a_relative_dir_to_the_launch_dir (.claude-work and literal ~/.claude)
    • test_anchor_to_launch_dir_keeps_an_absolute_dir
    • test_anchor_to_launch_dir_without_a_usable_launch_dir (unset, empty, relative CLAUDE_PROJECT_DIR)
    • test_get_settings_paths_resolves_a_relative_config_dir_against_the_project_dir: sets both variables through user_env::with_vars. It fails on develop, where the path stays relative to the cwd.
  • Manual check on Linux with develop and this branch built side by side. Setup: an isolated HOME, proj/~/.claude/settings.json holding {"permissions":{"deny":["Bash(git status)"]}}, CLAUDE_CONFIG_DIR='~/.claude', CLAUDE_PROJECT_DIR=<abs>/proj:
hook cwd develop: rtk rewrite "git status" / rtk hook claude this PR
proj exit 2 (deny) / no output exit 2 / no output
proj/sub exit 3, rtk git status / updatedInput: rtk git status exit 2 / no output
  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets, cargo clippy --no-default-features --all-targets (clean)
  • cargo test --all (lib: 4,391 passed, 8 ignored) and cargo test --no-default-features (lib: 4,227 passed, 8 ignored)

🤖 Opened with Superhuman, an open-source contribution agent.

…CT_DIR

Claude Code uses CLAUDE_CONFIG_DIR as given, so a relative value (or a
literal `~` no shell expanded) resolves against the directory it was
launched from, and it keeps reading that file after the agent `cd`s.
Each PreToolUse hook starts in the agent's current directory, so the
permission loader resolved the same value against a moving base: after
`cd sub`, `rtk hook claude` and `rtk rewrite` found no settings.json,
missed the user's deny rules, and rewrote denied commands.

Anchor a relative config dir to CLAUDE_PROJECT_DIR, the launch
directory Claude Code passes to hooks, when loading permission rules.
An absolute or unset CLAUDE_CONFIG_DIR, and runs without an absolute
CLAUDE_PROJECT_DIR, behave as before. Other resolve_claude_dir callers
(rtk init, hook status, discover) are unchanged.

Fixes rtk-ai#4676
@CLAassistant

CLAassistant commented Oct 21, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added bug Something isn't working hooks security labels Oct 21, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Fixes a bug where a relative CLAUDE_CONFIG_DIR was resolved against the hook process's current directory instead of the agent's launch directory, causing permission settings.json to be missed after a cd and deny rules to be silently bypassed. The fix adds an anchor_to_launch_dir helper that joins a relative Claude config dir onto CLAUDE_PROJECT_DIR when resolving settings paths for permission loading, leaving other resolve_claude_dir callers unchanged.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4676


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@gaurav0107
gaurav0107 marked this pull request as ready for review November 29, 2026 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working hooks security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hook claude: a relative CLAUDE_CONFIG_DIR is resolved against the hook's cwd, so deny rules are lost after the agent cds

2 participants