"Agent-assisted plan drafting to define a reviewable execution contract before coding. Reuses gather/clarify evidence first, fills unresolved gaps with targeted research, applies BDD success criteria and cwf:review integration, then persists plan+lessons as runtime-independent files for plan→impl→review continuity. Triggers: \"cwf:plan\", \"plan this task\""
Resources
1Install
npx skillscat add corca-ai/claude-plugins/plan Install via the SkillsCat registry.
Plan
Create a reviewable execution contract (scope, files, success criteria) before code changes begin.
Quick Start
cwf:plan <task description>Design Intent (Post-v3 Architecture)
CWF v3 moved planning from runtime-specific plan-mode hooks to a runtime-independent skill (cwf:plan) with file-based contracts.
- Better planning input quality before drafting
gather+clarifycollect evidence and decision points before planning starts.- Planning conversations can reveal constraints/preferences that must be recorded in
lessons.mdimmediately, not after implementation.
- Context continuity without user-managed reset choreography
- Some runtimes expose context-reset workflows after planning discussions.
- CWF keeps continuity by default through
plan.md,lessons.md, and optionalcwf:handoff --phase, instead of shifting context-management burden to the user.
- Stable cross-runtime contract for long autonomous work
plan.md(WHAT) +phase-handoff.md(HOW, optional) +lessons.md(learned constraints) define a persistent contract for impl/review stages.- This keeps execution safe and reliable across auto-compact and runtime boundaries (Claude/Codex).
Phase 0: Update Live State
Use the live-state helper (session-first write target):
bash {CWF_PLUGIN_DIR}/scripts/cwf-live-state.sh set . \
phase="plan" \
task="{task summary}"Phase 1: Parse & Scope
- Record the task description verbatim
- Identify what needs planning:
- What is the goal?
- What are the key decisions to make?
- What are the known constraints?
- Present a brief scope summary to the user before proceeding
## Task
"{user's task description verbatim}"
## Scope Summary
- **Goal**: {what we're trying to achieve}
- **Key Decisions**: {decisions that affect the plan}
- **Known Constraints**: {limitations, boundaries}Phase 2: Evidence Baseline & Gap-Fill Research
2.0 Resolve session directory
Resolve the effective live-state file, then read live.dir.
live_state_file=$(bash {CWF_PLUGIN_DIR}/scripts/cwf-live-state.sh resolve)session_dir: "{live.dir value from resolved live-state file}"2.1 Build baseline from existing artifacts
Use persisted artifacts as the default planning evidence before launching any new research.
- Resolve the effective live-state file and read
live.clarify_result_filewhen set. - Read gather/clarify artifacts already available for this session, prioritizing:
- clarify summary file (
live.clarify_result_file) {session_dir}/clarify-codebase-research.md{session_dir}/clarify-web-research.md{session_dir}/clarify-expert-alpha.md{session_dir}/clarify-expert-beta.md- relevant gathered markdown outputs (and matching
.meta.yaml) from the current session directory
- clarify summary file (
- Build an Evidence Gap List:
- which decision points are already answerable from existing evidence
- which decision points still need additional investigation
If no reusable artifacts are available, treat all unresolved decision points as gap candidates and continue to Phase 2.2.
2.2 Context recovery check (gap-fill outputs)
Apply the context recovery protocol to these gap-fill output files:
| Agent | Output file |
|---|---|
| Prior Art Researcher | {session_dir}/plan-prior-art-research.md |
| Codebase Analyst | {session_dir}/plan-codebase-analysis.md |
Decision:
- If Evidence Gap List is empty: skip to Phase 3 (no extra research needed).
- If Evidence Gap List is non-empty and both files are valid: reuse them and skip to Phase 3.
- Otherwise continue to Phase 2.3.
2.3 Adaptive gap triage
Assess each unresolved gap to decide which extra research lane is needed:
| Gap type | Agent decision |
|---|---|
| Gap is mainly repository-specific (existing architecture, constraints, local patterns) | Launch Codebase Analyst only |
| Gap is mainly external best practice / prior art | Launch Prior Art Researcher only |
| Gap spans both repository constraints and external practice | Launch both agents in parallel |
| Gap is already answerable from baseline after re-check | No launch for that gap |
When uncertain, prefer launching both agents.
2.4 Launch targeted sub-agents
Launch sub-agents simultaneously using the Task tool — only for lanes selected in Phase 2.3 and only when their result files are missing or invalid.
- Shared output persistence contract: agent-patterns.md § Sub-agent Output Persistence Contract.
Sub-agent A: Prior Art Researcher
Task tool:
subagent_type: general-purpose
max_turns: 20
prompt: |
Research best practices, frameworks, and prior art relevant to this task.
## Web Research Protocol
Read the "Web Research Protocol" section of
{CWF_PLUGIN_DIR}/references/agent-patterns.md and follow it exactly.
Key points: discover URLs via WebSearch first (never guess URLs),
use WebFetch then fall back to agent-browser for JS-rendered pages,
skip failed domains, budget turns for writing output.
You have Bash access for agent-browser CLI commands.
Find:
- Established methodologies or patterns for this type of work
- Common pitfalls and how others avoided them
- Relevant tools, libraries, or approaches
Cite real sources with URLs. Report findings — do not make decisions.
Task:
{task description from Phase 1}
Key decisions:
{decisions from Phase 1}
Baseline evidence summary from gather/clarify:
{summary from Phase 2.1}
Unresolved evidence gaps to investigate:
{gap list for prior-art lane from Phase 2.3}
## Output Persistence
Write your complete findings to: {session_dir}/plan-prior-art-research.md
At the very end of the file, append this sentinel marker on its own line:
<!-- AGENT_COMPLETE -->Sub-agent B: Codebase Analyst
Task tool:
subagent_type: Explore
max_turns: 20
prompt: |
Analyze the codebase for patterns, dependencies, and constraints relevant
to this task. For each finding:
- Cite file paths and line numbers
- Assess impact on the plan (High/Medium/Low)
- Note existing patterns that should be followed
Report evidence only — do not make decisions.
Task:
{task description from Phase 1}
Key decisions:
{decisions from Phase 1}
Baseline evidence summary from gather/clarify:
{summary from Phase 2.1}
Unresolved evidence gaps to investigate:
{gap list for codebase lane from Phase 2.3}
## Output Persistence
Write your complete findings to: {session_dir}/plan-codebase-analysis.md
At the very end of the file, append this sentinel marker on its own line:
<!-- AGENT_COMPLETE -->Wait for all launched sub-agents to complete. Re-validate each launched file using the context recovery protocol.
2.5 Read output files
After sub-agents complete, read the result files from the session directory (not in-memory return values):
{session_dir}/plan-prior-art-research.md— Prior art research findings{session_dir}/plan-codebase-analysis.md— Codebase analysis findings
Use these file contents as additional input for Phase 3 synthesis.
2.6 Persistence Gate (Critical when gap-fill research runs)
Apply the stage-tier policy from the context recovery protocol when Phase 2.4 launched any gap-fill sub-agent:
plan-prior-art-research.mdandplan-codebase-analysis.mdare critical.- If either file is still invalid after one bounded retry, hard fail the
stage with explicit file-level error and stop plan drafting. - Record gate path in output (
PERSISTENCE_GATE=HARD_FAILor equivalent).
If no gap-fill sub-agent was launched, record PERSISTENCE_GATE=SKIP_NO_GAP and proceed.
Phase 3: Plan Drafting
Synthesize baseline evidence (from gather/clarify artifacts) and any additional gap-fill research into a structured plan. Read {SKILL_DIR}/../../references/plan-protocol.md for protocol rules on location, sections, and format.
Cross-Cutting Pattern Gate
Before finalizing Steps, scan for cross-cutting patterns:
- Identify steps that apply identical logic to 3+ targets (files, skills, modules)
- If found: add a Step 0 that creates a shared reference file for the common pattern. Subsequent steps reference the shared file — never duplicate the pattern inline.
- If not found: proceed normally
Prohibited instructions in step descriptions:
- "동일 적용" / "apply the same pattern" / "same as Step N"
- Any instruction that delegates architecture to parallel implementors
Each step must either reference a shared file or contain self-contained instructions. Parallel agents cannot see each other's work, so sharing must be decided at plan level.
Preparatory Refactoring Check
Before finalizing Steps, assess whether preparatory refactoring is needed:
- For each target file in "Files to Create/Modify", check its line count
- If a file is 300+ lines AND 3+ changes are planned for it:
- Add a Step 0 that extracts separable blocks to reference files
- This reduces edit surface for subsequent steps and improves commit independence
- If no files meet the threshold: proceed normally
Plan Structure Contract
Use `plan-protocol.md` as the single source of truth for:
- Required plan/lesson sections
- Success criteria baseline structure
- Artifact location and creation timing
lessons.mdformat and language policy
Keep only these skill-specific additions in the generated plan:
Add a required
## Commit Strategysection:- Per step (default for modular changes)
- Per change pattern (for cross-cutting changes)
- Custom (explicit commit boundaries + rationale)
Keep Success Criteria in the two-layer format:
- Behavioral (BDD) scenarios
- Qualitative non-functional criteria
Expand
## Decision Logto include evidence/source and resolution metadata:# Decision Point Evidence / Source (artifact or URL + confidence) Alternatives Considered Resolution Status Resolved By Resolved At (UTC) 1 ... ... ... ... open/resolved ... ... Status=open: leaveResolution,Resolved By, andResolved AtasTBD.Status=resolved: cite concrete evidence (e.g.,plan-codebase-analysis.md,plan-prior-art-research.md, URL).
Research Integration
- Start from gather/clarify evidence as the primary baseline for plan rationale
- Incorporate gap-fill findings only for unresolved decisions
- Note where codebase patterns inform implementation steps
- Flag conflicts between best practices and existing code as decision points
Phase 4: Write Artifacts
Determine the session directory following plan-protocol.md location rules:
- If the user provided an output path, use it.
- Otherwise run
{CWF_PLUGIN_DIR}/scripts/next-prompt-dir.sh --bootstrap <title>and use its output path.--bootstrapcreates the resolved directory, initializes missingplan.md/lessons.md, and pre-registers the session incwf-state.yamlsessionswhen state exists.
Write two files:
plan.md
Write the complete plan from Phase 3, following plan-protocol.md and the skill-specific additions above (Commit Strategy, expanded Decision Log).
lessons.md
Initialize lessons.md using the shared format in plan-protocol.md (user language). If no learnings exist yet, create the file with a header and a short placeholder note.
Before finishing this skill, append plan-stage learnings captured during user ping-pong (for example: clarified constraints, corrected assumptions, revealed preferences). Do not defer these to implementation.
Phase 5: Review Offer
After writing plan artifacts, suggest review:
Plan drafted at .cwf/projects/{dir}/plan.md.
For a multi-perspective review before implementation, run:
cwf:review --mode planRules
- Evidence-first before drafting: Use gather/clarify artifacts as baseline first; run additional research only for unresolved evidence gaps
- Two-layer criteria: Success criteria must include both BDD and qualitative layers
- Cite evidence: Reference specific files, URLs, or sources for plan decisions
- Follow protocol: Adhere to plan-protocol.md for format and location
- Don't over-plan: Keep steps actionable and concrete, avoid excessive detail
- Preserve task intent: Refine the approach, don't redirect the goal
- Cross-cutting → shared reference first: When identical logic applies to 3+ targets, create a shared reference file as Step 0. "동일 적용" is a plan smell — replace with an explicit shared file path
- Commit Strategy is required: Every plan must include a Commit Strategy section. Default is one commit per Step.
- Preparatory refactoring check: When a target file is 300+ lines with 3+ planned changes, add Step 0 to extract separable blocks first
- Conditional critical persistence hard-fail: When gap-fill research is launched, if
plan-prior-art-research.mdorplan-codebase-analysis.mdremains invalid after bounded retry, stop with explicit error instead of drafting from partial data - Language override is mandatory:
plan.mdis in English;lessons.mdis in the user's language - Plan-stage learnings must be logged immediately: Record conversation-time learnings in
lessons.mdduring planning, not only after implementation
References
- plan-protocol.md — Plan & Lessons Protocol