← ClaudeAtlas

state-management-patternslisted

JSON persistence, atomic writes, file locking, crash recovery, and state versioning patterns. Use when implementing stateful libraries or features requiring persistent state. TRIGGER when: state persistence, atomic write, file locking, crash recovery, checkpoint. DO NOT TRIGGER when: stateless utilities, pure functions, config reads, documentation.
akaszubski/autonomous-dev · ★ 29 · Data & Documents · score 68
Install: claude install-skill akaszubski/autonomous-dev
# State Management Patterns Skill Standardized state management and persistence patterns for the autonomous-dev plugin ecosystem. Ensures reliable, crash-resistant state persistence across Claude restarts and system failures. ## When This Skill Activates - Implementing state persistence - Managing crash recovery - Handling concurrent state access - Versioning state schemas - Tracking batch operations - Managing user preferences - Keywords: "state", "persistence", "JSON", "atomic", "crash recovery", "checkpoint" --- ## Core Patterns ### 1. JSON Persistence with Atomic Writes **Definition**: Store state in JSON files with atomic writes to prevent corruption on crash. **Pattern**: ```python import json from pathlib import Path from typing import Dict, Any import tempfile import os def save_state_atomic(state: Dict[str, Any], state_file: Path) -> None: """Save state with atomic write to prevent corruption. Args: state: State dictionary to persist state_file: Target state file path Security: - Atomic Write: Prevents partial writes on crash - Temp File: Write to temp, then rename (atomic operation) - Permissions: Preserves file permissions """ # Write to temporary file first temp_fd, temp_path = tempfile.mkstemp( dir=state_file.parent, prefix=f".{state_file.name}.", suffix=".tmp" ) try: # Write JSON to temp file with os.fdopen(temp_fd, 'w') as f: j