cf-plan-gate
When the user asks to enforce spec-driven development, add planning gates, require specs before coding, or prevent scope creep — activate this SDD enforcement skill
Files3
View on GitHubSKILL.md.claude/skills/cf-plan-gate/SKILL.md
GitHubPlan Gate — Spec-Driven Development Enforcement
Concept
Plan Gate enforces Spec-Driven Development (SDD) through two complementary hooks that keep Claude aligned with your written specifications. Instead of letting implementation drift from the plan, these hooks provide continuous feedback:
- plan-gate.sh (PreToolUse) -- reminds you when no recent
.spec.mdfile exists before editing source code. Non-blocking, just a nudge. - scope-guard.sh (Stop) -- compares files actually modified against files declared in the active spec. Warns about out-of-scope changes. Non-blocking.
Together they create a lightweight planning discipline: write a spec, declare what files you will touch, then implement. Any deviation gets flagged.
The .spec.md File Format
Create a .spec.md file before starting work. The critical section is Files to Create/Modify:
# Feature: User Authentication
## Goal
Add JWT-based authentication to the API gateway.
## Files to Create/Modify
- src/auth/jwt.service.ts
- src/auth/auth.guard.ts
- src/config/jwt.config.ts
## Acceptance Criteria
- Tokens expire after 1 hour
- Invalid tokens return 401
Filenames are matched as substrings against git-modified paths. Use relative paths.
How plan-gate.sh Works
- Claude attempts to edit a source file via Edit or Write
- The PreToolUse hook runs
plan-gate.sh, which searches for.spec.mdmodified in last 14 days - Spec found -- edit proceeds silently (exit 0)
- No spec found -- prints a reminder, still allows the edit (exit 0, non-blocking)
How scope-guard.sh Works
- Claude finishes a task and the Stop event fires
- Script collects modified files via
git diff --name-only(staged + unstaged) - Finds the most recently modified
.spec.md(within 60 minutes) - Extracts declared files from "Files to Create/Modify" section, compares against actual changes
- All in scope -- silent exit. Out-of-scope -- prints warning listing unexpected files
Excluded from scope checking: test files, config, infrastructure, docs, lockfiles.
Installation
Add both hooks to your .claude/settings.json:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "bash /path/to/skills/skills/plan-gate/scripts/plan-gate.sh",
"statusMessage": "Plan Gate: checking for active spec..."
}
]
}
],
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "bash /path/to/skills/skills/plan-gate/scripts/scope-guard.sh",
"statusMessage": "Scope Guard: checking for out-of-scope changes..."
}
]
}
]
}
}
Replace /path/to/ with the actual absolute path to this repo on your machine.
Customizing
- Spec freshness:
plan-gate.shuses-mtime -14(14 days). Use-mtime -7for weekly sprints. - Scope-guard recency: Uses 60-minute window for active spec. Increase if you write specs early.
- Exclusions: Both scripts skip test/config/infra files. Add project-specific patterns as needed.
Gotchas
- Spec location: Both scripts search from
git rev-parse --show-toplevel. Keep specs in the repo. - Multiple specs:
scope-guard.shpicks the most recently modified.spec.md. Archive old specs when starting new work to avoid ambiguity. - Partial path matching: Declared file
auth.service.tsmatchessrc/auth/auth.service.tsbut alsoold/auth.service.ts. Use specific paths in your spec. - Non-blocking by design: Neither hook blocks Claude. They are reminders. For hard enforcement,
change exit codes to
2inplan-gate.sh. - Git dependency:
scope-guard.shrelies ongit diff. Fresh repos with no commits produce no output, so the guard stays silent. - CLAUDE_TOOL_INPUT_FILE: Set by Claude Code automatically. For manual testing, export it yourself.
Pairing With Other Skills
- Use
/cf-tdd-gatealongside Plan Gate for spec + test-first enforcement - Use
/cf-workflow-autoto auto-generate.spec.mdtemplates from issue descriptions - Use
/cf-scqato structure the spec's goal and context sections