anthropics / anthropics/skills

Skill Creator causes config file corruption

Đang mở
#702 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
176k
Fork
20.8k
Merge trung bình
7 giờ 21 phút
Pull request đã merge (30 ngày)
5

Mô tả

# Config file corruption from race condition in `.claude.json` writes

When trying to use skill-creator, my .claude.json file keeps getting corrupted.

This requires me to re-authenticate and go through the new user process (select color theme etc.)

Super annoying.. This has happened to me a few times this month. I tasked claude with digging into it and here is what it came
up with:

## Summary

`.claude.json` gets corrupted during high-frequency file system activity, particularly when using the skill-creator plugin. The corruption pattern indicates a non-atomic write path that races with the normal atomic (temp+rename) writer.

## Environment

- macOS (Darwin 24.6.0, APFS)
- Claude Code 2.1.68
- Bun runtime
- skill-creator plugin (`claude-plugins-official`, SHA 205b6e0b3036)

## Reproduction

1. Run the skill-creator skill
2. Trigger an eval run that creates many skill variant files (e.g. `run_loop --eval-set ... --skill-path ... --max-iterations 5`)
3. The burst of file watcher events corrupts `.claude.json`

This has reproduced across two separate sessions on different days.

## Evidence

### Corruption event 1 — non-truncating overwrite

**Debug log:** `460373ba-77a2-4343-93de-aa60fc0a8e89.txt`
**Corrupted backup:** `.claude/backups/.claude.json.corrupted.1772660609610`

Two atomic writes complete 2ms apart (both 1540 bytes, both logged as "File written atomically"). 282ms later, the config read fails with `JSON Parse error: Unable to parse JSON string`.

The backed-up file shows valid JSON (1540 bytes) followed by leftover bytes from a previous longer version of the file:

```
"Read": {
"usageCount": 2,
"lastUsedAt": 1772660585557
}
}
}660585557
}
}
}
```

The trailing `}660585557\n }\n }\n}` is the tail of the prior file content that was not truncated. This cannot result from a temp+rename write — it requires a direct write to the file without `O_TRUNC`.

### Corruption event 2 — truncated file during skill change burst

**Debug log:** `002a629a-fb26-4c32-b7b2-5418aa647bdb.txt`
**Corrupted backup:** `.claude/backups/.claude.json.corrupted.1772753956833`

~50 `Detected skill change` events fire within 3 seconds while the skill-creator eval writes variant files. The corruption (`JSON Parse error: Unexpected EOF`) occurs with **no logged config write** preceding it — the write that corrupted the file did not go through the atomic write path and was not logged.

The error stack trace originates from a `node:events` `emit` call, indicating a file watcher callback triggered the corrupting read/write cycle.

## Root cause analysis

There appear to be two write paths to `.claude.json`:

1. **Atomic path** (temp file + rename): logged as "Writing to temp file" / "File written atomically". This path works correctly.
2. **Non-atomic path**: triggered by file watcher callbacks (skill change events, possibly others). This path writes directly to the file without truncation and without debug logging. It races with the atomic path and with itself.

Evidence for a second write path:
- Corruption event 1 produces a file with old bytes at the end, which is impossible with rename-based atomic writes
- Corruption event 2 has no logged write before the corruption, yet the file is corrupted
- Both events correlate with high-frequency file watcher activity

## Impact

- Config is reset to defaults, losing `projects`, `toolUsage`, `tipsHistory`, `clientDataCache`, and other state
- The corruption is automatically detected and a backup is saved, but the reset is disruptive

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.