Defense in Depth
Use when invalid data causes failures deep in execution, requiring validation at multiple system layers - validates at every layer data passes through to make bugs structurally impossible
Install
/plugin marketplace add lifangda/claude-pluginsThe repo is a Claude Code plugin marketplace. Run /plugin afterwards to pick the plugin that includes this skill.
npx skills add lifangda/claude-plugins --skill defense-in-depthgit clone --depth 1 https://github.com/lifangda/claude-plugins.git /tmp/claude-plugins
mkdir -p ~/.claude/skills
cp -r /tmp/claude-plugins/cli-tool/skills-library/testing-quality/defense-in-depth ~/.claude/skills/defense-in-depthPersonal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.
From the SKILL.md
# Defense-in-Depth Validation
## Overview
When you fix a bug caused by invalid data, adding validation at one place feels sufficient. But that single check can be bypassed by different code paths, refactoring, or mocks.
**Core principle:** Validate at EVERY layer data passes through. Make the bug structurally impossible.
## Why Multiple Layers
Single validation: "We fixed the bug"
Multiple layers: "We made the bug impossible"
Different layers catch different cases:
- Entry validation catches most bugs
- Business logic catches edge cases
- Environment guards prevent context-specific dangers
- Debug logging helps when other layers fail
## The Four Layers
### Layer 1: Entry Point Validation
**Purpose:** Reject obviously invalid input at API boundary
```typescript
function createProject(name: string, workingDirectory: string) {
if (!workingDirectory || workingDirectory.trim() === '') {
throw new Error('workingDirectory cannot be empty');
}
if (!existsSync(workingDirectory)) {
throw new Error(`workingDirectory does not exist: ${workingDirectory}`);
}
if (!statSync(workingDirectory).isDirectory()) {
throw new Error(`workingDirectory is not a directory: ${workingDirectory}`);
}
// ... proceed
}
```
### Layer 2: Business Logic Validation
**Purpose:** Ensure data makes sense for this operationDetails
- Skill name
defense-in-depth- Repository
- lifangda/claude-plugins
- Path
cli-tool/skills-library/testing-quality/defense-in-depth/SKILL.md- License
- MIT
- Repo updated
- 29 October 2025
FAQ
What does the Defense in Depth skill do?
Use when invalid data causes failures deep in execution, requiring validation at multiple system layers - validates at every layer data passes through to make bugs structurally impossible
How do I install the Defense in Depth skill?
Claude Code plugin: /plugin marketplace add lifangda/claude-plugins. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.
Is Defense in Depth popular?
It lives in lifangda/claude-plugins, which has 43 GitHub stars and 13 forks.
Related skills
Test Driven Development
43lifangda/claude-plugins
Use when implementing any feature or bugfix, before writing implementation code - write the test first, watch it fail, write minimal code to pass; ensures tests actually verify behavior by requiring failure first
Video Downloader
43lifangda/claude-plugins
Downloads videos from YouTube and other platforms for offline viewing, editing, or archival. Handles various formats and quality options.
Aeon
43lifangda/claude-plugins
Time series machine learning toolkit for classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search. Use this skill when working with temporal data, performing time series analysis, building predictive models on sequential data, or implementing workflows that involve distance metrics (DTW), transformations (ROCKET, Catch22), or deep learning for time series. Applicable for tasks like ECG classification, stock price forecasting, sensor anomaly detection, or activity recognition from wearable devices.
Testing Anti Patterns
43lifangda/claude-plugins
Use when writing or changing tests, adding mocks, or tempted to add test-only methods to production code - prevents testing mock behavior, production pollution with test-only methods, and mocking without understanding dependencies
Condition Based Waiting
43lifangda/claude-plugins
Use when tests have race conditions, timing dependencies, or inconsistent pass/fail behavior - replaces arbitrary timeouts with condition polling to wait for actual state changes, eliminating flaky tests from timing guesses
Testing Skills with Subagents
43lifangda/claude-plugins
Use when creating or editing skills, before deployment, to verify they work under pressure and resist rationalization - applies RED-GREEN-REFACTOR cycle to process documentation by running baseline without skill, writing to address failures, iterating to close loopholes
Browse the most popular Claude skills, all testing & qa skills, or write your own with the skills generator.