Antipattern Detection Skill
This skill automatically activates after linting failures, test failures, or code
review feedback to identify recurring antipatterns. It stores findings in
~/.claude/config/knowledge_base.yml (the YAML source of truth) via
learning_capture.sh. The human-readable docs/KNOWLEDGE_BASE.md is auto-generated
from the YAML by learning_capture.sh sync-docs.
Trigger Criteria
Activate when any of the following are detected in the current session:
| Trigger | Detection Method |
|---|---|
| Lint failure | Exit code != 0 from ruff, eslint, golangci-lint, tflint |
| Test failure | Exit code != 0 from pytest, go test, vitest, terratest |
| Security finding | Any finding from bandit, gosec, npm audit, tfsec |
| Repeated pattern | Same issue type seen 3+ times across files |
| Code review feedback | Parallel agent consensus flags a recurring concern |
Analysis Process
Step 1: Collect Failure Data
Gather from the current session:
- •Linter output (error codes, rule names, affected lines)
- •Test output (failure messages, assertion errors)
- •Security scan output (vulnerability types, severity)
- •Agent review feedback (concerns raised by 2+ agents)
Step 2: Pattern Classification
Classify each failure into an antipattern category:
| Category | Examples |
|---|---|
security | Hardcoded secrets, SQL injection, unsafe deserialization |
error-handling | Bare exceptions, silent failures, missing error boundaries |
performance | N+1 queries, unbounded loops, missing pagination |
type-safety | Missing type hints, any overuse, unchecked casts |
testing | Missing edge cases, brittle assertions, test pollution |
architecture | Circular imports, god classes, tight coupling |
naming | Misleading names, inconsistent conventions, abbreviations |
duplication | Copy-paste code, reimplemented stdlib, redundant logic |
Step 3: Deduplication
Before adding a new antipattern, check for existing entries in the knowledge base:
~/.claude/scripts/learning_capture.sh query --category antipattern --language <LANG> --format llm
- •
If a matching entry exists (same category + language + similar description), increment it:
bash~/.claude/scripts/learning_capture.sh increment <ID>
- •
Only create a new entry if no similar pattern is documented
Step 4: Store Entry
For each new antipattern, store it in the YAML knowledge base:
~/.claude/scripts/learning_capture.sh add \ --category antipattern \ --language <language> \ --title "<short title>" \ --description "<1-2 sentence problem description and recommended fix>" \ --tags "<comma-separated tags>" \ --confidence <high|medium|low> \ --source antipattern-detect
After storing all new entries, regenerate the human-readable docs:
~/.claude/scripts/learning_capture.sh sync-docs
Storage
Source of truth: ~/.claude/config/knowledge_base.yml (machine-readable YAML)
Entries are stored via learning_capture.sh add which handles:
- •Automatic ID generation (KB-NNN format)
- •YAML validation before writing
- •Header comment preservation
Human-readable view: docs/KNOWLEDGE_BASE.md (auto-generated)
Regenerated by learning_capture.sh sync-docs. Do not edit this file directly.
Non-Blocking Behavior
This skill follows the same non-blocking pattern as code-quality:
- •Never blocks user workflow or command execution
- •Reports inline when an antipattern is detected
- •Writes to knowledge_base.yml via learning_capture.sh after primary task completes
- •Suggests fixes but does not auto-apply changes
Integration
This skill complements other skills:
| Skill | Relationship |
|---|---|
code-quality | Feeds security/quality findings into antipattern detection |
learning-loop | Shares knowledge_base.yml as the common data store |
verify | Lint/test failures trigger antipattern analysis |
When both code-quality and antipattern-detect trigger:
- •
code-qualityprovides immediate inline feedback - •
antipattern-detectdocuments the pattern for future reference - •Results are complementary, not duplicated
Safety Checks
- •Never modify source code -- only writes to knowledge_base.yml via learning_capture.sh
- •learning_capture.sh validates YAML before writing
- •Cap entries at 500 per knowledge base file (learning_capture.sh limit)
- •Sanitize code examples to remove actual secrets or credentials
- •sync-docs regenerates docs/KNOWLEDGE_BASE.md -- do not edit that file directly