Skills & Patterns
Repeating Patterns, Written Once.
A skill file codifies a repeating code pattern — exception classes, test structure, module scaffold — so the AI applies it consistently across every sprint without re-prompting.
Without skill files, the AI drifts back to its defaults every session.
You correct the pattern, it holds for one session, then resets on the next. Skill files break that cycle permanently.
Without a skill file, the AI guesses your pattern from context. Sometimes right, often not — wrong exception class, different test structure, error messages that don't match the codebase. The real cost is the correction loop: you correct it, it drifts on the next task. You re-explain the pattern, it holds one session, resets the next.
Skill files break that cycle. The pattern is written down once. It applies every session, every task, for every developer on the team — because the AI reads the file, not your memory.
Skill files live in skills/ inside the project repo — git-tracked, shared with the team, and active for anyone who clones the repo. CLAUDE.md is the bridge: it tells the AI when to read each skill file.
skills/error-handling.SKILL.md — the NestJS exception map.
TiffinConnect's error-handling skill contains 10 scenarios, a throw pattern, a message format table, and an explicit anti-patterns section. The AI reads it before throwing any error in a service.
| Scenario | Exception class | HTTP |
|---|---|---|
| Order / user / vendor not found | NotFoundException | 404 |
| Invalid state transition | UnprocessableEntityException | 422 |
| Vendor capacity exceeded | ConflictException | 409 |
| Cutoff time has passed | BadRequestException | 400 |
| Wrong role / forbidden resource | ForbiddenException | 403 |
| Duplicate webhook event | Do not throw — return 200 | 200 |
| DTO field validation failure | Do not throw — ValidationPipe handles it | 400 |
// Throw pattern enforced by the skill throw new NotFoundException(`Order ${id} not found`); throw new ConflictException(`Vendor ${vendorId} has no available capacity`); throw new ForbiddenException(`Only vendors may approve orders`); // Anti-patterns the skill explicitly blocks: // ❌ manual response — HttpExceptionFilter won't run res.status(404).json({ message: 'not found' }); // ❌ raw Error — produces a 500, not a 404 throw new Error('order not found'); // ❌ swallowing in controller — hides real errors try { ... } catch (e) { return { success: false, message: e.message }; }
skills/unit-test.SKILL.md — Jest mock patterns for Mongoose.
The unit-test skill contains the standard test skeleton, three Mongoose mock patterns, and a 6-item coverage checklist. The AI reads it before writing any spec file.
// Standard skeleton — enforced by the skill describe('RatingsService', () => { let service: RatingsService; let mockModel: any; beforeEach(async () => { mockModel = jest.fn(); mockModel.findById = jest.fn(); mockModel.find = jest.fn(); const module: TestingModule = await Test.createTestingModule({ providers: [ RatingsService, { provide: getModelToken(Rating.name), useValue: mockModel }, ], }).compile(); service = module.get<RatingsService>(RatingsService); }); afterEach(() => jest.clearAllMocks()); }); // Pattern A — query chain (find, findById, findOne) mockModel.findById.mockReturnValue({ exec: jest.fn().mockResolvedValue(mockRating) }); // Pattern B — constructor + save const mockSave = jest.fn().mockResolvedValue(mockRating); mockModel.mockImplementation(() => ({ save: mockSave })); // Pattern C — findByIdAndUpdate mockModel.findByIdAndUpdate.mockReturnValue({ exec: jest.fn().mockResolvedValue(updated) });
The three mock patterns cover 95% of Mongoose operations. Without this skill, the AI invents a fourth pattern that doesn't work with the query chain — the most common source of failing tests in NestJS projects.
skills/debug.SKILL.md — the reproduce → isolate → fix loop, written down.
Bug fixing repeats the same steps every time, so it is a perfect candidate for a skill. A project-specific debug skill teaches the AI your repro commands, log locations, and stack — so "run the debug skill on this failure" replaces re-explaining the loop each session.
| Phase | What the skill makes the AI do |
|---|---|
| Reproduce | Run the project's repro command; capture expected vs actual. Refuse to patch without a reproduction. |
| Isolate | Read the relevant logs/stack trace, name the single most likely cause, and explain it before editing. |
| Fix | Apply the smallest change that addresses the cause — no drive-by refactors. |
| Regression-test | Add a test that fails before the fix and passes after; run the suite. |
# skills/debug.SKILL.md (project-specific — knows THIS repo) ## When to use: any failing test, error, or "it broke" report. ## Repro commands (edit per project) - API: `npm run test:api -- <spec>` logs: `docker logs api --tail=100` - Web: `npm run dev` then reproduce in browser; check the console ## Loop — do not skip a step 1. REPRODUCE first. If you cannot reproduce, ask for exact steps. Never patch blind. 2. ISOLATE: read the trace, state the single most likely cause, wait for confirm. 3. FIX: smallest change only. No unrelated refactors. 4. REGRESSION: add a test that fails before / passes after. Run the full suite. ## Anti-patterns # ❌ Changing several files at once "to be safe" — hides the real cause # ❌ Removing the failing assertion instead of fixing the code
This is the pattern behind a real team debug skill (e.g. a Nibe_debug_skill tuned to that project's services and logs). Start from this skeleton, then edit the repro commands and log paths to match your stack — and commit it so the whole team debugs the same way.
Two places skill files live. For a team, only project/skills/ matters.
Project skills are git-tracked, team-shared, and active immediately for anyone who clones the repo. Global skills are per-developer-machine and require manual installation.
| Property | your-project/skills/ | ~/.claude/skills/ |
|---|---|---|
| Scope | This project only | All Claude Code sessions on that machine |
| Shared with team | Yes — git-tracked, clone → ready | No — per developer machine, installed manually |
| How Claude reads it | CLAUDE.md tells Claude when to read the file | Auto-discoverable via the Skill tool |
| Setup needed | None — part of the repo scaffold | Each developer installs manually |
For a starter template, always use your-project/skills/. The moment someone clones the repo, the skill files are in place and CLAUDE.md is already wired to trigger them.
Rules for writing effective skill files.
Skill files degrade in two ways: scope creep (one file covers too many concerns) and prose drift (tables replaced by paragraphs the AI misreads).