Skip to content

init: CLAUDE_CONFIG_DIR is used as given when relative or holding a literal ~ #4247

Closed as not planned

Description

@KuSh

resolve_claude_dir_from (src/hooks/init/mod.rs) returns CLAUDE_CONFIG_DIR as-is whenever it is non-empty. A relative value, or one holding a ~ the shell never expanded (quoted in an env file, set in a GUI launcher), resolves against the current directory.

On develop (c50ff30d), run from a project directory with a fresh HOME:

CLAUDE_CONFIG_DIR result
~/.claude (literal) exit 1, Failed to create temp file in ~/.claude
.claude, missing exit 1, same error
.claude, exists in the project exit 0, writes ./.claude/{RTK.md,CLAUDE.md,settings.json} and reports a global install

Once #2521 lands, the first two also exit 0 and create ./~/.claude/ or ./.claude/ in the project.

Options: reject non-absolute values with an error naming the variable, or expand a leading ~ and then reject anything still relative. resolve_codex_dir_from uses the same non-empty filter on CODEX_HOME; the Hermes, Droid, Copilot and Pi resolvers are worth checking at the same time.

Activity

  1. rtk-wshm-sync-bot commented on Sep 25, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 90%

    Summary

    resolve_claude_dir_from (and likely codex/hermes/droid/copilot/pi resolvers) accepts relative paths and unexpanded literal ~ for CONFIG_DIR env vars, causing wrong-directory writes or misleading global-install reports; should reject or properly expand/validate.

    📁 Relevant files
    • src/hooks/init/mod.rs

    Suggested Actions

    1. Fix resolve_claude_dir_from in src/hooks/init/mod.rs to reject relative paths and expand leading ~
    2. Audit resolve_codex_dir_from (CODEX_HOME) for the same non-empty-only filter bug
    3. Check Hermes, Droid, Copilot, and Pi resolvers for the identical issue
    4. Coordinate with fix(init): create Claude config dir for global init #2521 since its landing changes the failure mode from exit 1 to silent wrong-directory writes

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

  2. KuSh commented on Oct 20, 2026

    @KuSh
    CollaboratorAuthor

    Closing as not planned, and I apologise: this issue was wrong.

    Claude Code reads CLAUDE_CONFIG_DIR exactly as set (process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), ".claude")). That holds in every release from 0.2.9 to 2.1.304, on Linux and Windows, including 2.1.283, the current release when I opened this. A literal ~ or a relative value resolves against the directory Claude Code was launched from: started in proj/ with CLAUDE_CONFIG_DIR='~/.claude', it loads proj/~/.claude/settings.json. So the three rows in the table above are rtk agreeing with Claude Code. Expanding or rejecting the value, as #4261 did at my suggestion, makes rtk init install where Claude Code never looks and makes the hook miss the user's deny rules.

    One real problem came out of checking this: rtk's hook resolves a relative value against its own working directory, which moves when the agent cds, while Claude Code keeps the launch directory. That is now #4676.

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