error-handling

A guide to handling failures in an AI coding assistant by separating unrecoverable session problems from expected tool errors. Expected errors are formatted and returned to the language model so it can respond or retry.

In plain words
What is it for?
Use it when writing tools, utilities, or services that can fail, especially around files, shell commands, network requests, authentication, or other system boundaries.
Why use it?
It avoids exposing confusing raw exceptions and gives the assistant enough structured information to explain failures, suggest fixes, or try again.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/techymt/claude-code-superpowers/error-handling
Any agent
npx skills add TechyMT/claude-code-superpowers --skill error-handling
Clone the repo
git clone --depth 1 https://github.com/TechyMT/claude-code-superpowers

Made for: Claude Code, Codex.

Per session 87 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,629 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00087 $0.01629
Opus 5 $0.00044 $0.00814
Sonnet 5 $0.00017 $0.00326
Haiku 4.5 $0.00009 $0.00163

Measured 2d ago against content hash 1758d1b727ae, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

error-handling scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

const response = await fetch(args.url)
skills/error-handling/SKILL.md · 134 lines

How it starts

The opening of the file, as written. The whole thing — 134 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Error Handling

The pattern

Claude Code has two error categories. Session errors are unrecoverable failures that crash the process or abort the current session (network configuration issues, authentication failures, corrupted state). Tool errors are expected failures that should be shown to the LLM so it can reason about them, retry, or explain the situation to the user.

The fundamental rule: tool.call() throws typed errors for expected failures. The framework catches them, calls formatError(error) from src/utils/toolErrors.ts, and delivers the formatted string to the LLM as a tool_result block with is_error: true. Only truly unrecoverable infrastructure failures should propagate past the framework as unhandled exceptions.

Why this matters

The LLM is in a conversation loop. If a tool throws a raw, unformatted exception, the framework must decide what to show the model — a stack trace is not useful. By throwing typed errors (ShellError, AbortError, Error), tools hand the framework enough structure to produce a clean, readable message. For example, a file-not-found error thrown from FileReadTool lets the LLM suggest the correct path or ask the user to check.

This also means the user sees a coherent explanation rather than an error box. The LLM translates the technical error into natural language in its next response.

Custom error types (ShellError, AbortError) are used at system boundaries — they carry structured context (exit code, stderr, interrupted flag) that formatError uses to build the right message.

How to apply it

  1. Wrap all I/O in try-catch inside call(). Catch specific error types first, then rethrow or let them propagate.
  2. throw new Error(message) for expected, non-shell failures. Include enough context for the LLM to act: what was attempted, what failed, what the user could check.
  3. For ENOENT (file not found): use isENOENT() from utils/errors.js to detect it and throw new Error("File not found: /path. Does it exist?").
  4. For command failures: throw new ShellError(stdout, stderr, code, interrupted)formatError assembles exit code and stderr automatically.
  5. For user cancellation: throw new AbortError()formatError maps it to a clean interruption message.
  6. Define custom error types when an error carries structured data that formatting logic needs.

Read the full file on GitHub · 134 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 134 lines · 87 tokens per session scan A 1758d1b727ae

Subscribe to this mod's changes

error-handling is a skill published in the GitHub repository TechyMT/claude-code-superpowers (5 stars, last pushed 5mo ago), licensed MIT. It adds 87 tokens to every session and 1,629 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

book-mirror

Take any book (EPUB/PDF), produce a personalized chapter-by-chapter analysis. Each chapter is preserved in detail (The Chapter) and mirrored back to the reader's actual life (The Mirror) using brain context. The mirror observes and resonates — a friend pointing out parallels, NOT a consultant rearranging the reader's…

garrytan/gbrain · 138 tokens

ljg-learn

Deep concept anatomist that deconstructs any concept through 8 exploration dimensions (history, dialectics, phenomenology, linguistics, formalization, existentialism, aesthetics, meta-philosophy) and compresses insights into an epiphany. Use when user asks to explain, dissect, or deeply understand a concept, term, or…

lijigang/ljg-skills · 113 tokens

eli5

Explain research, papers, or technical ideas in plain English with minimal jargon, concrete analogies, and clear takeaways. Use when the user says "ELI5 this", asks for a simple explanation of a paper or research result, wants jargon removed, or asks what something technically dense actually means.

companion-inc/feynman · 63 tokens

deck-course-module

暖纸背景 + Playfair, 左侧学习目标常驻, 含 MCQ 自测页.

nexu-io/html-anything · 25 tokens

creating-skills

Guide for creating Claude Code skills following Anthropic's official best practices. Use when user wants to create a new skill, build a skill, write SKILL.md, update an existing skill, or needs skill creation guidelines. Provides structure, frontmatter fields, naming conventions, and new features like dynamic context…

redai-infra/Relax · 70 tokens

grid-ctf-ops

Operational knowledge for the gridctf scenario including strategy playbook, lessons learned, and resource references. Use when generating, evaluating, coaching, or debugging gridctf strategies.

greyhaven-ai/autocontext · 42 tokens