You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug(init): global Claude init fails when ~/.claude is missing #2519
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:
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.
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.
Still reproduces on develop (d402152f, and current 5e0f92cd), and it's now blocking a PR.
$ HOME=$(mktemp -d) rtk init -g --auto-patch
rtk: Failed to write RTK.md: $HOME/.claude/RTK.md: Failed to create temp file
in $HOME/.claude: No such file or directory (os error 2)
EXIT=1
Two things worth adding to this issue:
1. It fails on CI, not just fresh user profiles.#4052 added an integration test that exercises rtk init -g, and it fails on windows-latest for exactly this reason — dirs::home_dir() ignores $HOME on Windows, so the test's temp home is bypassed and rtk writes into the runner's real C:\Users\runneradmin\.claude, which doesn't exist:
rtk: Failed to write RTK.md: C:\Users\runneradmin\.claude\RTK.md: Failed to create temp file
in C:\Users\runneradmin\.claude: The system cannot find the path specified. (os error 3)
2. The blast radius is about to grow.#4052 makes --opencode additive, which routes it through this same path. On develop, rtk init -g --opencode works on a machine with no ~/.claude (it skips Claude entirely); with that PR it exits 1 and installs nothing, not even the OpenCode plugin — because RTK.md is written at src/hooks/init.rs:1459, before ensure_opencode_plugin_installed at :1464. OpenCode-only users are precisely the ones without ~/.claude.
Fix, built and verified here (fmt + clippy clean, 3613 lib tests + all integration binaries green):
let claude_dir = resolve_claude_dir()?;if !dry_run {
fs::create_dir_all(&claude_dir).with_context(|| {format!("Failed to create Claude config directory: {}",
claude_dir.display())})?;}
at src/hooks/init.rs:1451 (run_default_mode) and :1249 (the settings.json patch path). run_claude_md_mode_with already does this at :1899, which is why --claude-md is the one global mode that survives today. With the fix, rtk init -g on a bare HOME exits 0 and writes RTK.md + settings.json, and --dry-run still creates nothing.
#2521 is fixed, tested, and ready for review and merge.
It is updated onto current develop. Global init still creates the missing Claude config directory before the atomic write, and dry-run still creates nothing. Verified locally with cargo test missing_claude (3 passed), plus the develop tests that overlapped the merge (utf8_bom, cwd_guard).
write_if_changed and the settings.json patch create the Claude config directory before the atomic write, so rtk init -g on a bare home writes RTK.md and settings.json instead of exiting on the missing parent. Dry-run still creates nothing. --opencode no longer stops before the plugin install: test_global_opencode_installs_when_claude_dir_missing checks that a missing Claude dir still gets RTK.md and ~/.config/opencode/plugins/rtk.ts.
That OpenCode test is Unix-only. dirs::home_dir() follows $HOME on Unix and ignores it on Windows, so the plugin path cannot be pinned with $HOME on windows-latest. The Claude path tests set CLAUDE_CONFIG_DIR, which resolve_claude_dir honors on every OS.
Verified locally: cargo test test_global_opencode_installs_when_claude_dir_missing passed.
Activity
pszymkowiak commentedon Jun 25, 2026
🔍 Automated Triage
bugmediumSummary
rtk init -g crashes on fresh profiles where ~/.claude doesn't exist; fix PR #2521 is already open and should be reviewed/merged.
📁 Relevant files
src/init/mod.rssrc/util/fs.rsTriaged automatically by wshm · This is an automated analysis, not a human review.
fix(init): create parent dir before atomic write on first-run global …
KuSh commentedon Sep 17, 2026
Still reproduces on
develop(d402152f, and current5e0f92cd), and it's now blocking a PR.Two things worth adding to this issue:
1. It fails on CI, not just fresh user profiles. #4052 added an integration test that exercises
rtk init -g, and it fails onwindows-latestfor exactly this reason —dirs::home_dir()ignores$HOMEon Windows, so the test's temp home is bypassed and rtk writes into the runner's realC:\Users\runneradmin\.claude, which doesn't exist:2. The blast radius is about to grow. #4052 makes
--opencodeadditive, which routes it through this same path. Ondevelop,rtk init -g --opencodeworks on a machine with no~/.claude(it skips Claude entirely); with that PR it exits 1 and installs nothing, not even the OpenCode plugin — becauseRTK.mdis written atsrc/hooks/init.rs:1459, beforeensure_opencode_plugin_installedat:1464. OpenCode-only users are precisely the ones without~/.claude.Fix, built and verified here (fmt + clippy clean, 3613 lib tests + all integration binaries green):
at
src/hooks/init.rs:1451(run_default_mode) and:1249(thesettings.jsonpatch path).run_claude_md_mode_withalready does this at:1899, which is why--claude-mdis the one global mode that survives today. With the fix,rtk init -gon a bareHOMEexits 0 and writesRTK.md+settings.json, and--dry-runstill creates nothing.elite133713 commentedon Sep 23, 2026
#2521 is fixed, tested, and ready for review and merge.
It is updated onto current
develop. Global init still creates the missing Claude config directory before the atomic write, and dry-run still creates nothing. Verified locally withcargo test missing_claude(3 passed), plus the develop tests that overlapped the merge (utf8_bom,cwd_guard).elite133713 commentedon Sep 23, 2026
@KuSh this is the failure #2521 fixes.
write_if_changedand thesettings.jsonpatch create the Claude config directory before the atomic write, sortk init -gon a bare home writesRTK.mdandsettings.jsoninstead of exiting on the missing parent. Dry-run still creates nothing.--opencodeno longer stops before the plugin install:test_global_opencode_installs_when_claude_dir_missingchecks that a missing Claude dir still getsRTK.mdand~/.config/opencode/plugins/rtk.ts.That OpenCode test is Unix-only.
dirs::home_dir()follows$HOMEon Unix and ignores it on Windows, so the plugin path cannot be pinned with$HOMEonwindows-latest. The Claude path tests setCLAUDE_CONFIG_DIR, whichresolve_claude_dirhonors on every OS.Verified locally:
cargo test test_global_opencode_installs_when_claude_dir_missingpassed.fix(init): fail closed on missing .claude dir and hoist OpenCode install
fix(init): fail closed on missing .claude dir and hoist OpenCode install