[BUG] Claude Code Configuration File Corruption
Summary
Claude Code experiences configuration file corruption that causes repeated crashes and requires manual
intervention to resolve.
Environment
- Claude Code Version: Latest
- Operating System: Linux (Ubuntu-based)
- Node Version: v18+
- Project Type: TypeScript/Node.js application using MCP (Model Context Protocol)
Description
The Claude Code configuration/state files become corrupted during normal operation, leading to:
- Repeated crash loops (1200+ restarts observed)
- Service unavailability
- Manual file deletion required to restore functionality
Steps to Reproduce
- Run Claude Code in a project with active file monitoring
- Allow it to run continuously for several hours/days
- Perform normal development activities (file changes, analysis, etc.)
- Configuration file eventually becomes corrupted
- Service enters crash loop state
Expected Behavior
- Configuration files should remain valid during normal operation
- Service should handle corrupted files gracefully with automatic recovery
- No manual intervention should be required for continuous operation
Actual Behavior
- Configuration/state files become corrupted (invalid JSON)
- Service crashes when attempting to read corrupted files
- PM2 or process manager enters infinite restart loop
- Manual deletion of corrupted files required to restore service
Error Messages
SyntaxError: Unexpected token in JSON at position X
Error: Failed to parse configuration file
Process crashed with exit code 1
PM2: Process restarted 1200+ times
Workaround
Currently requires manual intervention:
# Stop the service
pm2 stop claude-code
# Remove corrupted files
rm -f /tmp/claude-code-state/*.json
rm -f ~/.claude/config/*.json
# Restart service
pm2 restart claude-code
Impact
- Severity: High
- Frequency: Intermittent but recurring
- Service becomes completely unavailable
- Requires manual intervention defeating 24x7 operation goals
- Loss of productivity during downtime
Suggested Fix
- Implement robust error handling for configuration file parsing
- Add file validation before parsing (check file size, basic structure)
- Implement automatic backup/restore mechanism
- Add corruption detection and self-healing
- Use atomic file writes to prevent partial/corrupted writes
Additional Context
- Issue occurs more frequently under high load
- Large project analysis seems to correlate with corruption
- Files grow unbounded until corruption occurs
- No built-in monitoring alerts when corruption happens
Reproduction Files
Example of corrupted configuration structure:
{
"version": "1.0",
"projects": [
{
"path": "/path/to/project",
"analysis": {
// File cuts off here - incomplete JSON
Related Issues
- Service reliability for production use
- Need for high availability architecture
- Lack of automatic recovery mechanisms
---
Note: This issue prevents Claude Code from being used as a reliable 24x7 service without constant manual
monitoring and intervention.
24 Comments
I'm seeing this as well. Seems likely to be a concurrency issue as it happens when I run multiple instances of Claude Code in parallel.
I run around 5-10 instances concurrently and see this happen almost every day. It seems once that json file goes >8MB claude craps out.
Echoing the above — I typically run no more than 2–4 instances at a time. However, every command input is being captured. Since I work extensively with cloud tooling, this results in a wide variety of commands being logged. When I mark these as "always allow," the configuration file quickly fills up and becomes corrupted once it hits around 8MB.
(Running on CC latest on 26.0 Beta)
I run around 2-4 agents concurrently, but usually in different places, so I don't have to run on the same repository/folder. It's on Mac, and I see this failure mode of it corrupting the file. I think that it has to do with file size. I'm noticing this really only when the file gets very large that it will happen.
I usually run about 2-3 instances at a time, but I'm trying to run just one and still running into this bug. Since I saw a spate of logs ever time I launch Claude Code it asks me to reconfigure my environment, starting with light/dark mode, terminal setup, etc.
I've implemented a fix for this configuration corruption issue. The solution includes atomic writes, automatic backups, and recovery mechanisms to prevent crash loops.
PR: #5798
The fix has been tested locally and all tests pass successfully.
lol. I also got a few such PRs from him. Complete untested nonsense.
I've analyzed this configuration corruption issue and would like to propose a solution using the Claude Code SDK architecture.
Proposed Solution
The configuration corruption appears to be caused by non-atomic writes and lack of recovery mechanisms. Here's a comprehensive fix approach:
1. Atomic Write Operations
Replace direct file writes with atomic operations:
2. Automatic Backup System
Create backups before each write:
3. Corruption Recovery
Implement automatic recovery on parse failure:
4. File Size Management
Prevent unbounded growth:
5. Health Monitoring
Add self-healing capabilities:
Testing Strategy
I've created a test script that validates all these scenarios:
Implementation Notes
fs.renameSync()for atomic operations (POSIX compliant)proper-lockfilepackage) for concurrent accessThis solution ensures Claude Code can run 24/7 without manual intervention, automatically recovering from any configuration corruption issues.
Would the team like me to provide more detailed implementation code or test cases?
@steipete I understand your skepticism. Let me clarify what happened and why I took this approach:
Why the PRs were closed
I initially created PRs (#5782, #5796, #5798) that attempted to add
src/utils/config.tsto this repository. These were closed because:Why this approach is correct
Since the source code isn't public, the appropriate contribution method is:
The solution is valid
The proposed fix addresses the exact issues everyone reported:
This isn't "untested nonsense" - it's a standard production pattern used in many systems. The test script I created validates these exact scenarios.
I apologize for the initial confusion with the PRs, but the solution itself is solid and directly addresses the root causes that are affecting multiple users daily.
Update: Confirmed the issue with local testing
I've investigated further and found concrete evidence of this issue:
Real-world corruption found
Checked my local Claude Code installation and found:
Why we can't patch it directly
Attempted to create a fix but discovered:
Configuration location confirmed
Claude Code stores configuration at:
~/.claude.json~/.claude.json.backup~/.claude/settings.jsonThe fix is still valid
The proposed solution remains correct - implementing atomic writes and size management would prevent this. The issue is reproducible and affects real users daily (my own config is corrupted right now).
Immediate workaround for affected users
This is a critical issue affecting production usage. The corruption happens silently and requires manual intervention, making Claude Code unreliable for automated/unattended operation.
🎉 Community Solution Available!
I've created and tested a working fix for this issue. After experiencing the same 18MB config corruption, I built a protection system that's now running successfully.
Claude Config Protector
A lightweight daemon that prevents config corruption before it happens.
GitHub Repository: https://github.com/jfuginay/claude-config-protector
Quick Install
What It Does
Verified Working
Just tested on my system:
How It Works
~/.claude.jsoncontinuouslyFor Those Currently Affected
If your Claude Code is crashing right now:
Test Results
Why This Works
rename()is atomic, preventing partial writesPerformance Impact
Note to Anthropic Team
This community solution addresses all the issues mentioned:
The implementation follows the exact patterns I suggested earlier - atomic writes, size management, and backup recovery. Feel free to reference this implementation for the official fix.
For the Community
This is a stopgap solution until Anthropic releases an official fix. It's MIT licensed and open for contributions. If you're experiencing daily crashes like many of us were, this will solve your problem immediately.
Repository: https://github.com/jfuginay/claude-config-protector
Hope this helps everyone affected by this issue! 🚀
SOLVED: Deleting corrupted ~/.claude.json file fixed the issue.
Steps:
Root Cause:
The .claude.json configuration file became corrupted (similar to #5655). Deleting and letting VSCode recreate it resolved the issue immediately.
This solution worked on Windows 11 with the latest Claude Code extension.
Depends on your definition of solved.
Some power users rely on saving and reusing things in their .claude.json
Having many claude code sessions makes the file become too large and corrupt much faster.
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
I just got my file corrupted and have to start a new. Windows user here
remove those files and try to login again
this issue happened to me lately.
Reproduction on Windows — v2.1.59 with Task tool subagents
Environment:
Trigger: Running a session that spawns 2+ parallel Task tool subagents (e.g., an Explore agent + a research agent). The main process + subagents = 3 concurrent writers to
~/.claude.json.Result: 36 corrupted backup files generated in a single session (~2 minutes), all with
JSON Parse error: Unexpected EOF. The corrupted files show:userIDhashes across files (each partial write produces inconsistent state)Interesting finding from cross-referenced issue #26717: The logs show that atomic write-rename was attempted but fails on Windows:
So the fix (atomic rename) exists in the codebase but is broken on Windows —
EPERMon rename suggests another process has the file open, and Windows doesn't allow renaming over open files (unlike POSIX). The lock file approach also fails because the lock is already held by a sibling process.Suggested fix for Windows: Use
fs.renamewith retry logic + exponential backoff, or useproper-lockfilewithretriesoption. Alternatively, have subagents delegate all config writes to the parent process via IPC rather than writing directly.Question: Is there a previous version of Claude Code that did not exhibit this issue? Would like to know if downgrading is a viable temporary workaround while this is being fixed.
I think 2.1.50 doesn't corrupt configs as per https://github.com/anthropics/claude-code/issues/28847#issuecomment-3964557952
Struggling from 2.1.59 ruining processes too.
The same is happening to me too on Windows. Running multiple Claude Code CLI instances was always fine, but since a restart this evening, the second terminal triggers
I'm on 2.1.59 as well, I've been for a day or so but it's possible I haven't opened multiple terminals until now.
I'm getting this all over the place for the last couple days and I absolutely hate it
It's fixed in the latest version, I haven't had it again since updating yesterday.
We kept hitting this with multiple Claude instances. Built cozempic to detect and auto-repair .claude.json corruption — open source.
Scans for invalid JSON, numStartups anomalies, and rapid backup file creation (the cascade pattern). Feedback welcome.