Skip to content

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

Open

Description

@KuSh

rtk hook claude reads the user's permission rules from $CLAUDE_CONFIG_DIR/settings.json. When CLAUDE_CONFIG_DIR is relative (.claude-work, or a literal ~/.claude that no shell expanded), rtk resolves it against the hook process's working directory. Claude Code resolves it against the directory it was launched from. The two agree until the agent cds: Claude Code then starts each PreToolUse hook in the new directory, rtk looks for settings.json there, finds none, and rewrites commands that the user's deny rules cover.

Reproduced with Claude Code 2.1.304 against a mock API, with rtk built from develop 6c1af5f. Setup: CLAUDE_CONFIG_DIR='~/.claude', launched from proj/, with {"permissions":{"deny":["Bash(git status)"]}} and rtk hook claude as the PreToolUse hook, both in proj/~/.claude/settings.json.

Bash calls payload cwd / hook pwd CLAUDE_PROJECT_DIR rtk hook Claude Code result for git status
git status proj proj no output Permission to use Bash with command git status has been denied.
cd sub, then git status proj/sub proj updatedInput: rtk git status This command requires approval

Claude Code itself keeps using proj/~/.claude after the cd: it creates no proj/sub/~. The deny becomes a prompt for rtk git status, which an interactive user can accept.

CLAUDE_PROJECT_DIR is the launch directory, not the git root: launched from repo/sub, it is repo/sub. That makes it the base Claude Code uses for a relative CLAUDE_CONFIG_DIR. Resolving a relative value against it in the hook path, and against the process's directory elsewhere, would make rtk read the same file as Claude Code. An absolute or unset CLAUDE_CONFIG_DIR is not affected.

Context: #4247 (closed) asked to expand or reject such values. Claude Code accepts them as given, so rtk has to resolve them the way Claude Code does.

Activity

  1. rtk-wshm-sync-bot commented on Oct 20, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 90%

    Summary

    Relative CLAUDE_CONFIG_DIR is resolved against the hook's cwd instead of CLAUDE_PROJECT_DIR, so deny rules silently become prompts after an agent cds.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/hook/claude.rs
    • src/permissions/loader.rs

    Suggested Actions

    1. Resolve relative CLAUDE_CONFIG_DIR against CLAUDE_PROJECT_DIR in the hook path, matching Claude Code's behavior
    2. Add a regression test: hook invoked from a subdirectory after cd sub must still find proj/.claude/settings.json
    3. Cross-check against rtk hook claude: git refused in sessions isolated in a worktree outside .claude/worktrees/ #4634 and rtk hook check ignores pipeline rules: it reports a rewrite for commands the hook denies or passes through #4629, which also involve hook path/cwd resolution after worktree/cd changes
    4. Verify fix doesn't affect absolute or unset CLAUDE_CONFIG_DIR cases per the report

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions