Claude Code design-by-contract skill: Specify function contracts
Use design-by-contract to spell out what callers provide, what a function promises on return, and which properties a class must preserve across calls. It also helps decide where to validate an input.
中文Install in Claude Code
Use a local Claude Code session in a practice project. Supply a short requirement or point the skill at an existing function.
- Download the repository snapshot at the linked commit. Copy the entire software-design-plugin/skills/design-by-contract/ directory into .claude/skills/design-by-contract/ in your practice project.
- Confirm that SKILL.md is directly inside .claude/skills/design-by-contract/. Open Claude Code from the project root and enter /design-by-contract reserveSeat.
Example task
Run /design-by-contract reserveSeat. Add this requirement: a request for two seats succeeds when four remain, leaving two. A request for five fails and leaves four. Ask for a design report.What to check
Look for a positive-integer input requirement, a capacity check, and a clear guarantee that a rejected request leaves the seat count unchanged.
Original SKILL.md on GitHub · Updated
Frequently asked question
Where should reserveSeat check the requested number of seats?
Validate external input at the entry point and return a clear error for an invalid request. Reserve assertions for conditions the application itself has already guaranteed.