spec-kit-establish-constitution
Skill6 starsChanged 2 months agoApache-2.0View on GitHub
Create or update .speckit/memory/constitution.md — a project's non-negotiable architecture, security, and quality principles — from explicit documentation and/or by mining consistent patterns across existing code. Every mined principle carries evidence, coverage, and confidence, and none becomes binding without explicit user confirmation. Optional, and re-invocable to check whether current code has drifted from an existing constitution. When a pattern-miner agent is requested, generates compatible definitions for both Kiro CLI and Claude Code.
In this repository22 other files it gives its agents.
- backend-api-standardsSkill
- brain-orchestratorSkill
- brand-guidelinesSkill
- code-architecture-explainerSkill
- code-documentationSkill
- create-pull-requestSkill
- frontend-architectureSkill
- frontend-designSkill
- gh-stackSkill
- git-commitsSkill
- latex-academic-reportsSkill
- pre-pr-reviewSkill
- project-intelligenceSkill
- project-setupSkill
- spec-kit-amend-artifactsSkill
- spec-kit-analyze-consistencySkill
- spec-kit-execute-tasksSkill
- spec-kit-generate-planSkill
- spec-kit-generate-specSkill
- spec-kit-generate-tasksSkill
- spec-kit-sync-artifactsSkill
- verify-before-implementSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
17 rules. About 0 are common, 9 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 28
Always consider the complete user message and any files or attachments available in the current conversation, even when $ARGUMENTS appears …
- Distinctive: line 49
Do not invent principles: Every principle traces to an explicit document citation or a mined code pattern with concrete evidence (file …
- Very specific: line 71
constitution.mdis versioned with a changelog: Every update states what changed and why. - Distinctive: line 76
Sampling must be representative: Do not declare a pattern "dominant" from one or two examples — state how many instances of the category …
- Very specific: line 82
Generate portable agent pairs: If this workflow creates a pattern-miner (or other support agent), it must generate and validate both a Kiro …
- Distinctive: line 109
Read it before Phase 1 below.
- Very specific: line 122
If logging is off (RUN_LOG: off), continue normally.
- Distinctive: line 135
If the user's intent is ambiguous between these, ask which one before proceeding — they have very different scopes.
- Very specific: line 142
Read, in order: README(s), ADRs, style guides, and any project-specific architecture skill already active in this project …
- Distinctive: line 150
Do not mine the entire codebase blindly.
- Distinctive: line 152
If the user named an area ("just the data access layer"), mine only that.
- Distinctive: line 219
Read the entire current file and changelog.
- Distinctive: line 220
Treat the request as a delta — mine or cite only the new/changed area, do not re-derive unrelated sections.
- Very specific: line 225
If updating a principle contradicts a decision already made in an existing plan.md/spec.md elsewhere in the project, surface that conflict …
- Distinctive: line 231
When explicitly invoked to check code against an existing constitution, without adding to it:
- Very specific: line 248
Before inspecting the project, check .speckit/extensions.yml per spec-kit-shared/artifact-conventions.md's schema, reading …
- Very specific: line 254
After writing/updating constitution.md, process hooks.after_constitution the same way.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Establish Constitution — Project Convention Skill
Purpose
Make a project's real conventions explicit — the ones already written down, and the ones that
exist only as a consistent pattern across the code nobody documented — so every other spec-kit
skill can follow them "al pie de la letra" instead of guessing or reinventing them per feature.
This is the one skill in the kit that is genuinely optional: every other skill already handles a
missing constitution.md as N/A, not an error. This skill is what a project runs when it wants
that N/A to become real, cited principles instead.
This skill produces a governance document. It does not implement or refactor code to match
the constitution — that enforcement happens downstream, in spec-kit-generate-plan's Convention
Enforcement and spec-kit-execute-tasks's adherence to active architecture skills.
User Input
$ARGUMENTSAlways consider the complete user message and any files or attachments available in the current
conversation, even when $ARGUMENTS appears literally or is empty. Common inputs: "establish a
constitution for this project," a specific area to focus on ("just the data access layer"), or a
request to re-check the existing constitution against current code.
Core Principle
Explicit conventions are cited, not authored. Inferred conventions are mined with evidence, and never binding until the user confirms them.
- A principle sourced from a README/ADR/architecture skill is quoted and cited — this skill does not paraphrase it into something subtly different.
- A principle mined from code is a claim about the code as it exists today, not a value judgment about whether that pattern is good. Low coverage or real inconsistency means "report a mixed pattern," not "declare a winner."
- Nothing mined is written into
constitution.mdas binding without the user explicitly confirming it — the code being consistent today doesn't make a pattern intentional, and a project mid-migration can look "consistent" in exactly the wrong direction.
Non-Negotiable Rules
- Do not invent principles. Every principle traces to an explicit document citation or a mined code pattern with concrete evidence (file examples) — never to "how projects like this usually work."
- Explicit and Inferred are always labeled separately, never blended into one undifferentiated list — a reader must be able to tell which principles are sourced from documentation and which were mined from code.
- A mined principle requires real coverage and confidence, computed from actually sampling every relevant instance (or a stated, representative subset for a very large codebase) — not from the first two files that happened to agree.
- Low coverage or real inconsistency blocks promotion to a binding principle. Report it as a "mixed pattern detected" finding instead, and let the user decide the standard — do not average, round up, or otherwise force a verdict the evidence doesn't support.
- No mined principle is written into
constitution.mdas binding without explicit user confirmation. Present every candidate for confirm/reject first; an unconfirmed candidate does not get saved as a "draft binding" principle — it's simply not in the file yet. - If neither explicit documentation nor a consistent pattern exists for an area, that section stays empty. Never fill it with generic "best practice" from memory to make the document look complete.
- This skill does not implement or refactor code. It documents;
spec-kit-generate-planandspec-kit-execute-tasksare what actually enforce a constitution during real feature work. - Reuse
verify-before-implementto inspect the project before citing anything — explicit or inferred — as "existing." constitution.mdis versioned with a changelog. Every update states what changed and why; nothing is silently overwritten.- This skill is optional and re-invocable, not "run once." It can be invoked again specifically to check whether current code has drifted from an already-established constitution — a mismatch is reported, not silently resolved in either direction.
- Sampling must be representative. Do not declare a pattern "dominant" from one or two examples — state how many instances of the category exist and how many were actually sampled.
- A single documented, legitimate exception does not make a pattern "mixed." If 9 of 10 instances agree and the 10th is an explained special case, that is still high confidence — do not manufacture false inconsistency out of one reasonable outlier, any more than Rule 4 allows forcing a verdict out of real inconsistency.
- Generate portable agent pairs. If this workflow creates a
pattern-miner(or other support agent), it must generate and validate both a Kiro CLI and a Claude Code definition per the shared portability contract.
Shared Files
spec-kit-shared/… paths resolve against <skills-root>, the parent of this skill's own
directory: .claude/skills/ or the host's equivalent once installed, the repository root in a
checkout of the kit. Run shared scripts from the project root as
node <skills-root>/spec-kit-shared/scripts/<script>.mjs, with <skills-root> written out as an
absolute path; a bare spec-kit-shared/… script path resolves against the project and fails.
Cross-Platform Agent Compatibility
The complete portability contract lives in spec-kit-shared/agent-portability.md. Before
generating, validating, or reporting on the pattern-miner role — or any other agent this skill
materializes — read that file completely and follow it exactly. If the active host cannot resolve
the reference, follow its fallback section.
pattern-miner is the standard role for this skill: sampling every instance of one component
category to determine its dominant pattern, in parallel with mining other categories. Do not
invent a different name or redefine it for another purpose.
Artifact Conventions
.speckit/memory/constitution.md's location and the extensions.yml hook keys
(before_constitution/after_constitution) live in spec-kit-shared/artifact-conventions.md.
Read it before Phase 1 below.
Run Log
Record this run per spec-kit-shared/artifact-conventions.md § Run Log (project-wide, so <dir> is .speckit): start with
node <skills-root>/spec-kit-shared/scripts/log-event.mjs <dir> run.start --skill spec-kit-establish-constitution mode=<mode> and pass the printed RUN_ID to every
later call; end with a run.end event (status, reason when it stops, next), also when the run stops early.
Record these decisions, each with a one- or two-sentence rationale citing its IDs:
decisionkindotherfor each candidate principle:valueconfirmed / rejected / mixed pattern, with its evidenceuserevents for the confirmation gatereadiness— the constitution written, updated, or left unchanged
If logging is off (RUN_LOG: off), continue normally.
Input Contract
New vs. Update vs. Drift-Check Mode
- New mode:
.speckit/memory/constitution.mddoes not exist. Proceed through Phases 1–6. - Update mode: it exists and the user wants to add/revise principles (e.g. a new area of the codebase, or a principle that's changed). Read the existing file and its changelog first; treat the request as a delta, per § Updating an Existing Constitution.
- Drift-check mode: the user explicitly wants to check current code against the existing constitution, not add to it. Skip straight to § Drift-Check Mode.
If the user's intent is ambiguous between these, ask which one before proceeding — they have very different scopes.
Workflow (New and Update Modes)
Phase 1 — Load Explicit Sources
Read, in order: README(s), ADRs, style guides, and any project-specific architecture skill already
active in this project (frontend-architecture, backend-api-standards, or an equivalent). Cite
each as an Explicit source with its path — quote the relevant statement, do not paraphrase it
into something subtly different. If constitution.md already exists (update mode), read it and
its changelog completely first.
Phase 2 — Determine Mining Scope
Do not mine the entire codebase blindly. Scope to what's relevant:
- If the user named an area ("just the data access layer"), mine only that.
- Otherwise, identify the component categories with more than one existing instance (repositories, controllers/routes, service classes, UI components at the same level, test files) — these are the categories where a "dominant pattern" claim is even possible. A category with only one instance has nothing to mine a pattern from; note it as "insufficient instances to mine," not as a failure.
Phase 3 — Mine Patterns Per Category
For each category in scope, via verify-before-implement's inspection discipline:
- Enumerate every instance (or, for a very large codebase, a stated representative subset — name
the sampling method, e.g. "every instance under
src/services/, 14 files"). - Identify the dominant structural pattern: folder/file structure, layering, error-handling convention, naming convention, dependency-injection style, testing convention — whichever are observable and relevant to the category.
- Compute coverage (how many instances match the dominant pattern out of how many sampled)
and confidence:
- High: coverage is near-total, and any exception is a documented, explainable special case (Rule 12).
- Low: real, unexplained inconsistency exists across a meaningful fraction of instances (Rule 4) — report as a mixed pattern, do not promote.
- This category-by-category mining is naturally independent per category — when there are several
categories to mine, delegate each to a separate
pattern-minersubagent in parallel, each scoped only to its own category's files (not the whole codebase or the parent conversation).
Phase 4 — Draft Candidates
- Explicit sources become cited principles directly — no coverage/confidence computation needed; they're already authoritative for what they state.
- High-confidence mined patterns become draft
Inferredprinciple candidates, each with its evidence (concrete file examples) and coverage stat. - Low-confidence/mixed findings become open questions for the user, not draft principles — presented as "category X shows pattern A in N files and pattern B in M files; which should be the standard going forward?"
Phase 5 — User Confirmation (mandatory gate)
Present every Inferred candidate and every mixed-pattern question to the user. Nothing Inferred
is written into constitution.md until explicitly confirmed or resolved here (Rule 5). A
candidate the user rejects, or a mixed-pattern question left unanswered, is simply not written —
it does not get saved as a pending/draft entry inside the file.
Phase 6 — Write constitution.md
Structure principles by area (e.g. Architecture, Data Access, API/Contracts, Error Handling,
Testing, Security) — only sections with real content, per Rule 6. Each principle is tagged
Explicit or Inferred, with its source or evidence:
# Project Constitution
**Version**: [N] | **Last updated**: [date]
## Changelog
- **vN** ([date]): [what changed and why]
## [Area, e.g. Data Access]
- **C-01** (`Explicit`, source: `docs/architecture.md`): [quoted/cited principle].
- **C-02** (`Inferred`, coverage: 12/13 services, confidence: high — evidence:
`src/services/orderService.js`, `src/services/userService.js`, ...): [principle statement].Updating an Existing Constitution
- Read the entire current file and changelog.
- Treat the request as a delta — mine or cite only the new/changed area, do not re-derive unrelated sections.
- Preserve existing principle IDs where semantics are unchanged; add new IDs for new principles; never silently reuse an ID for a different principle.
- Bump the version and add a changelog entry describing exactly what changed and why.
- If updating a principle contradicts a decision already made in an existing
plan.md/spec.mdelsewhere in the project, surface that conflict explicitly — do not silently supersede prior work.
Drift-Check Mode
When explicitly invoked to check code against an existing constitution, without adding to it:
- Read
constitution.mdcompletely. - For each principle (
ExplicitorInferred), re-inspect the relevant code the same way Phase 3 does. - Report each principle as holding, drifted, or now-mixed (some instances still comply, others don't).
- Do not auto-fix either direction. A drifted principle is a decision point: either the code
needs to be brought back in line (a job for
spec-kit-execute-tasks/spec-kit-generate-planon a future feature, not this skill), or the constitution itself needs updating because the project's real direction changed. Present both options; let the user decide. - This is a read-only mode with one exception: if the user explicitly asks to update the constitution as a result of this check, that becomes an Update-mode invocation (§ Updating an Existing Constitution), not an automatic side effect of the drift check itself.
Pre-Execution Extension Hooks
Before inspecting the project, check .speckit/extensions.yml per
spec-kit-shared/artifact-conventions.md's schema, reading hooks.before_constitution. Follow
the same enablement/condition/mandatory-vs-optional rules the other spec-kit skills use.
Mandatory Post-Execution Hooks
After writing/updating constitution.md, process hooks.after_constitution the same way.
Completion Report
Report:
RUN_ID: this run's log ID, oroff.MODE: New / Update / Drift-Check.CONSTITUTION_FILE:.speckit/memory/constitution.mdpath.VERSION: current version after this run.EXPLICIT_PRINCIPLES/INFERRED_PRINCIPLES: counts, each with a one-line list.MIXED_PATTERNS_REPORTED: count and areas, or "none".REJECTED_CANDIDATES: count ofInferredcandidates the user did not confirm, or "none".DRIFT_FOUND(Drift-Check mode only): principles that no longer hold, or "none".AGENTS:none, or every generated Kiro/Claude path with validation and parity status.NEXT: if mixed patterns remain unresolved, name them; otherwise recommend the constitution is now available tospec-kit-generate-spec/spec-kit-generate-planas governing context.
Done When
- The run was logged from
run.starttorun.end(or logging is off). - The mode (New/Update/Drift-Check) was determined, explicitly if ambiguous.
- Explicit sources were read and cited, not paraphrased.
- Mining scope was determined deliberately, not applied blindly to the whole codebase.
- Every mined category's coverage and confidence were computed from actually sampling instances, with the sampling method stated.
- Low-confidence/mixed patterns were reported as open questions, never promoted to binding principles.
- No
Inferredprinciple was written without explicit user confirmation. constitution.md(if written/updated) is versioned with an accurate changelog entry.- No product code was implemented or refactored by this skill.
- Every generated support agent has a validated Kiro/Claude pair, or
AGENTS: noneis reported.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

