This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

wrapperModules.claude-code: wipe stale per-project keys in ~/.claude.json

Adds projectStateWipeKeys (default [ "mcpServers" ]). preHook rewrites
~/.claude.json via jq on every invocation, deleting the listed keys
from each projects.<dir> entry. Purges stale `claude mcp add`
registrations that pin GC-able /nix/store paths and shadow the
canonical set the wrapper writes via --settings. Empty list disables
the step.

+48 -10
+48 -10
wrapperModules/claude-code/flake-module.nix
··· 268 268 ''; 269 269 }; 270 270 271 + projectStateWipeKeys = lib.mkOption { 272 + type = lib.types.listOf lib.types.str; 273 + default = [ "mcpServers" ]; 274 + description = '' 275 + Keys to delete from every `projects.<dir>` entry of 276 + `~/.claude.json` on each invocation. Use this to purge 277 + unmanaged runtime drift that the wrapper otherwise can't 278 + override — most notably stale `mcpServers` registrations 279 + created by `claude mcp add`, which pin GC-able `/nix/store` 280 + paths and shadow the canonical set the wrapper writes via 281 + `--settings`. 282 + 283 + Anything not listed here is left alone, so new fields 284 + claude-code may add in future versions are preserved by 285 + default. Set to `[ ]` to disable the cleanup step. 286 + ''; 287 + }; 288 + 271 289 claudeMdMergeThreshold = lib.mkOption { 272 290 type = lib.types.float; 273 291 default = 0.15; ··· 310 328 order = 101; 311 329 }; 312 330 313 - config.preHook = lib.optionalString (config.claudeMd != null) '' 314 - CLAUDE_MD_DIR="''${CLAUDE_MD_DIR:-$HOME/.claude}" 315 - mkdir -p "$CLAUDE_MD_DIR" 316 - touch "$CLAUDE_MD_DIR/CLAUDE.md" 317 - ${levenshtein}/bin/levenshtein-merge merge \ 318 - ${config.claudeMd} \ 319 - "$CLAUDE_MD_DIR/CLAUDE.md" \ 320 - ${toString config.claudeMdMergeThreshold} \ 321 - || echo "levenshtein merge failed; leaving CLAUDE.md untouched" >&2 322 - ''; 331 + config.preHook = 332 + lib.optionalString (config.claudeMd != null) '' 333 + CLAUDE_MD_DIR="''${CLAUDE_MD_DIR:-$HOME/.claude}" 334 + mkdir -p "$CLAUDE_MD_DIR" 335 + touch "$CLAUDE_MD_DIR/CLAUDE.md" 336 + ${levenshtein}/bin/levenshtein-merge merge \ 337 + ${config.claudeMd} \ 338 + "$CLAUDE_MD_DIR/CLAUDE.md" \ 339 + ${toString config.claudeMdMergeThreshold} \ 340 + || echo "levenshtein merge failed; leaving CLAUDE.md untouched" >&2 341 + '' 342 + + lib.optionalString (config.projectStateWipeKeys != [ ]) '' 343 + CLAUDE_JSON="$HOME/.claude.json" 344 + if [ -f "$CLAUDE_JSON" ]; then 345 + CLAUDE_JSON_TMP=$(mktemp "$CLAUDE_JSON.XXXXXX") 346 + if ${pkgs.jq}/bin/jq \ 347 + --argjson wipe ${lib.escapeShellArg (builtins.toJSON config.projectStateWipeKeys)} ' 348 + if .projects then 349 + .projects |= with_entries( 350 + .value |= reduce $wipe[] as $k (.; del(.[$k])) 351 + ) 352 + else . end 353 + ' "$CLAUDE_JSON" > "$CLAUDE_JSON_TMP"; then 354 + mv "$CLAUDE_JSON_TMP" "$CLAUDE_JSON" 355 + else 356 + rm -f "$CLAUDE_JSON_TMP" 357 + echo "claude.json projects-state cleanup failed; leaving file untouched" >&2 358 + fi 359 + fi 360 + ''; 323 361 324 362 config.meta.maintainers = [ 325 363 {