com um clique
closing-the-loop
// Closed-loop planning discipline for non-trivial changes. Use when creating implementation plans, reviewing plan completeness, or preparing PRs that require structured planning evidence.
// Closed-loop planning discipline for non-trivial changes. Use when creating implementation plans, reviewing plan completeness, or preparing PRs that require structured planning evidence.
Use tmux correctly from an agent — explicit pane targeting, safe-state verification, send verification, state distinction, and recovery. Use when Claude Code, Codex, GitHub Copilot CLI, or any TUI/REPL must keep state across commands.
Dispatch parallel subagents for independent tasks without shared state. Use when facing 2+ independent failures, debugging unrelated subsystems, or researching separate topics concurrently.
Create isolated git worktrees for feature work with safety verification. Use when starting feature branches that need isolation, running parallel agents in separate workspaces, or before executing implementation plans.
Test-driven development discipline for any feature or bugfix. Use when implementing features, fixing bugs, or changing behavior — requires writing failing tests before implementation code.
Fetch up-to-date library documentation. Use when user asks about libraries, frameworks, or needs current API references/code examples.
Browse websites, interact with web pages, and run Playwright tests. Use for navigating URLs, clicking elements, filling forms, taking screenshots, running browser automation, or executing Playwright test suites.
| name | closing-the-loop |
| description | Closed-loop planning discipline for non-trivial changes. Use when creating implementation plans, reviewing plan completeness, or preparing PRs that require structured planning evidence. |
Formalize implementation plans so every non-trivial change has a clear contract between planning and verification. The 9 required sections close the loop between "what we plan" and "what we enforce."
Every non-trivial plan must include all 9 sections. Order is flexible; names accept alternatives.
What does success look like? What observable signal confirms this work landed correctly?
## Goal / Signal
After this lands:
- Observable signal: <what changes in the system>
- User-facing impact: <what users see differently>
Alternatives: Objective
What is in scope and what is explicitly out of scope for this change?
## Scope
**In scope:**
- Item A
- Item B
**Out of scope:**
- Item C (future PR)
Map each requirement to its test. This is the contract between what we build and how we verify it.
## TDD Matrix
| Requirement | Test | Type |
|---|---|---|
| Feature X works | `test_feature_x` | unit |
| API returns 200 | `test_api_returns_200` | integration |
Alternatives: Test Matrix
Ordered steps with enough detail that another agent could execute them. Group by TDD phase (Red/Green/Refactor) when applicable.
## Implementation Steps
### Phase 1: Red
1. Write failing test for X
### Phase 2: Green
2. Implement X to pass test
### Phase 3: Refactor
3. Clean up implementation
Alternatives: Approach
Concrete commands and expected results. Every claim in the plan maps to a verification step.
## Verification Matrix
| Check | Command | Expected Result |
|---|---|---|
| Tests pass | `pytest tests/ -v` | All green |
| Lint clean | `shellcheck scripts/*.sh` | No errors |
Alternatives: Verification Checklist
Manual workaround rule: If any verification step requires an ad-hoc manual workaround (chmod/chown, container edits, one-off env vars, etc.) outside documented code, automation, or runbooks, treat it as a blocker. See Guardrails in
AGENTS.mdfor required response and merge recommendation semantics.
What CI checks enforce this change? What drift could occur and how is it caught?
## CI / Drift Gates
- **New gate:** `check_foo.py` runs on PRs
- **Existing gates preserved:** bats, compose, shellcheck
- **Drift risk:** If X changes, Y catches it
Alternatives: CI Gates, Drift Gates
What could go wrong and how do we prevent or handle it?
## Risks & Mitigations
| Risk | Likelihood | Impact | Mitigation |
|---|---|---|---|
| X breaks Y | Low | High | Guard with Z |
Checkbox list of all conditions that must be true before this work is complete.
## Definition of Done
- [ ] All tests pass
- [ ] CI green
- [ ] Docs updated
- [ ] Line count constraints met
Alternatives: Done Criteria
When should work stop? What explicit boundaries prevent scope creep?
## Stop Conditions
**Stop if:**
- X exceeds threshold Y
- Approach Z proves unviable
**Out of scope:**
- Future enhancement A
- Unrelated refactor B
Alternatives: Out of Scope, Out-of-Scope
Copy into your plan and check off as you complete each section:
- [ ] Goal / Signal
- [ ] Scope
- [ ] TDD Matrix
- [ ] Implementation Steps
- [ ] Verification Matrix
- [ ] CI / Drift Gates
- [ ] Risks & Mitigations
- [ ] Definition of Done
- [ ] Stop Conditions
| Anti-Pattern | Why It Fails | Fix |
|---|---|---|
| Vague goal ("improve things") | No observable signal to verify | State concrete before/after |
| TDD matrix without test names | Can't verify tests were written | Name every test function |
| Steps without phase grouping | Unclear when to test vs. implement | Group by Red/Green/Refactor |
| Missing stop conditions | Scope creep goes unchecked | Define explicit boundaries |
| Verification without commands | "It works" isn't evidence | Include exact commands + expected output |
| Risks without mitigations | Identified but unaddressed | Every risk needs a mitigation |
| DoD without checkboxes | Can't track completion | Use - [ ] for each condition |
| Scope without "out of scope" | Boundaries are implicit | Explicitly list what you won't do |
| CI section says "existing" only | Doesn't explain new enforcement | Document new gates + drift risks |
| Verification via ad-hoc manual workaround | Root cause unknown, fix isn't durable, breaks on redeploy | Identify root cause, determine least-privilege fix, state merge recommendation: patch first (default), split follow-up (only if safe to ship independently, no security regression, no redeploy breakage), or merge now (only if no real workaround needed or durable fix already in PR) |
The check_plan_closed_loop.py script validates plan sections:
PLAN_CLOSED_LOOP_STRICT=1): Fails on missing sections, exits 1.claude/plans/*.md filesThis skill maps to step 2 of the Required PR Workflow in AGENTS.md:
/primer/closing-the-loop (this skill)AGENTS.md (non-negotiable 6, PR workflow step 2)scripts/checks/check_plan_closed_loop.pytests/checks/test_check_plan_closed_loop.py.github/docs/best-practices.md (section 2).github/docs/contribution-workflow.md.github/agents/planner.md