Skip to content

bug(init): global Claude init fails when ~/.claude is missing #2519

Description

@elite133713

Bug report

Summary

rtk init -g fails on a fresh user profile when the Claude config directory does not already exist.

The failure occurs before RTK can create RTK.md because the atomic write implementation creates a temporary file inside the target file's parent directory, and that parent directory is missing.

Steps to reproduce

Run global init on a machine or temp home where ~/.claude does not exist:

rm -rf ~/.claude
rtk init -g

Equivalent isolated reproduction:

tmp=$(mktemp -d)
HOME="$tmp/home" CLAUDE_CONFIG_DIR="$tmp/.claude" rtk init -g --auto-patch

Actual behavior

rtk: Failed to write RTK.md: /Users/rm-rf/.claude/RTK.md: Failed to create temp file in /Users/rm-rf/.claude: No such file or directory (os error 2)

Expected behavior

rtk init -g should create the missing Claude config directory and then write:

  • ~/.claude/RTK.md
  • ~/.claude/CLAUDE.md
  • ~/.claude/settings.json when patching is enabled

Dry-run mode should continue to report intended writes without creating the directory.

Cause

atomic_write() uses NamedTempFile::new_in(parent), so callers that write into global config paths must ensure the parent directory exists before attempting the atomic write.

Fix PR

Proposed fix: #2518

Related but separate: #1840 addresses the Cursor-only rtk init -g --agent cursor path and missing ~/.cursor; this issue is for plain/global Claude init with missing ~/.claude.

Validation in PR #2518

  • Added regression tests for missing Claude config dir in default global init, hook-only global init, and dry-run.
  • cargo fmt --all --check
  • cargo test missing_claude_dir -- --nocapture
  • cargo test --all (2212 passed, 8 ignored)
  • cargo clippy --all-targets -- -D warnings
  • Manual temp-home check: ./target/debug/rtk init -g --auto-patch

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions