---
name: claudejson-write-hazard
description: "NEVER open-truncate ~/.claude.json (or any trust/config store) — 2026-07-04 my pretrust json.dump(open(p,'w')) crashed on ENOSPC mid-write and WIPED the box trust store (16 projects → 0). Always write-temp + os.replace."
metadata: 
  node_type: memory
  type: feedback
  originSessionId: fd0a5f34-2e68-404b-b6f6-e440c02f0a22
---

2026-07-04: my rig pretrust helper wrote `json.dump(d, open(p,'w'))` straight onto `~/.claude.json`. The box hit transient ENOSPC mid-dump → file truncated to 0 bytes → CC quarantined + regenerated a MINIMAL store → operator lost all project trust/settings (16 entries); subsequent probe spawns silently failed unbound (F-026 trust-wedge, environmental edition). Recovered by merging a Jun-23 quarantine copy back in (`~/.claude/backups/.claude.json.corrupted.*` — quarantines double as the only long-horizon backups; recent `.backup.*` rotate every ~1min and were all post-wipe).

**Why:** `open(p,'w')` truncates BEFORE writing; any mid-write failure (ENOSPC, kill, crash) destroys the file. The trust store is shared, live-rewritten by running CC sessions, and load-bearing for every headless spawn.

**How to apply:** in every rig/script that edits `~/.claude.json` (or any config store): dump to `p + '.tmp'` in the SAME directory, then `os.replace(tmp, p)` (atomic on NTFS). Snapshot the current file to scratchpad before the first edit of a session. Check free disk before write-heavy runs. Related: [[f027-trust-seam-groundtruth]], [[checkpoint-wake-broken-postclear-forcenative]].
