Skip to content

fix(claude-code): settings.json / CLAUDE.md を symlink からコピー配備に変更 - #52

Merged
thinceller merged 1 commit into
masterfrom
fix/claude-code-copy-deploy
Aug 8, 2026
Merged

fix(claude-code): settings.json / CLAUDE.md を symlink からコピー配備に変更#52
thinceller merged 1 commit into
masterfrom
fix/claude-code-copy-deploy

Conversation

@thinceller

Copy link
Copy Markdown
Owner

背景

~/.claude/settings.json が rebuild のたびに消える問題の修正。

home-manager が張る nix store への symlink は、store ファイルの mtime が 1970-01-01 固定のため、Claude Code のバックグラウンド housekeeping (retention cleanup) に「期限切れファイル」と判定されて symlink ごと削除される (cleanupPeriodDays = 9999 でも、古さ判定が stat で symlink を辿るため必ず期限切れになる)。fswatch で削除の瞬間と .last-cleanup 更新の一致を観測し、バイナリ内の cleanup 実装 (stat → mtime 比較 → unlink) も確認済み。2026-06〜07 に ~/.claude/CLAUDE.md (user memory) が消えていた件 (check-user-memory hook 導入の経緯) も同根。

また、read-only symlink のままでは Claude Code / デスクトップアプリからの設定書き込みも全て失敗していた (デスクトップアプリは /nix/store/...tmp への EACCES をログに記録、CLI の /config トグルは無反応)。

既知の関連報告 (nix store symlink の settings.json が壊れる件。auto-reference 回避のため code span):

  • https://github.com/anthropics/claude-code/issues/52525 (sandbox 起動失敗、not planned でクローズ)
  • https://github.com/anthropics/claude-code/issues/55485 (HM 管理下で設定変更不可)
  • https://github.com/anthropics/claude-code/issues/15786 (多段 symlink で atomic write が EACCES)

変更内容

  • deploy.nix (新規): upstream モジュールの home.file 配備を enable = false で無効化し、activation (linkGeneration 後) で settings.json / CLAUDE.md を通常ファイルとして install。前回配備内容を ~/.claude/.nix-deployed-* に baseline として保持し、Claude が実行時に書いた変更 (drift) があれば rebuild 時に *.drift へ退避して警告。claude-config-drift コマンドで baseline と現状の差分 (jq 正規化 diff) を確認し、dotfiles へ手で取り込める
  • common.nix (新規): darwin (default.nix) と oberon (server.nix) で重複していた settings を共通化。両エントリはホスト固有差分のみに
  • upstream の home-manager master (darwin) / release-25.11 (oberon) の home.file キー差異 (絶対/相対パス) は deploy.nix 内で吸収

検証

  • nix build .#darwinConfigurations.kohei-m4-mac-mini.system --no-link
  • nix build .#darwinConfigurations.SC-N-843.system --no-link
  • nix eval --raw .#nixosConfigurations.oberon.config.system.build.toplevel.drvPath
  • nix fmt clean ✅
  • 生成される settings.json / CLAUDE.md の内容は全ホストで変更前と同一 (store path 一致で確認: a1jy259c…-claude-code-settings.json 等)
  • 新 generation の home-files/.claude/ から settings.json / CLAUDE.md が消え、activateclaudeDeploy 呼び出しが入ることを確認

🤖 Generated with Claude Code

home-manager が張る nix store への symlink は store ファイルの mtime が
1970 のため、Claude Code の retention cleanup (housekeeping) に
「期限切れ」と判定されて削除される (cleanupPeriodDays=9999 でも、
判定が stat で symlink を辿るため)。また read-only symlink のままでは
Claude 本体・デスクトップアプリからの設定書き込みも全て失敗する。
2026-06〜07 の ~/.claude/CLAUDE.md (user memory) 消失も同根。

- deploy.nix: upstream モジュールの home.file 配備を enable=false で
  無効化し、activation (linkGeneration 後) で通常ファイルとして
  install。前回配備内容を baseline として保持し、Claude が実行時に
  書いた変更は *.drift へ退避。claude-config-drift で差分確認できる
- common.nix: darwin (default.nix) / oberon (server.nix) で重複していた
  settings を共通化。生成される settings.json の内容は全ホストで
  変更前と同一 (store path 一致で確認)

参考: anthropics/claude-code の issue 52525 / 55485 / 15786
(nix store symlink の settings.json が壊れる既知報告)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

Nix Diff

Compare changes

kohei-m4-mac-mini

Attribute: darwinConfigurations.kohei-m4-mac-mini.system

Diff Output
<<< /nix/store/9ygx0z9x61i1ll4v7yz81s61gw2xhjbh-darwin-system-26.11.d8a6661.drv
>>> /nix/store/8w7ka7fidic8ldzsx8igw7l3p2saycsm-darwin-system-26.11.d8a6661.drv

ADDED
[A.] claude-config-drift                  <none>
[A.] claude-config-drift-fish-completions <none>
[A.] user-memory.md                       <none>

REMOVED
[R.] hm_usermemory.md                     <none>

PATHS: 14368 -> 14370 (+18, -16)
SIZE: 399 MiB -> 399 MiB
DIFF: 8.59 KiB

SC-N-843

Attribute: darwinConfigurations.SC-N-843.system

Diff Output
<<< /nix/store/wl6l4zhydb903ipi33ksn136k8q7dl56-darwin-system-26.11.d8a6661.drv
>>> /nix/store/sfpjs4xi36bqv8n06kcsqyfy45i355q3-darwin-system-26.11.d8a6661.drv

ADDED
[A.] claude-config-drift                  <none>
[A.] claude-config-drift-fish-completions <none>
[A.] user-memory.md                       <none>

REMOVED
[R.] hm_usermemory.md                     <none>

PATHS: 12656 -> 12658 (+18, -16)
SIZE: 280 MiB -> 280 MiB
DIFF: 8.59 KiB

📄 View diff as HTML in the Artifacts section


Generated by nix-diff-action using dix

@thinceller
thinceller merged commit 3b59020 into master Aug 8, 2026
4 checks passed
@thinceller
thinceller deleted the fix/claude-code-copy-deploy branch August 8, 2026 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant