.claude/skills/speckit-optimize-learn/SKILL.md
Analyze AI session patterns to suggest constitution rules or memory entries.
npx skillsauth add pradeepmouli/zod-to-form speckit-optimize-learnInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
$ARGUMENTS
You MUST consider the user input before proceeding (if not empty).
Arguments: --rules-only to skip memory suggestions, --memory-only to skip rule suggestions, --since <commit> to limit analysis scope.
Analyze the current AI session's work to identify patterns of mistakes, repetitive corrections, and governance gaps. Produce suggestions for new constitution rules or memory entries that would prevent these patterns in future sessions. Apply nothing without explicit user consent.
This command answers: "What did this AI session learn the hard way that future sessions should know from the start?"
When to use: End of an implementation session, before creating a PR/MR. Run while the session context is still fresh.
.specify/memory/constitution.md (follow redirects) for the constitution. Memory files go to the tool's memory system (e.g., .claude/ for Claude Code).Identify the work done in the current session:
Git-based scope (primary):
git log --oneline to find recent commits--since <commit> is provided, use that as the starting pointSESSION_RANGEDiff analysis:
git diff <SESSION_RANGE> to get the full session diffgit diff --stat <SESSION_RANGE> for a file-level overviewSESSION_FILESSession metadata:
If no git changes are found, inform the user: "No session changes detected. This command analyzes git history to find patterns. Run it after making changes."
Load the constitution (following the standard resolution chain from .specify/memory/constitution.md). Parse into a flat list of rules for gap analysis.
Load config from .specify/extensions/optimize/optimize-config.yml (or defaults) for:
min_corrections_to_flag (default: 2)include_memory_suggestions (default: true)include_rule_suggestions (default: true)Analyze the session's git history for evidence of repeated corrections:
For each file in SESSION_FILES, check commit history within SESSION_RANGE:
Same-file re-edits: Files modified in 3+ separate commits within the session. This suggests the AI got it wrong initially and had to correct multiple times. Record the file and the nature of each change.
Revert patterns: Look for pairs of commits where the second commit undoes part of the first (same lines modified in opposite directions). This indicates the AI made a wrong choice that was immediately corrected.
Fix-after-fix chains: Commits with messages containing correction indicators: "fix", "actually", "oops", "correct", "should be", "typo", "missed", "forgot". Each represents a mistake the AI made.
Checkstyle/linter fix commits: Commits that only fix style violations (detected by diffing against checkstyle or linter output). These indicate the AI didn't follow style rules the first time.
Look for the same type of change applied to multiple files:
Boilerplate additions: Same code pattern added to 3+ files (e.g., adding this. prefix, adding file headers, adding import ordering). If the AI had to manually apply the same transformation many times, it suggests a rule that should be automated.
Naming corrections: Same type of rename applied multiple times (e.g., removing Entity suffix from non-entity classes, or adding it to entity classes). Suggests unclear naming rules.
Pattern enforcement: Same structural change across files (e.g., converting @Service annotations to @Bean registration). Suggests the AI kept defaulting to a wrong pattern.
For each detected mistake pattern:
Beyond mistakes, identify tasks the AI performed repeatedly that suggest missing automation or rules:
Manual enforcement: Tasks that could be automated (e.g., repeatedly checking import order → should be enforced by a linter, repeatedly adding JavaDoc → should be caught by checkstyle)
Boilerplate generation: Repeated creation of similar files (e.g., creating test classes with the same structure, creating DTOs with the same patterns). Suggests templates or generators would help.
Cross-file consistency: Changes that required updating multiple files to stay consistent (e.g., adding a field to an entity requires updating the DTO, the mapper, and the test). Suggests a documentation or tooling gap.
For each detected pattern, generate a proposal. Proposals are either constitution rules or memory entries.
Only propose constitution rules when the pattern:
Format for each proposed rule:
### Proposed Rule: <short title>
**Type**: Constitution Rule
**Principle Placement**: <existing principle name, or "New Principle: <name>">
**Severity**: MUST / SHOULD
**Rule Text**:
> <Concrete, deterministic rule text. MUST/SHOULD qualified. No vague language.>
**Rationale**: <What session pattern triggered this>
**Evidence**:
- `<file>:<line>` — <what happened>
- Commit `<hash>` — <what the fix was>
- Pattern repeated <N> times across <files>
**Enforcement Suggestion**: <How to automate: checkstyle rule, Gradle task, CI check, or "manual review only">
**Token Cost**: ~<estimated tokens this rule adds to the constitution>
Propose memory entries when the pattern:
Format for each proposed memory:
### Proposed Memory: <short title>
**Type**: Memory Entry
**Memory Type**: feedback / user / project / reference
**File Name**: <proposed filename, e.g., feedback_import_order.md>
**Content**:
> <Proposed memory content, structured per the memory type's conventions>
**Rationale**: <What session pattern triggered this>
**Evidence**:
- <specific examples from the session>
Present all proposals to the user:
## Session Learning Report
**Session**: <commit range>
**Files Modified**: <count>
**Commits Analyzed**: <count>
### Session Patterns Detected
| # | Pattern | Occurrences | Type | Proposal |
|---|---------|-------------|------|----------|
| 1 | <pattern description> | X times | Mistake | Rule / Memory |
| 2 | <pattern description> | X times | Repetitive | Rule / Memory |
| ... | ... | ... | ... | ... |
### Existing Rules Violated
| # | Rule | Principle | Violation Count | Issue |
|---|------|-----------|-----------------|-------|
| 1 | <rule text> | <principle> | X | Ambiguous / Easy to miss |
**Suggestion**: Rewrite for clarity → <proposed rewrite>
### Proposed Constitution Rules (<count>)
[List each proposed rule per format above]
### Proposed Memory Entries (<count>)
[List each proposed memory per format above]
### Summary
- **Total patterns detected**: X
- **Constitution rules proposed**: X (adds ~Y tokens to governance)
- **Memory entries proposed**: X
- **Existing rules to rewrite**: X
**Which proposals would you like to apply?**
Select by number, "all rules", "all memories", or "none".
Wait for user selection. Do NOT apply anything without explicit consent.
For each user-approved proposal:
Constitution rules:
/speckit.constitution with the specific rule text, principle placement, and rationaleMemory entries:
MEMORY.md)Rule rewrites (for existing rules that were violated due to ambiguity):
/speckit.optimize.run --category ai_interpretability for a targeted rewrite/speckit.constitution for manual amendment## Session Learning Complete
### Applied
- Constitution rules handed to `/speckit.constitution`: X
- Memory entries written: X
- Rule rewrites suggested: X
### Declined
- [List of declined proposals — preserved in report for future reference]
### Learning Report Saved
- Report: `.specify/optimize/learning-report-<date>.md`
### Recommended Follow-Up
- Run `/speckit.constitution` to formally add approved rules
- Run `/speckit.optimize.run` to verify the new rules don't create contradictions
- Run `/speckit.optimize.tokens` to check token budget after additions
Ask the user: "Save this learning report to .specify/optimize/learning-report-<date>.md?"
If approved, save the full report for historical reference. This enables trend analysis across sessions: "Are the same patterns recurring despite rules being added?"
Every proposal cites specific files, line numbers, commits, and pattern counts. No speculative rules based on general best practices — only rules motivated by observed session behavior.
Prefer memory entries (zero token cost to future sessions) over constitution rules (permanent token cost). Only propose constitution rules when the pattern is project-wide, tool-agnostic, and would benefit all future AI sessions.
Every proposed rule text is concrete, MUST/SHOULD qualified, and deterministic. If the AI agent writing the proposal cannot make the rule deterministic, it should propose a memory entry instead.
The learning report is a proposal, not an action. The user reviews each suggestion individually and decides what to keep. Declined proposals are preserved in the report for future reconsideration.
This command only analyzes the current session's work. It does not dig into older history or make suggestions based on past sessions. For historical analysis, use /speckit.optimize.run which audits the full constitution.
tools
Use when working with zod-to-form (core, react, cli, codegen, vite).
tools
Vite plugin for zod-to-form — transforms ?z2f imports into generated form components and optionally replaces <ZodForm> JSX call sites with generated components at build time Use when: You want `import SignupForm from './signup.schema?z2f'` to Just Work in a.... Also: vite, vite-plugin, zod, zod-v4, codegen, forms, form-generation, schema-driven, react-hook-form, build-plugin, jsx-transform.
development
Runtime <ZodForm> renderer for Zod v4 schemas Use when: You need form rendering in storybook, playgrounds, or low-traffic admin UIs —.... Also: zod, zod-v4, react, forms, form-generation, react-hook-form, schema-driven, dynamic-forms, form-renderer, hookform-resolver, zod-form-renderer.
development
Schema walker and processor registry for Zod v4 form generation Use when: You want per-field validation instead of whole-form validation. Also: zod, zod-v4, forms, form-generation, schema, schema-walker, processor-registry, react-hook-form, schema-driven, form-schema, zod-registry.