fix(claude-code): settings.json / CLAUDE.md を symlink からコピー配備に変更 - #52
Merged
Conversation
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>
Nix Diffkohei-m4-mac-miniAttribute: Diff OutputSC-N-843Attribute: Diff Output
Generated by nix-diff-action using dix |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
~/.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)変更内容
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 へ手で取り込めるdefault.nix) と oberon (server.nix) で重複していた settings を共通化。両エントリはホスト固有差分のみに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 fmtclean ✅a1jy259c…-claude-code-settings.json等)home-files/.claude/から settings.json / CLAUDE.md が消え、activateにclaudeDeploy呼び出しが入ることを確認🤖 Generated with Claude Code