Repository navigation
fix(hooks): resolve a relative CLAUDE_CONFIG_DIR against CLAUDE_PROJECT_DIR - #4719
Open
gaurav0107 wants to merge 1 commit into
Open
gaurav0107 wants to merge 1 commit into
gaurav0107 wants to merge 1 commit into
Conversation
…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
📊 Automated PR Analysis
SummaryFixes 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 Review Checklist
Linked issues: #4676 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
gaurav0107
marked this pull request as ready for review
November 29, 2026 11:00
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4676
CLAUDE_CONFIG_DIR(.claude-work, or a literal~/.claudeno shell expanded) against the directory it was launched from, and keeps reading that file after the agentcds. Each PreToolUse hook starts in the agent's current directory, so the permission loader resolved the same value against a different base. Aftercd sub,rtk hook claudeandrtk rewritefound nosettings.json, missed the user's deny rules, and rewrote denied commands (the deny turned into an approval prompt).get_settings_pathsnow passes the resolved Claude dir throughanchor_to_launch_dir, which joins a relative value ontoCLAUDE_PROJECT_DIR. That is the launch directory Claude Code passes to hooks (as the issue notes, it is not the git root).CLAUDE_CONFIG_DIR, and any run without an absoluteCLAUDE_PROJECT_DIR, such asrtk discoverfrom a shell. Only permission loading changes.resolve_claude_dirand 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
src/hooks/permissions.rs:test_anchor_to_launch_dir_joins_a_relative_dir_to_the_launch_dir(.claude-workand literal~/.claude)test_anchor_to_launch_dir_keeps_an_absolute_dirtest_anchor_to_launch_dir_without_a_usable_launch_dir(unset, empty, relativeCLAUDE_PROJECT_DIR)test_get_settings_paths_resolves_a_relative_config_dir_against_the_project_dir: sets both variables throughuser_env::with_vars. It fails ondevelop, where the path stays relative to the cwd.developand this branch built side by side. Setup: an isolatedHOME,proj/~/.claude/settings.jsonholding{"permissions":{"deny":["Bash(git status)"]}},CLAUDE_CONFIG_DIR='~/.claude',CLAUDE_PROJECT_DIR=<abs>/proj:develop:rtk rewrite "git status"/rtk hook claudeprojproj/subrtk git status/updatedInput: rtk git statuscargo 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) andcargo test --no-default-features(lib: 4,227 passed, 8 ignored)🤖 Opened with Superhuman, an open-source contribution agent.