claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Claude Code Configuration File Corruption

Open pm0code opened this issue 7 months ago • 16 comments

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:

  1. Repeated crash loops (1200+ restarts observed)
  2. Service unavailability
  3. Manual file deletion required to restore functionality

Steps to Reproduce

  1. Run Claude Code in a project with active file monitoring
  2. Allow it to run continuously for several hours/days
  3. Perform normal development activities (file changes, analysis, etc.)
  4. Configuration file eventually becomes corrupted
  5. 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

  1. Implement robust error handling for configuration file parsing
  2. Add file validation before parsing (check file size, basic structure)
  3. Implement automatic backup/restore mechanism
  4. Add corruption detection and self-healing
  5. 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.

pm0code avatar Jul 01 '25 15:07 pm0code