/lawcheck:setupfrom lawcheck
Writes the first Lawcheck law of this repository from the code as it is, and asks the user before it forbids a use the code already makes. When the user asks, it also writes advice on the architecture, or a target architecture with a plan, as a proposal beside the law that becomes law only item by item on the user's yes. Use it when the user asks for a Lawcheck law, or for Lawcheck to be set up in this repository; the user can also type /lawcheck:setup.
Ships in lawcheck. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Write no text to the user until you ask a question or give the final message. In Claude Code, every text between two tool calls is a message to the user, so put none there: no note on what you read, run or found.
Read what the user asked for, the words typed with the command and before it or the request that started this skill, and pick the row of "What the user asked for" below. Ask no question about which row.
Run lawcheck docs agent-setup, in every row. That page is the procedure of the first law, and the files of advice and of a target use its parts. It comes with the Lawcheck that runs here, so it matches the commands. Say nothing about advice or a target before that page and the measurements it asks for have run.
lawcheck: give the user the two ways to install it, and let the user choose and run one. npm install --global lawcheck puts one program on this machine, for every repository. npm install --save-dev lawcheck pins the version in this project's package.json, for the whole team and CI; then run each lawcheck as npx --no-install lawcheck, and write runner: npx into .lawcheck/config.yaml after lawcheck init. End the turn. When the user says it is installed, go on with what the user first asked for. Never ask the user to type the command or the request again.agent-setup: the installed Lawcheck is older than this plugin. Tell the user to update it with the command of the way it was installed, and stop.Every message to the user follows the page's part "The words for the user". The page's steps 3 and 10 may ask the user questions. Such a message stops after the last question, with no next step. The final message carries the next step. Every reply after the user's last answer is the final message, whole, with all its labels: also after "no", "not now", "thanks" or "I'll think about it".
| The user | Do |
|---|---|
types /lawcheck:setup alone, or asks for a law, with no law here | the page, all of it |
asks for advice: what could be better, what to tighten, recommendations, or types advice | with no law here, the page first, all of it; then the advice |
asks for a target architecture, a redesign, a plan to rebuild, or says where the code should get to, or types target | with no law here, the page first, all of it; then the target |
| asks for advice and for a target | the page when no law is here, then the advice, then the target |
types /lawcheck:setup alone, or asks for a law, and a law is already here | say that the law stands and that lawcheck prime says how to change it, and stop |
asks to make an item of .lawcheck/advice.md or a step of .lawcheck/target.md law | the page's step 1 up to lawcheck prime, then what the file of the advice or the target says to do on a yes, for that item or step alone |
The user's words count in any language, and so do the words typed after the command.
With a law already here, the advice and the target start from the law that stands. Do the page's step 1 up to lawcheck prime, then its step 2, and go to the file of the advice or the target. The page's other steps do not run.
With no law here, the advice or the target starts only after the four checks of the page's step 11 hold. When step 10 asked questions, that is after the user answered them. The final message then holds everything that step 11 lists and what the file of the advice or the target says to tell. Its next step is still to commit .lawcheck/law.yaml and the rule files.
The final message of the advice or the target has the labels of the page's step 11, in their order, then its own part. With a law already here, The law and Debt describe the law that stands, so the user can tell the law from the proposal.
With both asked, the target starts after the user answered the question of the advice, so an item the user accepted is already law when the target starts from it.
Read a file of references/ only for the row that names it.
No final message offers advice, a target or another run of the skill. The user asks for them in their own words, with or without /lawcheck:setup.
A line that says how to make an item or a step of a proposal file law is no offer, because the file already holds that item.
Advice and a target are proposals. They hold in every line of both:
.lawcheck/advice.md or .lawcheck/target.md. Lawcheck reads neither. Its first paragraph says that a coding agent wrote it, the date, the commit (git rev-parse --short HEAD), the Lawcheck version, and "Nothing in this file is law."written, direction, cycle, few, mixed or convention, with the file and line and the words quoted, or with the measured counts. In a target, also aim: the user's words, quoted. The name of a pattern, such as "layers", "hexagonal" or "clean architecture", is never evidence. What the files do is.lawcheck check --full --base HEAD exits 0. An accepted item leaves the file, because the law holds it from then on. A yes to a whole proposal writes no law..lawcheck/, except for a CI job the user asks for, as the page's part "A CI job the user asks for" says. Until the user says yes to an item, change in .lawcheck/ only the proposal file and what this session's run of the page wrote. The page's part "Never" holds here too.Each lawcheck check --full here is a deliberate audit of the whole code, run on purpose to count or prove a candidate law. It is no step for each later change, and no step of CI.
Make the temporary folder and save uses.mjs in it as the page's part "Measure a law that is not in force" says. Save this script there once, as $KEEP/total.mjs:
let text = '';
for await (const chunk of process.stdin) text += chunk;
const report = JSON.parse(text);
if (report.schema !== 'lawcheck-check/0') process.exit(2);
const uses = report.findings.filter((finding) => finding.code === 'forbidden-use');
const count = (n, word) => `${n} ${word}${n === 1 ? '' : 's'}`;
console.log(`total: ${count(uses.length, 'use')} in ${count(new Set(uses.map((finding) => finding.file)).size, 'file')}`);
const debt = report.findings.filter((finding) => finding.debt);
console.log(`debt (outside this change): ${debt.length === 0 ? 'none' : `${count(debt.length, 'finding')} in ${count(new Set(debt.map((finding) => finding.file)).size, 'file')}`}`);
Write the candidate into that folder as candidate.yaml: the whole law, the same as .lawcheck/law.yaml except in its types and their may_use lists. Then run this as one shell command:
$ cp .lawcheck/law.yaml "$KEEP/law.yaml" && cp "$KEEP/candidate.yaml" .lawcheck/law.yaml; lawcheck check --full --base HEAD --json > "$KEEP/report.json"; lawcheck prime > "$KEEP/prime.txt"; lawcheck explain . > "$KEEP/types.txt"; cp "$KEEP/law.yaml" .lawcheck/law.yaml && cmp "$KEEP/law.yaml" .lawcheck/law.yaml; node "$KEEP/uses.mjs" < "$KEEP/report.json"; node "$KEEP/total.mjs" < "$KEEP/report.json"; if grep -q 'shortened to fit' "$KEEP/prime.txt"; then echo 'prime: shortened'; fi
It prints the table of the page's part, then one line total: with every use the candidate forbids and the files that make them, each file counted once. The line debt (outside this change): after it is the line that lawcheck check --full --base HEAD prints with the candidate as the law, without its counts of waivers and unresolved uses. A last line prime: shortened means the candidate does not fit lawcheck prime unshortened. The file $KEEP/report.json keeps each use with its file, line and type, for a question the table does not answer. The file $KEEP/types.txt holds the count of files of each type of the candidate. Lines that start with an error code mean the candidate is no valid law: fix the candidate, never the code.
A script rule that is not law yet is counted the same way, with its file in the folder as <id>.mjs and candidate.yaml holding the law plus the rule's entry and why. Pick an id the law does not use. Run as one shell command:
$ cp .lawcheck/law.yaml "$KEEP/law.yaml" && cp "$KEEP/candidate.yaml" .lawcheck/law.yaml && mkdir -p .lawcheck/rules && cp "$KEEP/<id>.mjs" .lawcheck/rules/<id>.mjs; lawcheck try <id> '<pattern>'; rm -f .lawcheck/rules/<id>.mjs; rmdir .lawcheck/rules 2>/dev/null; cp "$KEEP/law.yaml" .lawcheck/law.yaml && cmp "$KEEP/law.yaml" .lawcheck/law.yaml
Delete the folder with rm -r and its path before the final message.
lawcheck init. Send all the questions of step 10 in one call. When step 10 has more questions than the tool takes in one call, write them all in your message as one numbered list instead, and end the turn.claude -p, a person still reads your message and answers in the next prompt. Ask the questions of step 3 or 10, of the advice or of the target in your message, put nothing after them, and end the turn. Never skip them because the session looks non-interactive: skip them only when the user said that no one will answer..lawcheck/law.yaml at that moment. So a measurement keeps its candidate outside the repository and swaps it in and out within one shell command, as the page's part "Measure a law that is not in force" shows, and as "Measure for a proposal" above does. Write a proposal file only when no candidate is in place..lawcheck/law.yaml and the rule files. That is expected.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub krzysztofdudek/lawcheck --plugin lawcheck