claude-usage-limits 1.11.7 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,15 +46,14 @@ function readState() {
46
46
  }
47
47
  }
48
48
 
49
+ // Atomic, because this file is read, changed and written back by the Stop hook
50
+ // of every session at once. A torn read here did not just lose one total: the
51
+ // reader parsed nothing, then wrote its own slot back as the whole file, and
52
+ // every other session's tally went with it.
49
53
  function writeState(all) {
50
- try {
51
- const file = stateFile();
52
- fs.mkdirSync(path.dirname(file), { recursive: true });
53
- fs.writeFileSync(file, JSON.stringify(all), 'utf8');
54
- } catch (err) {
55
- // Losing the total costs one re-read of the transcript. Failing the hook
56
- // that runs after every reply is not worth avoiding that.
57
- }
54
+ // Never throws: losing the total costs one re-read of the transcript, and
55
+ // failing the hook that runs after every reply is not worth avoiding that.
56
+ usage.writeJsonAtomic(stateFile(), all);
58
57
  }
59
58
 
60
59
  function isSession(value) {