[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.