Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Intelligent file write error handler: diagnoses permissions, disk space, path length, file locks before retrying. Use when you encounter 'Error writing file', 'Permission denied', 'Access denied', 'No space left', or related file write failures.
.claude/skills/foryourhealth111-pixel-smart-file-writer/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-03 | ✗→✓ | ▲ Improved | 104% | 0% |
| case-10 | ✗→✓ | ▲ Improved | 133% | 0% |
| case-17 | ✗→✓ | ▲ Improved | 72% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 127% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 92% | 0% |
Automatically diagnoses and resolves file write errors through systematic investigation rather than blind retries. Prevents common write failures proactively.
Use this skill when any of these occurs:
This skill does NOT:
Required inputs:
1. Path Validation
pythonimport os # Check path length (Windows: 260 char limit) if len(filepath) > 260 and os.name == 'nt': print(f"Path too long: {len(filepath)} chars") # Check parent directory exists parent = os.path.dirname(filepath) if not os.path.exists(parent): print(f"Parent directory missing: {parent}")
2. Permission Check
pythonimport os # Check directory write permission parent = os.path.dirname(filepath) or '.' if not os.access(parent, os.W_OK): print(f"No write permission: {parent}") # Check file permissions if exists if os.path.exists(filepath): if not os.access(filepath, os.W_OK): print(f"File not writable: {filepath}")
3. Disk Space Check
pythonimport shutil # Check available disk space stat = shutil.disk_usage(os.path.dirname(filepath) or '.') free_gb = stat.free / (1024**3) if free_gb < 0.1: # Less than 100MB print(f"Low disk space: {free_gb:.2f} GB free")
4. File Lock Detection
pythonimport os # Try to open with exclusive access try: with open(filepath, 'a') as f: pass except PermissionError: print(f"File locked by another process: {filepath}")
5. Windows-Specific Checks
bash# Check if file is in use (Windows) handle.exe -a "filepath" # Check file attributes attrib "filepath"
Pattern 1: Create Missing Directories
pythonimport os os.makedirs(os.path.dirname(filepath), exist_ok=True)
Pattern 2: Atomic Write (Temp + Rename)
pythonimport os import tempfile # Write to temp file first temp_fd, temp_path = tempfile.mkstemp(dir=os.path.dirname(filepath)) try: with os.fdopen(temp_fd, 'w') as f: f.write(content) # Atomic rename os.replace(temp_path, filepath) except Exception as e: os.unlink(temp_path) raise
Pattern 3: Exponential Backoff for Transient Issues
pythonimport time def write_with_retry(filepath, content, max_retries=3): for attempt in range(max_retries): try: with open(filepath, 'w') as f: f.write(content) return True except (PermissionError, OSError) as e: if attempt < max_retries - 1: wait = 2 ** attempt # 1s, 2s, 4s time.sleep(wait) else: raise
Pattern 4: Alternative Path (Shorten Long Paths)
pythonimport os import hashlib def shorten_path(long_path): """Use hash for long filenames""" dir_path = os.path.dirname(long_path) filename = os.path.basename(long_path) if len(long_path) > 260: # Hash the filename name, ext = os.path.splitext(filename) hash_name = hashlib.md5(name.encode()).hexdigest()[:16] return os.path.join(dir_path, f"{hash_name}{ext}") return long_path
Pattern 5: Permission Fix Suggestions
bash# Linux/Mac: Add write permission chmod u+w filepath # Windows: Remove read-only attribute attrib -r filepath # Windows: Take ownership (admin required) takeown /f filepath icacls filepath /grant %username%:F
Pattern 6: Detect Antivirus Interference
pythonimport time import os def is_antivirus_blocking(filepath): """Detect if antivirus is scanning file""" try: # Try to open exclusively with open(filepath, 'r+b') as f: pass return False except PermissionError: # Wait and retry time.sleep(0.5) try: with open(filepath, 'r+b') as f: pass return True # Was temporarily blocked except: return False # Persistent block
Before Any Critical Write
pythondef validate_write_conditions(filepath): """Run before writing important files""" issues = [] # 1. Path length if len(filepath) > 260 and os.name == 'nt': issues.append(f"Path too long: {len(filepath)} chars") # 2. Parent directory parent = os.path.dirname(filepath) or '.' if not os.path.exists(parent): issues.append(f"Parent missing: {parent}") elif not os.access(parent, os.W_OK): issues.append(f"No write permission: {parent}") # 3. Disk space stat = shutil.disk_usage(parent) if stat.free < 100 * 1024 * 1024: # 100MB issues.append(f"Low disk space: {stat.free / 1024**2:.1f} MB") # 4. File exists and writable if os.path.exists(filepath): if not os.access(filepath, os.W_OK): issues.append(f"File not writable: {filepath}") return issues
Wrap Write Tool
python# Before using Write tool, validate: issues = validate_write_conditions(target_path) if issues: print("Pre-write validation failed:") for issue in issues: print(f" - {issue}") # Take corrective action else: # Proceed with Write tool
Wrap Edit Tool
python# Before editing, check file is writable if not os.access(filepath, os.W_OK): print(f"Cannot edit: {filepath} is read-only") # Suggest: chmod u+w or attrib -r
Wrap Bash File Operations
bash# Before redirecting output if [ ! -w "$(dirname "$output_file")" ]; then echo "Cannot write to directory" exit 1 fi
Input:
Steps:
os.makedirs('results', exist_ok=True)Expected output:
Diagnosis: Parent directory 'results' does not exist
Resolution: Created directory 'results'
Retry: torch.save() succeededInput:
D:\very\long\path\with\many\subdirectories\...\extremely_long_filename_that_exceeds_windows_limit.csvSteps:
Expected output:
Warning: Path length 285 chars exceeds Windows limit (260)
Alternative: D:\very\long\path\...\a3f5e8b2c1d4.csv
Mapping saved to: path_mappings.json
Write succeeded to alternative pathInput:
Steps:
attrib -r data.csvExpected output:
Diagnosis: File 'data.csv' has read-only attribute
Resolution: Run 'attrib -r data.csv' to remove read-only flag
[After user confirmation]
Attribute removed. Retry succeeded.Input:
Steps:
Expected output:
Diagnosis: File 'report.xlsx' is locked by another process
Likely cause: File is open in Microsoft Excel
Resolution options:
1. Close Excel and retry
2. Write to alternative: 'report_new.xlsx'
3. Use atomic write with temp file
Cannot proceed automatically. User action required.Input:
Steps:
Expected output:
Warning: Insufficient disk space
Required: ~2.0 GB
Available: 0.5 GB
Recommendations:
1. Clean up temporary files
2. Write to alternative drive: E:\
3. Compress checkpoint before saving
Write operation blocked to prevent failure.references/diagnostic-procedures.md: Detailed diagnostic workflowsreferences/platform-specific.md: Windows/Linux/Mac specific issuesreferences/integration-guide.md: Integrating with Claude Code toolsreferences/error-catalog.md: Common error messages and solutions| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→fail | 4,808 | 11,807 | +146% | 1 | 1 | 0% | 587 | 4,207 | +617% | 0 | 0 | — |
case-02 | pass→pass | 9,259 | 6,035 | -35% | 1 | 1 | 0% | 1,775 | 4,026 | +127% | 0 | 0 | — |
case-03 | fail→pass | 12,802 | 11,121 | -13% | 1 | 1 | 0% | 2,405 | 4,909 | +104% | 0 | 0 | — |
case-04 | pass→pass | 12,797 | 9,555 | -25% | 1 | 1 | 0% | 2,359 | 4,538 | +92% | 0 | 0 | — |
case-05 | pass→pass | 12,843 | 28,178 | +119% | 1 | 1 | 0% | 2,307 | 4,354 | +89% | 0 | 0 | — |
case-06 | pass→pass | 2,971 | 3,358 | +13% | 1 | 1 | 0% | 515 | 3,459 | +572% | 0 | 0 | — |
case-07 | pass→pass | 8,717 | 5,416 | -38% | 1 | 1 | 0% | 1,521 | 3,619 | +138% | 0 | 0 | — |
case-08 | pass→pass | 14,791 | 10,154 | -31% | 1 | 1 | 0% | 2,708 | 4,577 | +69% | 0 | 0 | — |
case-09 | pass→pass | 20,458 | 13,523 | -34% | 1 | 1 | 0% | 4,053 | 5,306 | +31% | 0 | 0 | — |
case-10 | fail→pass | 10,752 | 5,832 | -46% | 1 | 1 | 0% | 1,668 | 3,884 | +133% | 0 | 0 | — |
case-11 | pass→pass | 8,293 | 5,119 | -38% | 1 | 1 | 0% | 1,231 | 3,874 | +215% | 0 | 0 | — |
case-12 | pass→pass | 6,650 | 5,339 | -20% | 1 | 1 | 0% | 1,222 | 3,903 | +219% | 0 | 0 | — |
case-13 | pass→pass | 8,182 | 4,423 | -46% | 1 | 1 | 0% | 1,454 | 3,593 | +147% | 0 | 0 | — |
case-14 | pass→pass | 3,233 | 2,819 | -13% | 1 | 1 | 0% | 540 | 3,454 | +540% | 0 | 0 | — |
case-15 | pass→pass | 4,025 | 2,266 | -44% | 1 | 1 | 0% | 658 | 3,216 | +389% | 0 | 0 | — |
case-16 | pass→pass | 4,750 | 4,919 | +4% | 1 | 1 | 0% | 876 | 3,811 | +335% | 0 | 0 | — |
case-17 | fail→pass | 11,529 | 3,645 | -68% | 1 | 1 | 0% | 2,016 | 3,471 | +72% | 0 | 0 | — |
case-18 | pass→pass | 9,660 | 7,544 | -22% | 1 | 1 | 0% | 1,893 | 4,450 | +135% | 0 | 0 | — |
case-19 | pass→pass | 3,569 | 3,581 | +0% | 1 | 1 | 0% | 537 | 3,494 | +551% | 0 | 0 | — |
case-20 | pass→pass | 17,514 | 7,159 | -59% | 1 | 1 | 0% | 1,634 | 4,280 | +162% | 0 | 0 | — |
case-21 | pass→pass | 7,668 | 4,387 | -43% | 1 | 1 | 0% | 1,097 | 3,525 | +221% | 0 | 0 | — |
case-22 | pass→pass | 14,928 | 13,021 | -13% | 1 | 1 | 0% | 2,645 | 5,038 | +90% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +14 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.