defensive-patterns

defensive-patterns is a skill for Claude Code, Codex from arch3rPro/dsh-skills. It costs 81 tokens per session (1,297 once invoked), scanned A, original, MIT.

A set of defensive programming rules for code involving lifecycles, concurrency, subprocesses, teardown, callbacks, workers, resource disposal, error reporting, or untrusted input and output.

In plain words
What is it for?
It helps review or write setup and cleanup code, process and worker handling, callback logic, temporary-file use, error aggregation, and other failure-prone system code.
Why use it?
It targets bugs caused by reporting only part of an outcome or losing track of who owns a resource while asynchronous work is still running.

Skill for Claude CodeCodex

Written for Claude Code and Codex: shipped in a Claude Code plugin, but also agents/openai.yaml present.

Part of the dsh-skills plugin — 15 skills shipped together

Good fit It helps review or write setup and cleanup code, process and worker…

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/arch3rpro/dsh-skills/defensive-patterns
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.

Any agent
npx skills add arch3rPro/dsh-skills --skill defensive-patterns
Clone the repo
git clone --depth 1 https://github.com/arch3rPro/dsh-skills

Made for: Claude Code, Codex.

Or install dsh-skills, the plugin that ships this one along with the rest of its 15 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for defensive-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/arch3rpro/dsh-skills/defensive-patterns.svg)](https://agentmods.dev/skills/arch3rpro/dsh-skills/defensive-patterns)
Your own site
<a href="https://agentmods.dev/skills/arch3rpro/dsh-skills/defensive-patterns"><img src="https://agentmods.dev/badge/skills/arch3rpro/dsh-skills/defensive-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 81 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,297 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00081 $0.01297
Opus 5 $0.00041 $0.00648
Sonnet 5 $0.00016 $0.00259
Haiku 4.5 $0.00008 $0.00130

Measured 6d ago against content hash 4b2f33bdd690, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

defensive-patterns scanned grade A with 0 findings 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 6d 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.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/architecture/defensive-patterns/SKILL.md · 69 lines

How it starts

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

Defensive Patterns

A catalogue of bug-class rules distilled from defects that actually shipped. Each pattern is one class of failure, stated as the rule that prevents its recurrence. Read this before writing lifecycle, concurrency, subprocess, teardown, or error-reporting code — these are the places where "it usually works" hides a reproducible race.

The defining constraint: these rules are about settlement — the honest, complete reporting of an outcome — and ownership — knowing who owns a resource until it is fully gone. Most concurrency bugs are a settlement or ownership violation in disguise.

This is guidance, not a script. Each pattern names a failure mode and the positive rule that avoids it; apply the ones your code touches. Patterns cluster into two groups — reporting and ownership — with one untrusted-IO trio.

Reporting — tell the whole truth about an outcome

Report orthogonal outcomes independently

A result can be several things at once. A process can time out and exit 0 because it trapped the signal; a call can fail and leave valid partial state. Surface each independent fact (timedOut, signal, exitCode) on its own field or branch — never nest one flag's report inside another's branch, or a caller reads a cut-short run as a clean success. When two facts can both be true, the code that reports only one is lying.

Honor public contracts on BOTH sides

When an implementation receives several representations of one outcome, normalize them before returning through the public API. If a provider may signal failure by throwing or by emitting an error token, the public runtime exposes model-request failures as exactly one form; middleware and caller defects remain thrown. Consumers must never guess whether a caught exception came from the provider, a wrapper, or their own assembly. Document the normalized contract where the type is defined, and exercise every source form through the real consumer.

Contain callback exceptions in the dispatcher

Read the full file on GitHub · 69 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 6d ago First seen · 69 lines · 81 tokens per session scan A 4b2f33bdd690

Subscribe to this mod's changes

defensive-patterns is a skill published in the GitHub repository arch3rPro/dsh-skills (4 stars, last pushed 19d ago), licensed MIT. It adds 81 tokens to every session and 1,297 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.