スキル一覧に戻る
hgeldenhuys

error-recovery

by hgeldenhuys

1🍴 0📅 2026年1月24日
GitHubで見るManusで実行

SKILL.md


name: error-recovery description: Handle Claude Code errors gracefully - error types, recovery, prevention version: 1.0.0 author: Claude Code SDK tags: [errors, recovery, handling, prevention]

Error Recovery

Handle Claude Code errors gracefully with systematic recovery strategies and prevention techniques.

Quick Reference

Error CategoryCommon CausesQuick Fix
API ErrorsRate limits, overload, authWait, retry, check credentials
Tool ErrorsPermissions, missing filesCheck permissions, validate paths
Context ErrorsToken overflow, corruption/compact or /clear
MCP ErrorsServer disconnect, timeoutRestart server, check logs
Hook ErrorsJSON syntax, script failureValidate JSON, test script

Error Message Anatomy

Claude Code error messages follow a consistent pattern:

[Error Category] [Specific Error]: [Description]
  at [Location/Context]
  Cause: [Root cause if known]
  Suggestion: [Recommended action]

Reading Error Messages

PartWhat It Tells YouAction
CategoryType of error (API, Tool, etc.)Determines recovery approach
Specific ErrorExact error code/nameLook up in error reference
DescriptionHuman-readable explanationUnderstand what went wrong
LocationWhere error occurredIdentify failing component
CauseWhy it happenedFix root cause
SuggestionRecommended fixTry suggested action first

Common Error Patterns

API Errors

ErrorMeaningRecovery
rate_limit_errorToo many requestsWait 60s, reduce frequency
overloaded_errorAPI at capacityWait 30-60s, retry
context_length_exceededToo many tokens/compact or split request
authentication_errorInvalid/expired tokenclaude auth login
invalid_request_errorMalformed requestCheck input format
api_errorServer-side issueRetry with backoff

Tool Errors

ErrorMeaningRecovery
permission_deniedTool not allowed/permissions, allow tool
file_not_foundPath doesn't existVerify path, check working dir
directory_not_foundDir doesn't existCreate directory first
read_errorCan't read fileCheck permissions, encoding
write_errorCan't write fileCheck permissions, disk space
command_failedBash command errorCheck exit code, stderr
timeoutOperation too slowIncrease timeout, simplify

Context Errors

ErrorMeaningRecovery
context_overflowToken limit reached/compact or /clear
memory_limitToo much in memoryClear memory banks
session_expiredSession timed outStart new session
state_corruptionSession state invalid/clear, restart

Recovery Workflow

Step 1: Identify Error Type

Error occurred
    |
    +-- API Error?
    |   +-- Yes --> See API recovery
    |   +-- No --> Continue
    |
    +-- Tool Error?
    |   +-- Yes --> See Tool recovery
    |   +-- No --> Continue
    |
    +-- Context Error?
    |   +-- Yes --> See Context recovery
    |   +-- No --> Continue
    |
    +-- Unknown?
        +-- Check debug output
        +-- Use /bug to report

Step 2: Apply Recovery Strategy

For API Errors:

  1. Wait for rate limit window (60s typical)
  2. Retry with exponential backoff
  3. If persistent, check credentials

For Tool Errors:

  1. Check /permissions
  2. Validate inputs (paths, arguments)
  3. Check file/directory exists

For Context Errors:

  1. Run /compact to reduce context
  2. If severe, use /clear
  3. Start fresh if corrupted

Step 3: Verify Recovery

# Check system health
claude doctor

# Verify specific component
/permissions  # Tool permissions
/mcp          # MCP servers
/hooks        # Hook status

Quick Recovery Commands

SituationCommand
Context too large/compact
Session corrupted/clear
Need to restartCtrl+C, restart claude
Check healthclaude doctor
Debug modeclaude --debug
Verbose loggingANTHROPIC_LOG=debug claude

Retry Patterns

Simple Retry

For transient errors (rate limits, overload):

1. Wait initial delay (1s)
2. Retry operation
3. If fails, double delay (2s, 4s, 8s...)
4. Max 5 retries or 60s total
5. If still failing, escalate

Backoff with Jitter

For high-contention scenarios:

delay = min(cap, base * 2^attempt) + random(0, 1000ms)
  • Base: 1000ms
  • Cap: 60000ms
  • Jitter: 0-1000ms random

Circuit Breaker

For persistent failures:

If 3 failures in 60s:
    Open circuit (stop trying)
    Wait 5 minutes
    Try once (half-open)
    If success: close circuit
    If failure: keep open

Error Prevention Checklist

Before operations:

  • Validate file paths exist
  • Check permissions are granted
  • Verify network connectivity
  • Ensure context has headroom
  • Test hooks work correctly

During operations:

  • Watch for warning signs
  • Monitor context size
  • Handle errors gracefully
  • Log important state

After errors:

  • Document what happened
  • Fix root cause
  • Add prevention measures
  • Test fix works

Reference Files

FileContents
ERROR-TYPES.mdComprehensive error reference
RECOVERY-PATTERNS.mdRecovery strategies and patterns
PREVENTION.mdError prevention techniques

Common Scenarios

Scenario: Rate Limited

Symptom: rate_limit_error after many requests

Solution:

  1. Wait 60 seconds
  2. Reduce request frequency
  3. Batch operations when possible

Scenario: Context Overflow

Symptom: context_length_exceeded error

Solution:

  1. Run /compact to summarize context
  2. If still too large, /clear and restart
  3. Use smaller file reads (with offset/limit)

Scenario: Tool Permission Denied

Symptom: Tool blocked by permissions

Solution:

  1. Run /permissions
  2. Allow the specific tool
  3. Or add to settings.json for persistence

Scenario: MCP Server Disconnected

Symptom: MCP tools return errors

Solution:

  1. Check /mcp for server status
  2. Restart MCP server if needed
  3. Verify .mcp.json configuration

Best Practices

  1. Fail Fast: Validate early, fail before expensive operations
  2. Graceful Degradation: Have fallbacks for non-critical features
  3. Clear Errors: Provide actionable error messages
  4. Log Everything: Enable debug mode when troubleshooting
  5. Test Recovery: Verify recovery procedures work before you need them

When to Escalate

Use /bug command when:

  • Error persists after recovery attempts
  • Error message is unclear or missing
  • Behavior contradicts documentation
  • Reproducible crash occurs

Include in report:

  • Claude Code version
  • Error message (full text)
  • Steps to reproduce
  • Debug output

スコア

総合スコア

50/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です