Skip to content

Claude Code guide in three levels, Beginner to Advanced: hands-on lessons with checked exercises, every volatile fact cited to its source. Independent community guide.

ci: lint em dashes, images and lesson structure (#52)

Wesam Abousaida326a000d418
diff --git a/.github/scripts/fixtures/added-em-dash/base/docs/hooks.md b/.github/scripts/fixtures/added-em-dash/base/docs/hooks.md
new file mode 100644
index 0000000..eaca61d
--- /dev/null
+++ b/.github/scripts/fixtures/added-em-dash/base/docs/hooks.md
@@ -0,0 +1,3 @@
+# Hooks
+
+A hook runs a command at a lifecycle event.
diff --git a/.github/scripts/fixtures/added-em-dash/fixture.json b/.github/scripts/fixtures/added-em-dash/fixture.json
new file mode 100644
index 0000000..ca09cf6
--- /dev/null
+++ b/.github/scripts/fixtures/added-em-dash/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "em-dash",
+ "expect": "fail",
+ "about": "A pull request adds a prose line with an em dash."
+}
diff --git a/.github/scripts/fixtures/added-em-dash/tree/docs/hooks.md b/.github/scripts/fixtures/added-em-dash/tree/docs/hooks.md
new file mode 100644
index 0000000..459f581
--- /dev/null
+++ b/.github/scripts/fixtures/added-em-dash/tree/docs/hooks.md
@@ -0,0 +1,5 @@
+# Hooks
+
+A hook runs a command at a lifecycle event.
+
+Hooks run with your permissions — review them first.
diff --git a/.github/scripts/fixtures/asset-name-not-kebab-case/fixture.json b/.github/scripts/fixtures/asset-name-not-kebab-case/fixture.json
new file mode 100644
index 0000000..32d3b0f
--- /dev/null
+++ b/.github/scripts/fixtures/asset-name-not-kebab-case/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "images",
+ "expect": "fail",
+ "about": "An image under assets/ whose file name is not kebab-case."
+}
diff --git a/.github/scripts/fixtures/asset-name-not-kebab-case/tree/README.md b/.github/scripts/fixtures/asset-name-not-kebab-case/tree/README.md
new file mode 100644
index 0000000..9ac5d0e
--- /dev/null
+++ b/.github/scripts/fixtures/asset-name-not-kebab-case/tree/README.md
@@ -0,0 +1,3 @@
+# Fixture
+
+![The context grid fills as the session grows](assets/lessons/b-4/Context_Grid.png)
diff --git a/.github/scripts/fixtures/asset-name-not-kebab-case/tree/assets/lessons/b-4/Context_Grid.png b/.github/scripts/fixtures/asset-name-not-kebab-case/tree/assets/lessons/b-4/Context_Grid.png
new file mode 100644
index 0000000..0dd1608
--- /dev/null
+++ b/.github/scripts/fixtures/asset-name-not-kebab-case/tree/assets/lessons/b-4/Context_Grid.png
@@ -0,0 +1,2 @@
+�PNG
+
diff --git a/.github/scripts/fixtures/asset-over-size-budget/fixture.json b/.github/scripts/fixtures/asset-over-size-budget/fixture.json
new file mode 100644
index 0000000..89a6afc
--- /dev/null
+++ b/.github/scripts/fixtures/asset-over-size-budget/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "images",
+ "expect": "fail",
+ "about": "An SVG under assets/ larger than the 50 KB budget. The file is generated, to keep the fixture small."
+}
diff --git a/.github/scripts/fixtures/asset-over-size-budget/generate.mjs b/.github/scripts/fixtures/asset-over-size-budget/generate.mjs
new file mode 100644
index 0000000..2163e2a
--- /dev/null
+++ b/.github/scripts/fixtures/asset-over-size-budget/generate.mjs
@@ -0,0 +1,9 @@
+import { mkdirSync, writeFileSync } from 'node:fs';
+import { join } from 'node:path';
+
+export default function generate(root) {
+ const dir = join(root, 'assets', 'lessons', 'b-4');
+ mkdirSync(dir, { recursive: true });
+ const rects = '<rect width="1" height="1"/>'.repeat(2200);
+ writeFileSync(join(dir, 'context-grid.svg'), `<svg xmlns="http://www.w3.org/2000/svg">${rects}</svg>`);
+}
diff --git a/.github/scripts/fixtures/asset-over-size-budget/tree/README.md b/.github/scripts/fixtures/asset-over-size-budget/tree/README.md
new file mode 100644
index 0000000..c6eea7e
--- /dev/null
+++ b/.github/scripts/fixtures/asset-over-size-budget/tree/README.md
@@ -0,0 +1,3 @@
+# Fixture
+
+![The context grid fills as the session grows](assets/lessons/b-4/context-grid.svg)
diff --git a/.github/scripts/fixtures/em-dash-allowed-cases/base/docs/hooks.md b/.github/scripts/fixtures/em-dash-allowed-cases/base/docs/hooks.md
new file mode 100644
index 0000000..9b70fed
--- /dev/null
+++ b/.github/scripts/fixtures/em-dash-allowed-cases/base/docs/hooks.md
@@ -0,0 +1,3 @@
+# Hooks
+
+An older line — left as it was.
diff --git a/.github/scripts/fixtures/em-dash-allowed-cases/fixture.json b/.github/scripts/fixtures/em-dash-allowed-cases/fixture.json
new file mode 100644
index 0000000..7753694
--- /dev/null
+++ b/.github/scripts/fixtures/em-dash-allowed-cases/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "em-dash",
+ "expect": "pass",
+ "about": "Em dashes pass on unchanged lines, inside backticks or code blocks, inside double quotes, and on a line with the allow marker."
+}
diff --git a/.github/scripts/fixtures/em-dash-allowed-cases/tree/docs/hooks.md b/.github/scripts/fixtures/em-dash-allowed-cases/tree/docs/hooks.md
new file mode 100644
index 0000000..a334b98
--- /dev/null
+++ b/.github/scripts/fixtures/em-dash-allowed-cases/tree/docs/hooks.md
@@ -0,0 +1,13 @@
+# Hooks
+
+An older line — left as it was.
+
+The status bar shows `Auto — on`.
+
+The docs call it "a hook — or a guard".
+
+The product name is Foo—Bar. <!-- allow-em-dash -->
+
+```text
+exit 2 — blocked
+```
diff --git a/.github/scripts/fixtures/image-missing-alt-text/fixture.json b/.github/scripts/fixtures/image-missing-alt-text/fixture.json
new file mode 100644
index 0000000..74e26f7
--- /dev/null
+++ b/.github/scripts/fixtures/image-missing-alt-text/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "images",
+ "expect": "fail",
+ "about": "A Markdown image with empty alt text."
+}
diff --git a/.github/scripts/fixtures/image-missing-alt-text/tree/README.md b/.github/scripts/fixtures/image-missing-alt-text/tree/README.md
new file mode 100644
index 0000000..341e342
--- /dev/null
+++ b/.github/scripts/fixtures/image-missing-alt-text/tree/README.md
@@ -0,0 +1,3 @@
+# Fixture
+
+![](assets/lessons/b-4/context-grid.png)
diff --git a/.github/scripts/fixtures/image-missing-alt-text/tree/assets/lessons/b-4/context-grid.png b/.github/scripts/fixtures/image-missing-alt-text/tree/assets/lessons/b-4/context-grid.png
new file mode 100644
index 0000000..0dd1608
--- /dev/null
+++ b/.github/scripts/fixtures/image-missing-alt-text/tree/assets/lessons/b-4/context-grid.png
@@ -0,0 +1,2 @@
+�PNG
+
diff --git a/.github/scripts/fixtures/lesson-check-out-of-order/fixture.json b/.github/scripts/fixtures/lesson-check-out-of-order/fixture.json
new file mode 100644
index 0000000..6e56394
--- /dev/null
+++ b/.github/scripts/fixtures/lesson-check-out-of-order/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "lesson-lint",
+ "expect": "fail",
+ "about": "A lesson whose Check slot puts the npm run check line before the task list."
+}
diff --git a/.github/scripts/fixtures/lesson-check-out-of-order/tree/docs/beginner/02-permission-modes-and-plan-mode.md b/.github/scripts/fixtures/lesson-check-out-of-order/tree/docs/beginner/02-permission-modes-and-plan-mode.md
new file mode 100644
index 0000000..ba28e1e
--- /dev/null
+++ b/.github/scripts/fixtures/lesson-check-out-of-order/tree/docs/beginner/02-permission-modes-and-plan-mode.md
@@ -0,0 +1,97 @@
+# Choose who approves what: permission modes and plan mode
+
+<sub>**Beginner** · Lesson 2 of 5 · about 15 minutes · Needs: [Install, sign in and look around](01-install-and-look-around.md) · Verified against Claude Code v2.1.285 (stable) on 2026-10-20 (sample)</sub>
+
+## Goal
+
+By the end of this lesson you can pick a permission mode for a task, switch modes during a session, and use plan mode to approve a plan before Claude changes any file.
+
+## You need
+
+- Your copy of the practice template, cloned locally, with no uncommitted changes. To practice in one of your own git repositories instead, keep the template copy as well: the check runs from it.
+- Node.js LTS installed, or the template opened in Codespaces.
+- One small change you want made, such as adding input validation to a function.
+
+## The idea
+
+A [permission mode](https://code.claude.com/docs/en/permission-modes) decides which actions Claude can take without asking you first. You switch modes with `Shift+Tab`, and the status bar under the prompt always shows the one in force.
+
+Four modes matter now:
+
+| Status bar shows | Mode | Claude does this without asking |
+|---|---|---|
+| `⏸ manual mode on` | Manual | Reads files |
+| `⏵⏵ accept edits on` | Accept edits | Reads, edits files, runs common file commands |
+| `⏸ plan mode on` | Plan | Reads and explores, then writes a plan. It cannot edit your files until you approve the plan |
+| `⏵⏵ auto mode on` | Auto | Everything, with background safety checks |
+
+Plan mode is the habit to build first. You see the whole change before any file moves.
+
+## Worked example
+
+1. Look at the status bar. Your session probably starts in auto mode.
+2. Press `Shift+Tab` until the status bar reads `⏸ plan mode on`. From auto, the first press gives Manual, then Accept edits, then Plan.
+3. Ask for the change:
+
+ ```text
+ Add a check to parseConfig in src/config.js that rejects an empty file with a clear error message.
+ ```
+
+4. Claude reads files and may run commands to explore, but does not edit your files. Then it shows a plan and asks how to proceed. You see three choices: **Yes, and use auto mode**; **Yes, manually approve edits**; **No, keep planning**. While Claude plans, watch the status bar: it keeps reading `⏸ plan mode on`.
+5. If the plan touches more than you asked for, for example a new test file, choose **No, keep planning** and say what to change:
+
+ ```text
+ Keep the change to src/config.js and its existing test file. Don't add new test files.
+ ```
+
+6. When the revised plan looks right, leave it on screen. Open another terminal in the same folder. In your own repository, first run `echo '.practice/' >> .git/info/exclude` once, so git [ignores](https://git-scm.com/docs/gitignore) the snapshot folder there without a commit. Then save what git sees before you approve:
+
+ ```bash
+ mkdir -p .practice
+ git status --porcelain > .practice/b-2-before.txt
+ ```
+
+ Then write the files the plan says it will change into `.practice/b-2-plan.txt`, one path per line, for example:
+
+ ```bash
+ printf '%s\n' src/config.js test/config.test.js > .practice/b-2-plan.txt
+ ```
+
+ The template ignores `.practice/`, so these files do not show up in `git status`.
+7. Back in Claude Code, choose **Yes, manually approve edits**. The session leaves plan mode, and Claude asks before each edit. Approve them one at a time.
+8. Set the example's change aside so Your turn starts clean: `git stash push --include-untracked -m b-2-example`. Your `.practice/` folder stays, because git ignores it.
+
+## Your turn
+
+Repeat the example in your practice copy (or your own repository) with your own small change:
+
+1. Switch to plan mode with `Shift+Tab`.
+2. Ask for the change.
+3. Send the plan back once with **No, keep planning** and one correction.
+4. While the final plan is shown, run the commands from Worked example step 6 in another terminal, with your plan's file list (in your own repository, run the one-time exclude line first).
+5. Approve it with **Yes, manually approve edits** and approve each edit.
+
+Stop before committing. The next lesson takes the change to a commit.
+
+## Check
+
+You are done when all of these are true:
+
+Run `npm run check -- b-2` before you commit. In your own repository, run `npm run check -- b-2 --dir <your repo>` from your template copy instead.
+
+- [ ] Before you approved, you saved `git status --porcelain > .practice/b-2-before.txt` in another terminal, and it lists no files.
+- [ ] After approving, every path that `git status --porcelain` lists (apart from `.practice/`) appears in `.practice/b-2-plan.txt`.
+- [ ] Self-check (not tested): say, in one sentence, when you would pick Manual instead of Auto.
+
+If `.practice/b-2-before.txt` lists files, check that the status bar read `⏸ plan mode on` when you sent the prompt, then look in the transcript for a command Claude ran that wrote a file. If a changed path is missing from `.practice/b-2-plan.txt`, compare the plan you approved with what Claude changed.
+
+## Go further
+
+- Type `/plan <your task>` to enter plan mode and start the task in one step. When you approve, the option you pick sets the mode you continue in.
+- Official: [Analyze before you edit with plan mode](https://code.claude.com/docs/en/permission-modes#analyze-before-you-edit-with-plan-mode).
+
+---
+
+<sub>Sources: [Choose a permission mode](https://code.claude.com/docs/en/permission-modes)</sub>
+
+<sub>← [Install, sign in and look around](01-install-and-look-around.md) · [Beginner index](README.md) · [Your first change, from request to commit](03-first-change.md) → · Topic: [Permissions and safety](../topics/permissions-and-safety.md) · [Stuck on this lesson?](https://github.com/wesammustafa/Claude-Code-Everything-You-Need-to-Know/issues/new?template=lesson-feedback.yml&lesson=b-2)</sub>
diff --git a/.github/scripts/fixtures/lesson-missing-fixed-slot/fixture.json b/.github/scripts/fixtures/lesson-missing-fixed-slot/fixture.json
new file mode 100644
index 0000000..713aea8
--- /dev/null
+++ b/.github/scripts/fixtures/lesson-missing-fixed-slot/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "lesson-lint",
+ "expect": "fail",
+ "about": "A lesson without its The idea slot."
+}
diff --git a/.github/scripts/fixtures/lesson-missing-fixed-slot/tree/docs/beginner/02-permission-modes-and-plan-mode.md b/.github/scripts/fixtures/lesson-missing-fixed-slot/tree/docs/beginner/02-permission-modes-and-plan-mode.md
new file mode 100644
index 0000000..a464a47
--- /dev/null
+++ b/.github/scripts/fixtures/lesson-missing-fixed-slot/tree/docs/beginner/02-permission-modes-and-plan-mode.md
@@ -0,0 +1,82 @@
+# Choose who approves what: permission modes and plan mode
+
+<sub>**Beginner** · Lesson 2 of 5 · about 15 minutes · Needs: [Install, sign in and look around](01-install-and-look-around.md) · Verified against Claude Code v2.1.285 (stable) on 2026-10-20 (sample)</sub>
+
+## Goal
+
+By the end of this lesson you can pick a permission mode for a task, switch modes during a session, and use plan mode to approve a plan before Claude changes any file.
+
+## You need
+
+- Your copy of the practice template, cloned locally, with no uncommitted changes. To practice in one of your own git repositories instead, keep the template copy as well: the check runs from it.
+- Node.js LTS installed, or the template opened in Codespaces.
+- One small change you want made, such as adding input validation to a function.
+
+## Worked example
+
+1. Look at the status bar. Your session probably starts in auto mode.
+2. Press `Shift+Tab` until the status bar reads `⏸ plan mode on`. From auto, the first press gives Manual, then Accept edits, then Plan.
+3. Ask for the change:
+
+ ```text
+ Add a check to parseConfig in src/config.js that rejects an empty file with a clear error message.
+ ```
+
+4. Claude reads files and may run commands to explore, but does not edit your files. Then it shows a plan and asks how to proceed. You see three choices: **Yes, and use auto mode**; **Yes, manually approve edits**; **No, keep planning**. While Claude plans, watch the status bar: it keeps reading `⏸ plan mode on`.
+5. If the plan touches more than you asked for, for example a new test file, choose **No, keep planning** and say what to change:
+
+ ```text
+ Keep the change to src/config.js and its existing test file. Don't add new test files.
+ ```
+
+6. When the revised plan looks right, leave it on screen. Open another terminal in the same folder. In your own repository, first run `echo '.practice/' >> .git/info/exclude` once, so git [ignores](https://git-scm.com/docs/gitignore) the snapshot folder there without a commit. Then save what git sees before you approve:
+
+ ```bash
+ mkdir -p .practice
+ git status --porcelain > .practice/b-2-before.txt
+ ```
+
+ Then write the files the plan says it will change into `.practice/b-2-plan.txt`, one path per line, for example:
+
+ ```bash
+ printf '%s\n' src/config.js test/config.test.js > .practice/b-2-plan.txt
+ ```
+
+ The template ignores `.practice/`, so these files do not show up in `git status`.
+7. Back in Claude Code, choose **Yes, manually approve edits**. The session leaves plan mode, and Claude asks before each edit. Approve them one at a time.
+8. Set the example's change aside so Your turn starts clean: `git stash push --include-untracked -m b-2-example`. Your `.practice/` folder stays, because git ignores it.
+
+## Your turn
+
+Repeat the example in your practice copy (or your own repository) with your own small change:
+
+1. Switch to plan mode with `Shift+Tab`.
+2. Ask for the change.
+3. Send the plan back once with **No, keep planning** and one correction.
+4. While the final plan is shown, run the commands from Worked example step 6 in another terminal, with your plan's file list (in your own repository, run the one-time exclude line first).
+5. Approve it with **Yes, manually approve edits** and approve each edit.
+
+Stop before committing. The next lesson takes the change to a commit.
+
+## Check
+
+You are done when all of these are true:
+
+- [ ] Before you approved, you saved `git status --porcelain > .practice/b-2-before.txt` in another terminal, and it lists no files.
+- [ ] After approving, every path that `git status --porcelain` lists (apart from `.practice/`) appears in `.practice/b-2-plan.txt`.
+- [ ] Self-check (not tested): say, in one sentence, when you would pick Manual instead of Auto.
+
+Run `npm run check -- b-2` before you commit. In your own repository, run `npm run check -- b-2 --dir <your repo>` from your template copy instead.
+
+If `.practice/b-2-before.txt` lists files, check that the status bar read `⏸ plan mode on` when you sent the prompt, then look in the transcript for a command Claude ran that wrote a file. If a changed path is missing from `.practice/b-2-plan.txt`, compare the plan you approved with what Claude changed.
+
+## Go further
+
+- Type `/plan <your task>` to enter plan mode and start the task in one step. When you approve, the option you pick sets the mode you continue in.
+- Official: [Analyze before you edit with plan mode](https://code.claude.com/docs/en/permission-modes#analyze-before-you-edit-with-plan-mode).
+
+---
+
+<sub>Sources: [Choose a permission mode](https://code.claude.com/docs/en/permission-modes)</sub>
+
+<sub>← [Install, sign in and look around](01-install-and-look-around.md) · [Beginner index](README.md) · [Your first change, from request to commit](03-first-change.md) → · Topic: [Permissions and safety](../topics/permissions-and-safety.md) · [Stuck on this lesson?](https://github.com/wesammustafa/Claude-Code-Everything-You-Need-to-Know/issues/new?template=lesson-feedback.yml&lesson=b-2)</sub>
diff --git a/.github/scripts/fixtures/lesson-missing-sources-footer/fixture.json b/.github/scripts/fixtures/lesson-missing-sources-footer/fixture.json
new file mode 100644
index 0000000..3d29905
--- /dev/null
+++ b/.github/scripts/fixtures/lesson-missing-sources-footer/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "lesson-lint",
+ "expect": "fail",
+ "about": "A lesson whose footer has navigation but no Sources line."
+}
diff --git a/.github/scripts/fixtures/lesson-missing-sources-footer/tree/docs/beginner/02-permission-modes-and-plan-mode.md b/.github/scripts/fixtures/lesson-missing-sources-footer/tree/docs/beginner/02-permission-modes-and-plan-mode.md
new file mode 100644
index 0000000..635fd4c
--- /dev/null
+++ b/.github/scripts/fixtures/lesson-missing-sources-footer/tree/docs/beginner/02-permission-modes-and-plan-mode.md
@@ -0,0 +1,95 @@
+# Choose who approves what: permission modes and plan mode
+
+<sub>**Beginner** · Lesson 2 of 5 · about 15 minutes · Needs: [Install, sign in and look around](01-install-and-look-around.md) · Verified against Claude Code v2.1.285 (stable) on 2026-10-20 (sample)</sub>
+
+## Goal
+
+By the end of this lesson you can pick a permission mode for a task, switch modes during a session, and use plan mode to approve a plan before Claude changes any file.
+
+## You need
+
+- Your copy of the practice template, cloned locally, with no uncommitted changes. To practice in one of your own git repositories instead, keep the template copy as well: the check runs from it.
+- Node.js LTS installed, or the template opened in Codespaces.
+- One small change you want made, such as adding input validation to a function.
+
+## The idea
+
+A [permission mode](https://code.claude.com/docs/en/permission-modes) decides which actions Claude can take without asking you first. You switch modes with `Shift+Tab`, and the status bar under the prompt always shows the one in force.
+
+Four modes matter now:
+
+| Status bar shows | Mode | Claude does this without asking |
+|---|---|---|
+| `⏸ manual mode on` | Manual | Reads files |
+| `⏵⏵ accept edits on` | Accept edits | Reads, edits files, runs common file commands |
+| `⏸ plan mode on` | Plan | Reads and explores, then writes a plan. It cannot edit your files until you approve the plan |
+| `⏵⏵ auto mode on` | Auto | Everything, with background safety checks |
+
+Plan mode is the habit to build first. You see the whole change before any file moves.
+
+## Worked example
+
+1. Look at the status bar. Your session probably starts in auto mode.
+2. Press `Shift+Tab` until the status bar reads `⏸ plan mode on`. From auto, the first press gives Manual, then Accept edits, then Plan.
+3. Ask for the change:
+
+ ```text
+ Add a check to parseConfig in src/config.js that rejects an empty file with a clear error message.
+ ```
+
+4. Claude reads files and may run commands to explore, but does not edit your files. Then it shows a plan and asks how to proceed. You see three choices: **Yes, and use auto mode**; **Yes, manually approve edits**; **No, keep planning**. While Claude plans, watch the status bar: it keeps reading `⏸ plan mode on`.
+5. If the plan touches more than you asked for, for example a new test file, choose **No, keep planning** and say what to change:
+
+ ```text
+ Keep the change to src/config.js and its existing test file. Don't add new test files.
+ ```
+
+6. When the revised plan looks right, leave it on screen. Open another terminal in the same folder. In your own repository, first run `echo '.practice/' >> .git/info/exclude` once, so git [ignores](https://git-scm.com/docs/gitignore) the snapshot folder there without a commit. Then save what git sees before you approve:
+
+ ```bash
+ mkdir -p .practice
+ git status --porcelain > .practice/b-2-before.txt
+ ```
+
+ Then write the files the plan says it will change into `.practice/b-2-plan.txt`, one path per line, for example:
+
+ ```bash
+ printf '%s\n' src/config.js test/config.test.js > .practice/b-2-plan.txt
+ ```
+
+ The template ignores `.practice/`, so these files do not show up in `git status`.
+7. Back in Claude Code, choose **Yes, manually approve edits**. The session leaves plan mode, and Claude asks before each edit. Approve them one at a time.
+8. Set the example's change aside so Your turn starts clean: `git stash push --include-untracked -m b-2-example`. Your `.practice/` folder stays, because git ignores it.
+
+## Your turn
+
+Repeat the example in your practice copy (or your own repository) with your own small change:
+
+1. Switch to plan mode with `Shift+Tab`.
+2. Ask for the change.
+3. Send the plan back once with **No, keep planning** and one correction.
+4. While the final plan is shown, run the commands from Worked example step 6 in another terminal, with your plan's file list (in your own repository, run the one-time exclude line first).
+5. Approve it with **Yes, manually approve edits** and approve each edit.
+
+Stop before committing. The next lesson takes the change to a commit.
+
+## Check
+
+You are done when all of these are true:
+
+- [ ] Before you approved, you saved `git status --porcelain > .practice/b-2-before.txt` in another terminal, and it lists no files.
+- [ ] After approving, every path that `git status --porcelain` lists (apart from `.practice/`) appears in `.practice/b-2-plan.txt`.
+- [ ] Self-check (not tested): say, in one sentence, when you would pick Manual instead of Auto.
+
+Run `npm run check -- b-2` before you commit. In your own repository, run `npm run check -- b-2 --dir <your repo>` from your template copy instead.
+
+If `.practice/b-2-before.txt` lists files, check that the status bar read `⏸ plan mode on` when you sent the prompt, then look in the transcript for a command Claude ran that wrote a file. If a changed path is missing from `.practice/b-2-plan.txt`, compare the plan you approved with what Claude changed.
+
+## Go further
+
+- Type `/plan <your task>` to enter plan mode and start the task in one step. When you approve, the option you pick sets the mode you continue in.
+- Official: [Analyze before you edit with plan mode](https://code.claude.com/docs/en/permission-modes#analyze-before-you-edit-with-plan-mode).
+
+---
+
+<sub>← [Install, sign in and look around](01-install-and-look-around.md) · [Beginner index](README.md) · [Your first change, from request to commit](03-first-change.md) → · Topic: [Permissions and safety](../topics/permissions-and-safety.md) · [Stuck on this lesson?](https://github.com/wesammustafa/Claude-Code-Everything-You-Need-to-Know/issues/new?template=lesson-feedback.yml&lesson=b-2)</sub>
diff --git a/.github/scripts/fixtures/lesson-watch-out-too-long/fixture.json b/.github/scripts/fixtures/lesson-watch-out-too-long/fixture.json
new file mode 100644
index 0000000..209a83c
--- /dev/null
+++ b/.github/scripts/fixtures/lesson-watch-out-too-long/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "lesson-lint",
+ "expect": "fail",
+ "about": "A lesson whose Watch out slot has four items; the limit is three."
+}
diff --git a/.github/scripts/fixtures/lesson-watch-out-too-long/tree/docs/intermediate/05-hooks.md b/.github/scripts/fixtures/lesson-watch-out-too-long/tree/docs/intermediate/05-hooks.md
new file mode 100644
index 0000000..491b575
--- /dev/null
+++ b/.github/scripts/fixtures/lesson-watch-out-too-long/tree/docs/intermediate/05-hooks.md
@@ -0,0 +1,147 @@
+# Enforce a rule with a hook
+
+<sub>**Intermediate** · Lesson 5 of 8 · about 20 minutes · Needs: [Permissions, settings scopes and the sandbox](#) · Verified against Claude Code v2.1.X (stable) on YYYY-MM-DD</sub>
+
+## Goal
+
+By the end of this lesson you can add a hook that stops Claude from editing files you protect, and prove it fires.
+
+## You need
+
+- Your copy of the practice template, which ships a `package-lock.json` for this demo, or one of your own repositories that has one. Keep the template copy either way: the check runs from it, with Node.js LTS.
+- `jq` installed.
+- macOS, Linux or WSL2.
+
+> [!NOTE]
+> On native Windows, hook commands run in Git Bash, or in PowerShell when Git Bash is missing. Use WSL2 for this lesson.
+
+## The idea
+
+A permission rule asks "may Claude do this?". A [hook](https://code.claude.com/docs/en/hooks-guide) is your own command that Claude Code runs at a fixed point, every time, whatever Claude decides. A `PreToolUse` hook runs before a tool call. If your command exits with code 2, the call is blocked, and what you printed to stderr goes back to Claude as the reason.
+
+```mermaid
+flowchart LR
+ A[Claude calls Edit or Write] --> B[PreToolUse hook runs your script]
+ B -->|exit 0| C[Normal permission check, then the edit]
+ B -->|exit 2| D[Edit blocked; stderr message goes to Claude]
+```
+
+`PreToolUse` hooks run before the permission-mode check, so a block holds in every mode.
+
+## Worked example
+
+This is the official protected-files hook, unchanged.
+
+1. Save it as `.claude/hooks/protect-files.sh`:
+
+ ```bash
+ #!/bin/bash
+ INPUT=$(cat)
+ FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')
+ FILE_PATH="${FILE_PATH//\\//}"
+
+ PROTECTED_PATTERNS=(".env" "package-lock.json" ".git/")
+
+ for pattern in "${PROTECTED_PATTERNS[@]}"; do
+ if [[ "$FILE_PATH" == *"$pattern"* ]]; then
+ echo "Blocked: $FILE_PATH matches protected pattern '$pattern'" >&2
+ exit 2
+ fi
+ done
+ exit 0
+ ```
+
+2. Make it executable: `chmod +x .claude/hooks/protect-files.sh`.
+3. Register it in `.claude/settings.json`:
+
+ ```json
+ {
+ "hooks": {
+ "PreToolUse": [
+ {
+ "matcher": "Edit|Write",
+ "hooks": [
+ { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/protect-files.sh" }
+ ]
+ }
+ ]
+ },
+ "permissions": {
+ "deny": ["Read(.env)"]
+ }
+ }
+ ```
+
+4. From the repository root, test the script without Claude by piping in the JSON a tool call would send:
+
+ ```bash
+ echo "{\"tool_input\":{\"file_path\":\"$PWD/.env\"}}" | .claude/hooks/protect-files.sh; echo "exit $?"
+ ```
+
+ It prints the `Blocked:` line and `exit 2`.
+5. In a session, run `/hooks`. The hook is listed under `PreToolUse`.
+6. Ask Claude to add a blank line at the end of `package-lock.json`. The edit is blocked, and Claude reports the `Blocked:` reason.
+
+ The `Read(.env)` deny rule keeps Claude's file tools away from any real `.env`, so the hook is never your only protection for secrets ([permissions: Read and Edit](https://code.claude.com/docs/en/permissions#read-and-edit)).
+
+## Your turn
+
+The example has a bug. `*".env"*` also matches `.env.example`, which teams commit on purpose, and any path that merely contains `.env`, such as `src/config.envelope.ts`. It also misses `secrets/`. Edit the script so that:
+
+1. A file named exactly `.env`, or `.env.` followed by anything except `example`, is blocked in any folder.
+2. Anything inside a `secrets/` folder is blocked.
+3. Everything else is allowed.
+
+Start from this skeleton:
+
+```bash
+NAME=$(basename "$FILE_PATH")
+# TODO: block .env and .env.* except .env.example
+# TODO: block any path containing /secrets/
+exit 0
+```
+
+Then, in a session, ask Claude to edit `.env.example`, and then to create `secrets/test.key`.
+
+## Check
+
+You are done when all of these are true:
+
+- [ ] Every input in the table below gives its expected exit code when piped to your script.
+- [ ] Claude's edit to `.env.example` succeeded: `git status --porcelain` lists the file.
+- [ ] Self-check (not tested): Claude's attempt to create `secrets/test.key` was blocked with your `Blocked:` message, and `/hooks` lists your hook.
+
+Run the loop from your repository's root. Edit and Write always send an absolute `file_path` ([hooks reference](https://code.claude.com/docs/en/hooks#pretooluse-input)), so every row starts with `$PWD`. The exit code must match.
+
+| Input `file_path` | Expected exit |
+|---|---|
+| `$PWD/.env` | 2 |
+| `$PWD/config/.env.local` | 2 |
+| `$PWD/.env.example` | 0 |
+| `$PWD/secrets/api.key` | 2 |
+| `$PWD/src/config.envelope.ts` | 0 |
+
+```bash
+for p in "$PWD/.env" "$PWD/config/.env.local" "$PWD/.env.example" "$PWD/secrets/api.key" "$PWD/src/config.envelope.ts"; do
+ printf '%s ' "$p"; echo "{\"tool_input\":{\"file_path\":\"$p\"}}" | .claude/hooks/protect-files.sh 2>/dev/null; echo $?
+done
+```
+
+Run `npm run check -- i-5 --dir <your repo>` from your template copy (or `npm run check -- i-5` inside the template).
+
+## Watch out
+
+- This hook watches the Edit and Write tools only. A shell command such as `echo X >> .env` goes through Bash, and this script cannot see its target: Bash input has `command`, not `file_path`. Add an `Edit(.env)` deny rule as well: it also covers shell redirects like `>> .env` ([permissions: Redirections](https://code.claude.com/docs/en/permissions#redirections)). The [hooks guide](https://code.claude.com/docs/en/hooks-guide#filter-hooks-with-matchers) shows a `Bash|PowerShell` pattern for full coverage.
+- Hooks in a repository's `.claude/settings.json` run in an interactive session once you trust the folder, and in `claude -p` or SDK runs without asking. Read a repository's hooks before you trust it or script `claude -p` in it.
+- A third caveat.
+- A fourth caveat that belongs in another lesson.
+
+## Go further
+
+- Official: [Automate actions with hooks](https://code.claude.com/docs/en/hooks-guide) and the [hooks reference](https://code.claude.com/docs/en/hooks).
+
+---
+
+<sub>Sources: [Automate actions with hooks](https://code.claude.com/docs/en/hooks-guide) · [Hooks reference: workspace trust](https://code.claude.com/docs/en/hooks#workspace-trust) · [Configure permissions](https://code.claude.com/docs/en/permissions)</sub>
+
+<sub>← [Permissions, settings scopes and the sandbox](#) · [Intermediate index](#) · [Delegate to a custom subagent](#) → · Topic: [Hooks](../topics/hooks.md) · [Stuck on this lesson?](https://github.com/wesammustafa/Claude-Code-Everything-You-Need-to-Know/issues/new?template=lesson-feedback.yml&lesson=i-5)</sub>
diff --git a/.github/scripts/fixtures/mermaid-without-accessibility/fixture.json b/.github/scripts/fixtures/mermaid-without-accessibility/fixture.json
new file mode 100644
index 0000000..bbaedc6
--- /dev/null
+++ b/.github/scripts/fixtures/mermaid-without-accessibility/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "images",
+ "expect": "fail",
+ "about": "A Mermaid diagram with no accTitle or accDescr."
+}
diff --git a/.github/scripts/fixtures/mermaid-without-accessibility/tree/README.md b/.github/scripts/fixtures/mermaid-without-accessibility/tree/README.md
new file mode 100644
index 0000000..c6297b3
--- /dev/null
+++ b/.github/scripts/fixtures/mermaid-without-accessibility/tree/README.md
@@ -0,0 +1,10 @@
+# Fixture
+
+The hook blocks the edit when it exits 2.
+
+```mermaid
+flowchart LR
+ A[Edit] --> B{Hook}
+ B -->|exit 0| C[Allowed]
+ B -->|exit 2| D[Blocked]
+```
diff --git a/.github/scripts/fixtures/orphan-asset/fixture.json b/.github/scripts/fixtures/orphan-asset/fixture.json
new file mode 100644
index 0000000..cc386b9
--- /dev/null
+++ b/.github/scripts/fixtures/orphan-asset/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "images",
+ "expect": "fail",
+ "about": "A file under assets/lessons/ that no page references."
+}
diff --git a/.github/scripts/fixtures/orphan-asset/tree/README.md b/.github/scripts/fixtures/orphan-asset/tree/README.md
new file mode 100644
index 0000000..77e88f0
--- /dev/null
+++ b/.github/scripts/fixtures/orphan-asset/tree/README.md
@@ -0,0 +1,3 @@
+# Fixture
+
+No images here.
diff --git a/.github/scripts/fixtures/orphan-asset/tree/assets/lessons/b-4/context-grid.png b/.github/scripts/fixtures/orphan-asset/tree/assets/lessons/b-4/context-grid.png
new file mode 100644
index 0000000..0dd1608
--- /dev/null
+++ b/.github/scripts/fixtures/orphan-asset/tree/assets/lessons/b-4/context-grid.png
@@ -0,0 +1,2 @@
+�PNG
+
diff --git a/.github/scripts/fixtures/sample-lessons-pass-lesson-lint/fixture.json b/.github/scripts/fixtures/sample-lessons-pass-lesson-lint/fixture.json
new file mode 100644
index 0000000..c159aa8
--- /dev/null
+++ b/.github/scripts/fixtures/sample-lessons-pass-lesson-lint/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "lesson-lint",
+ "expect": "pass",
+ "about": "The three sample lessons from the rework's design work (Beginner 2, Intermediate 5, Advanced 3), placed at their lesson paths with full navigation."
+}
diff --git a/.github/scripts/fixtures/sample-lessons-pass-lesson-lint/tree/docs/advanced/03-dynamic-workflows.md b/.github/scripts/fixtures/sample-lessons-pass-lesson-lint/tree/docs/advanced/03-dynamic-workflows.md
new file mode 100644
index 0000000..973987a
--- /dev/null
+++ b/.github/scripts/fixtures/sample-lessons-pass-lesson-lint/tree/docs/advanced/03-dynamic-workflows.md
@@ -0,0 +1,69 @@
+# Run and save a dynamic workflow
+
+<sub>**Advanced** · Lesson 3 of 7 · about 20 minutes, plus run time · Needs: [Choose an orchestration pattern](#) · Verified against Claude Code v2.1.X (stable) on YYYY-MM-DD</sub>
+
+## Goal
+
+By the end of this lesson you can have Claude write a [dynamic workflow](https://code.claude.com/docs/en/workflows) for a fan-out task, keep its cost bounded, and save it as a command you can rerun with input.
+
+## You need
+
+- A paid plan or API access. **On Pro, workflows are off until you turn on the Dynamic workflows row in `/config`.**
+- Your own repository with at least 20 source files, or your template copy. At the end, run `npm run check -- a-3 --dir <repo>` from your template copy, with `<repo>` the repository you used. In your own repository, first run `echo '.practice/' >> .git/info/exclude` once, so git ignores the folder where you save reports.
+
+## The idea
+
+In the previous lesson you saw that a workflow moves the plan out of Claude's turn-by-turn reasoning and into a script. The runtime runs the script in the background, the script spawns the agents, and only the final answer returns to your conversation. That makes a workflow rerunnable, and it lets the script cross-check its own agents' findings.
+
+## Worked example
+
+1. Run the bundled workflow and approve it when asked: `/deep-research What changed in the Node.js permission model between v20 and v22?`
+2. Run `/workflows`, select the run and press Enter. Each phase shows its agent count, tokens and elapsed time.
+3. Press `Shift+Tab` until the status bar reads `⏸ manual mode on`. In auto mode, Claude Code asks before only your first workflow launch ([Approve the plan before it runs](https://code.claude.com/docs/en/workflows#approve-the-plan-before-it-runs)), so you would not get to read the script.
+4. Ask for a workflow of your own, in plain words:
+
+ ```text
+ use a workflow to audit every route handler under src/routes/ for missing authentication checks, and adversarially verify each finding before reporting it
+ ```
+
+ In your template copy, or any repository without `src/routes/`, name a folder it does have and a check that fits its code.
+
+5. Before it starts, Claude Code shows the planned phases. Choose **View raw script** once to read what will run, then **Yes, run it**.
+6. When it finishes, open `/workflows`, select the run, press `s` and save it to `.claude/workflows/`. New sessions pick it up by name; to run it in this session, run `/reload-skills` first ([Edit a saved script](https://code.claude.com/docs/en/workflows#edit-a-saved-script)). Commit it, and anyone who clones the repository can run it.
+
+## Your turn
+
+**Brief.** Build a workflow that finds every `TODO` and `FIXME` comment in a folder you name, checks whether each one still applies to the current code, and reports the ones that do.
+
+**Acceptance criteria:**
+- It is saved in `.claude/workflows/` and runs by name.
+- It takes the folder as input (`args`), so `Run /<name> on src/payments` works without editing the script.
+- Every reported item has a `file:line`, and items that no longer apply are left out.
+- A first run on a single small folder stays under your size guideline and shows no `Large workflow` warning.
+
+After each edit to the script, run `/reload-skills` before you run it again. Save the reports of two runs on different folders as `.practice/a-3-run1.md` and `.practice/a-3-run2.md`, each with the folder you ran it on as its first line.
+
+## Check
+
+- [ ] Your script is in `.claude/workflows/`, and it parses as a workflow script.
+- [ ] `.practice/a-3-run1.md` and `.practice/a-3-run2.md` name different folders on their first lines, the two reports differ, and every `path:line` in them exists and holds `TODO` or `FIXME`.
+- [ ] Self-check (not tested): you did not edit the script between the two runs, three reported items you spot-checked still apply, and in `/workflows` each run's agent count stayed within your size guideline.
+
+Run `npm run check -- a-3 --dir <your repo>` from your template copy (or `npm run check -- a-3` inside the template).
+
+## Watch out
+
+- One run can use far more tokens than doing the task in conversation, and it counts against your plan's limits. Try it on one small folder first.
+- The `Large workflow` warning, which appears above 25 agents or 1.5 million projected tokens, is advisory. It does not stop the run; stop it yourself from `/workflows`.
+- In auto mode, one Yes approves every later workflow launch.
+
+## Go further
+
+- Elective: [Agent teams](#), for when the workers need to talk to each other.
+- Official: [Pass input to a saved workflow](https://code.claude.com/docs/en/workflows#pass-input-to-a-saved-workflow) and [Set a size guideline](https://code.claude.com/docs/en/workflows#set-a-size-guideline).
+
+---
+
+<sub>Sources: [Orchestrate subagents at scale with dynamic workflows](https://code.claude.com/docs/en/workflows)</sub>
+
+<sub>← [Choose an orchestration pattern](#) · [Advanced index](#) · [Script Claude Code with `claude -p`](#) → · Topic: [Subagents and parallel work](../topics/subagents-and-parallel-work.md) · [Stuck on this lesson?](https://github.com/wesammustafa/Claude-Code-Everything-You-Need-to-Know/issues/new?template=lesson-feedback.yml&lesson=a-3)</sub>
diff --git a/.github/scripts/fixtures/sample-lessons-pass-lesson-lint/tree/docs/beginner/02-permission-modes-and-plan-mode.md b/.github/scripts/fixtures/sample-lessons-pass-lesson-lint/tree/docs/beginner/02-permission-modes-and-plan-mode.md
new file mode 100644
index 0000000..4dac31f
--- /dev/null
+++ b/.github/scripts/fixtures/sample-lessons-pass-lesson-lint/tree/docs/beginner/02-permission-modes-and-plan-mode.md
@@ -0,0 +1,97 @@
+# Choose who approves what: permission modes and plan mode
+
+<sub>**Beginner** · Lesson 2 of 5 · about 15 minutes · Needs: [Install, sign in and look around](01-install-and-look-around.md) · Verified against Claude Code v2.1.285 (stable) on 2026-10-20 (sample)</sub>
+
+## Goal
+
+By the end of this lesson you can pick a permission mode for a task, switch modes during a session, and use plan mode to approve a plan before Claude changes any file.
+
+## You need
+
+- Your copy of the practice template, cloned locally, with no uncommitted changes. To practice in one of your own git repositories instead, keep the template copy as well: the check runs from it.
+- Node.js LTS installed, or the template opened in Codespaces.
+- One small change you want made, such as adding input validation to a function.
+
+## The idea
+
+A [permission mode](https://code.claude.com/docs/en/permission-modes) decides which actions Claude can take without asking you first. You switch modes with `Shift+Tab`, and the status bar under the prompt always shows the one in force.
+
+Four modes matter now:
+
+| Status bar shows | Mode | Claude does this without asking |
+|---|---|---|
+| `⏸ manual mode on` | Manual | Reads files |
+| `⏵⏵ accept edits on` | Accept edits | Reads, edits files, runs common file commands |
+| `⏸ plan mode on` | Plan | Reads and explores, then writes a plan. It cannot edit your files until you approve the plan |
+| `⏵⏵ auto mode on` | Auto | Everything, with background safety checks |
+
+Plan mode is the habit to build first. You see the whole change before any file moves.
+
+## Worked example
+
+1. Look at the status bar. Your session probably starts in auto mode.
+2. Press `Shift+Tab` until the status bar reads `⏸ plan mode on`. From auto, the first press gives Manual, then Accept edits, then Plan.
+3. Ask for the change:
+
+ ```text
+ Add a check to parseConfig in src/config.js that rejects an empty file with a clear error message.
+ ```
+
+4. Claude reads files and may run commands to explore, but does not edit your files. Then it shows a plan and asks how to proceed. You see three choices: **Yes, and use auto mode**; **Yes, manually approve edits**; **No, keep planning**. While Claude plans, watch the status bar: it keeps reading `⏸ plan mode on`.
+5. If the plan touches more than you asked for, for example a new test file, choose **No, keep planning** and say what to change:
+
+ ```text
+ Keep the change to src/config.js and its existing test file. Don't add new test files.
+ ```
+
+6. When the revised plan looks right, leave it on screen. Open another terminal in the same folder. In your own repository, first run `echo '.practice/' >> .git/info/exclude` once, so git [ignores](https://git-scm.com/docs/gitignore) the snapshot folder there without a commit. Then save what git sees before you approve:
+
+ ```bash
+ mkdir -p .practice
+ git status --porcelain > .practice/b-2-before.txt
+ ```
+
+ Then write the files the plan says it will change into `.practice/b-2-plan.txt`, one path per line, for example:
+
+ ```bash
+ printf '%s\n' src/config.js test/config.test.js > .practice/b-2-plan.txt
+ ```
+
+ The template ignores `.practice/`, so these files do not show up in `git status`.
+7. Back in Claude Code, choose **Yes, manually approve edits**. The session leaves plan mode, and Claude asks before each edit. Approve them one at a time.
+8. Set the example's change aside so Your turn starts clean: `git stash push --include-untracked -m b-2-example`. Your `.practice/` folder stays, because git ignores it.
+
+## Your turn
+
+Repeat the example in your practice copy (or your own repository) with your own small change:
+
+1. Switch to plan mode with `Shift+Tab`.
+2. Ask for the change.
+3. Send the plan back once with **No, keep planning** and one correction.
+4. While the final plan is shown, run the commands from Worked example step 6 in another terminal, with your plan's file list (in your own repository, run the one-time exclude line first).
+5. Approve it with **Yes, manually approve edits** and approve each edit.
+
+Stop before committing. The next lesson takes the change to a commit.
+
+## Check
+
+You are done when all of these are true:
+
+- [ ] Before you approved, you saved `git status --porcelain > .practice/b-2-before.txt` in another terminal, and it lists no files.
+- [ ] After approving, every path that `git status --porcelain` lists (apart from `.practice/`) appears in `.practice/b-2-plan.txt`.
+- [ ] Self-check (not tested): say, in one sentence, when you would pick Manual instead of Auto.
+
+Run `npm run check -- b-2` before you commit. In your own repository, run `npm run check -- b-2 --dir <your repo>` from your template copy instead.
+
+If `.practice/b-2-before.txt` lists files, check that the status bar read `⏸ plan mode on` when you sent the prompt, then look in the transcript for a command Claude ran that wrote a file. If a changed path is missing from `.practice/b-2-plan.txt`, compare the plan you approved with what Claude changed.
+
+## Go further
+
+- Type `/plan <your task>` to enter plan mode and start the task in one step. When you approve, the option you pick sets the mode you continue in.
+- Official: [Analyze before you edit with plan mode](https://code.claude.com/docs/en/permission-modes#analyze-before-you-edit-with-plan-mode).
+
+---
+
+<sub>Sources: [Choose a permission mode](https://code.claude.com/docs/en/permission-modes)</sub>
+
+<sub>← [Install, sign in and look around](01-install-and-look-around.md) · [Beginner index](README.md) · [Your first change, from request to commit](03-first-change.md) → · Topic: [Permissions and safety](../topics/permissions-and-safety.md) · [Stuck on this lesson?](https://github.com/wesammustafa/Claude-Code-Everything-You-Need-to-Know/issues/new?template=lesson-feedback.yml&lesson=b-2)</sub>
diff --git a/.github/scripts/fixtures/sample-lessons-pass-lesson-lint/tree/docs/intermediate/05-hooks.md b/.github/scripts/fixtures/sample-lessons-pass-lesson-lint/tree/docs/intermediate/05-hooks.md
new file mode 100644
index 0000000..e7dfc64
--- /dev/null
+++ b/.github/scripts/fixtures/sample-lessons-pass-lesson-lint/tree/docs/intermediate/05-hooks.md
@@ -0,0 +1,145 @@
+# Enforce a rule with a hook
+
+<sub>**Intermediate** · Lesson 5 of 8 · about 20 minutes · Needs: [Permissions, settings scopes and the sandbox](#) · Verified against Claude Code v2.1.X (stable) on YYYY-MM-DD</sub>
+
+## Goal
+
+By the end of this lesson you can add a hook that stops Claude from editing files you protect, and prove it fires.
+
+## You need
+
+- Your copy of the practice template, which ships a `package-lock.json` for this demo, or one of your own repositories that has one. Keep the template copy either way: the check runs from it, with Node.js LTS.
+- `jq` installed.
+- macOS, Linux or WSL2.
+
+> [!NOTE]
+> On native Windows, hook commands run in Git Bash, or in PowerShell when Git Bash is missing. Use WSL2 for this lesson.
+
+## The idea
+
+A permission rule asks "may Claude do this?". A [hook](https://code.claude.com/docs/en/hooks-guide) is your own command that Claude Code runs at a fixed point, every time, whatever Claude decides. A `PreToolUse` hook runs before a tool call. If your command exits with code 2, the call is blocked, and what you printed to stderr goes back to Claude as the reason.
+
+```mermaid
+flowchart LR
+ A[Claude calls Edit or Write] --> B[PreToolUse hook runs your script]
+ B -->|exit 0| C[Normal permission check, then the edit]
+ B -->|exit 2| D[Edit blocked; stderr message goes to Claude]
+```
+
+`PreToolUse` hooks run before the permission-mode check, so a block holds in every mode.
+
+## Worked example
+
+This is the official protected-files hook, unchanged.
+
+1. Save it as `.claude/hooks/protect-files.sh`:
+
+ ```bash
+ #!/bin/bash
+ INPUT=$(cat)
+ FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')
+ FILE_PATH="${FILE_PATH//\\//}"
+
+ PROTECTED_PATTERNS=(".env" "package-lock.json" ".git/")
+
+ for pattern in "${PROTECTED_PATTERNS[@]}"; do
+ if [[ "$FILE_PATH" == *"$pattern"* ]]; then
+ echo "Blocked: $FILE_PATH matches protected pattern '$pattern'" >&2
+ exit 2
+ fi
+ done
+ exit 0
+ ```
+
+2. Make it executable: `chmod +x .claude/hooks/protect-files.sh`.
+3. Register it in `.claude/settings.json`:
+
+ ```json
+ {
+ "hooks": {
+ "PreToolUse": [
+ {
+ "matcher": "Edit|Write",
+ "hooks": [
+ { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/protect-files.sh" }
+ ]
+ }
+ ]
+ },
+ "permissions": {
+ "deny": ["Read(.env)"]
+ }
+ }
+ ```
+
+4. From the repository root, test the script without Claude by piping in the JSON a tool call would send:
+
+ ```bash
+ echo "{\"tool_input\":{\"file_path\":\"$PWD/.env\"}}" | .claude/hooks/protect-files.sh; echo "exit $?"
+ ```
+
+ It prints the `Blocked:` line and `exit 2`.
+5. In a session, run `/hooks`. The hook is listed under `PreToolUse`.
+6. Ask Claude to add a blank line at the end of `package-lock.json`. The edit is blocked, and Claude reports the `Blocked:` reason.
+
+ The `Read(.env)` deny rule keeps Claude's file tools away from any real `.env`, so the hook is never your only protection for secrets ([permissions: Read and Edit](https://code.claude.com/docs/en/permissions#read-and-edit)).
+
+## Your turn
+
+The example has a bug. `*".env"*` also matches `.env.example`, which teams commit on purpose, and any path that merely contains `.env`, such as `src/config.envelope.ts`. It also misses `secrets/`. Edit the script so that:
+
+1. A file named exactly `.env`, or `.env.` followed by anything except `example`, is blocked in any folder.
+2. Anything inside a `secrets/` folder is blocked.
+3. Everything else is allowed.
+
+Start from this skeleton:
+
+```bash
+NAME=$(basename "$FILE_PATH")
+# TODO: block .env and .env.* except .env.example
+# TODO: block any path containing /secrets/
+exit 0
+```
+
+Then, in a session, ask Claude to edit `.env.example`, and then to create `secrets/test.key`.
+
+## Check
+
+You are done when all of these are true:
+
+- [ ] Every input in the table below gives its expected exit code when piped to your script.
+- [ ] Claude's edit to `.env.example` succeeded: `git status --porcelain` lists the file.
+- [ ] Self-check (not tested): Claude's attempt to create `secrets/test.key` was blocked with your `Blocked:` message, and `/hooks` lists your hook.
+
+Run the loop from your repository's root. Edit and Write always send an absolute `file_path` ([hooks reference](https://code.claude.com/docs/en/hooks#pretooluse-input)), so every row starts with `$PWD`. The exit code must match.
+
+| Input `file_path` | Expected exit |
+|---|---|
+| `$PWD/.env` | 2 |
+| `$PWD/config/.env.local` | 2 |
+| `$PWD/.env.example` | 0 |
+| `$PWD/secrets/api.key` | 2 |
+| `$PWD/src/config.envelope.ts` | 0 |
+
+```bash
+for p in "$PWD/.env" "$PWD/config/.env.local" "$PWD/.env.example" "$PWD/secrets/api.key" "$PWD/src/config.envelope.ts"; do
+ printf '%s ' "$p"; echo "{\"tool_input\":{\"file_path\":\"$p\"}}" | .claude/hooks/protect-files.sh 2>/dev/null; echo $?
+done
+```
+
+Run `npm run check -- i-5 --dir <your repo>` from your template copy (or `npm run check -- i-5` inside the template).
+
+## Watch out
+
+- This hook watches the Edit and Write tools only. A shell command such as `echo X >> .env` goes through Bash, and this script cannot see its target: Bash input has `command`, not `file_path`. Add an `Edit(.env)` deny rule as well: it also covers shell redirects like `>> .env` ([permissions: Redirections](https://code.claude.com/docs/en/permissions#redirections)). The [hooks guide](https://code.claude.com/docs/en/hooks-guide#filter-hooks-with-matchers) shows a `Bash|PowerShell` pattern for full coverage.
+- Hooks in a repository's `.claude/settings.json` run in an interactive session once you trust the folder, and in `claude -p` or SDK runs without asking. Read a repository's hooks before you trust it or script `claude -p` in it.
+
+## Go further
+
+- Official: [Automate actions with hooks](https://code.claude.com/docs/en/hooks-guide) and the [hooks reference](https://code.claude.com/docs/en/hooks).
+
+---
+
+<sub>Sources: [Automate actions with hooks](https://code.claude.com/docs/en/hooks-guide) · [Hooks reference: workspace trust](https://code.claude.com/docs/en/hooks#workspace-trust) · [Configure permissions](https://code.claude.com/docs/en/permissions)</sub>
+
+<sub>← [Permissions, settings scopes and the sandbox](#) · [Intermediate index](#) · [Delegate to a custom subagent](#) → · Topic: [Hooks](../topics/hooks.md) · [Stuck on this lesson?](https://github.com/wesammustafa/Claude-Code-Everything-You-Need-to-Know/issues/new?template=lesson-feedback.yml&lesson=i-5)</sub>
diff --git a/.github/scripts/fixtures/valid-asset-tree/fixture.json b/.github/scripts/fixtures/valid-asset-tree/fixture.json
new file mode 100644
index 0000000..d316556
--- /dev/null
+++ b/.github/scripts/fixtures/valid-asset-tree/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "images",
+ "expect": "pass",
+ "about": "Referenced, kebab-case assets within budget; the mark pair behind a picture element; the card and its source as allowed orphans; Mermaid with accTitle and accDescr."
+}
diff --git a/.github/scripts/fixtures/valid-asset-tree/tree/README.md b/.github/scripts/fixtures/valid-asset-tree/tree/README.md
new file mode 100644
index 0000000..aa3f6e9
--- /dev/null
+++ b/.github/scripts/fixtures/valid-asset-tree/tree/README.md
@@ -0,0 +1,3 @@
+# Fixture <picture><source media="(prefers-color-scheme: dark)" srcset="assets/brand/mark-dark.svg"><img src="assets/brand/mark-light.svg" alt="Three trail blazes climbing a post" width="44"></picture>
+
+The guide.
diff --git a/.github/scripts/fixtures/valid-asset-tree/tree/assets/brand/mark-dark.svg b/.github/scripts/fixtures/valid-asset-tree/tree/assets/brand/mark-dark.svg
new file mode 100644
index 0000000..0c7be4e
--- /dev/null
+++ b/.github/scripts/fixtures/valid-asset-tree/tree/assets/brand/mark-dark.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg"/>
diff --git a/.github/scripts/fixtures/valid-asset-tree/tree/assets/brand/mark-light.svg b/.github/scripts/fixtures/valid-asset-tree/tree/assets/brand/mark-light.svg
new file mode 100644
index 0000000..0c7be4e
--- /dev/null
+++ b/.github/scripts/fixtures/valid-asset-tree/tree/assets/brand/mark-light.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg"/>
diff --git a/.github/scripts/fixtures/valid-asset-tree/tree/assets/brand/social-card.png b/.github/scripts/fixtures/valid-asset-tree/tree/assets/brand/social-card.png
new file mode 100644
index 0000000..0dd1608
--- /dev/null
+++ b/.github/scripts/fixtures/valid-asset-tree/tree/assets/brand/social-card.png
@@ -0,0 +1,2 @@
+�PNG
+
diff --git a/.github/scripts/fixtures/valid-asset-tree/tree/assets/brand/social-card.svg b/.github/scripts/fixtures/valid-asset-tree/tree/assets/brand/social-card.svg
new file mode 100644
index 0000000..0c7be4e
--- /dev/null
+++ b/.github/scripts/fixtures/valid-asset-tree/tree/assets/brand/social-card.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg"/>
diff --git a/.github/scripts/fixtures/valid-asset-tree/tree/assets/lessons/b-4/context-grid.png b/.github/scripts/fixtures/valid-asset-tree/tree/assets/lessons/b-4/context-grid.png
new file mode 100644
index 0000000..0dd1608
--- /dev/null
+++ b/.github/scripts/fixtures/valid-asset-tree/tree/assets/lessons/b-4/context-grid.png
@@ -0,0 +1,2 @@
+�PNG
+
diff --git a/.github/scripts/fixtures/valid-asset-tree/tree/docs/beginner/04-keep-a-session-on-track.md b/.github/scripts/fixtures/valid-asset-tree/tree/docs/beginner/04-keep-a-session-on-track.md
new file mode 100644
index 0000000..80f2483
--- /dev/null
+++ b/.github/scripts/fixtures/valid-asset-tree/tree/docs/beginner/04-keep-a-session-on-track.md
@@ -0,0 +1,14 @@
+# Keep a session on track
+
+![The context grid shows how much of the window each part of the session uses](../../assets/lessons/b-4/context-grid.png)
+
+A hook exits 0 to allow the edit or 2 to block it.
+
+```mermaid
+flowchart LR
+ accTitle: Hook exit paths
+ accDescr: An edit reaches the hook; exit 0 allows it and exit 2 blocks it.
+ A[Edit] --> B{Hook}
+ B -->|exit 0| C[Allowed]
+ B -->|exit 2| D[Blocked]
+```
diff --git a/.github/scripts/lib/git.mjs b/.github/scripts/lib/git.mjs
index f6a6f99..ea227b0 100644
--- a/.github/scripts/lib/git.mjs
+++ b/.github/scripts/lib/git.mjs
@@ -52,3 +52,27 @@ export function previousTag(root, tag) {
export function changedBetween(root, from, to) {
return git(root, ['diff', '--name-only', from, to]).split('\n').filter((f) => f && !isExcluded(f));
}
+
+// The lines each changed file adds relative to the base, as 1-based line
+// numbers in the working tree: { path: Set(lines) }. Untracked files count as
+// wholly added.
+export function addedLines(root, sha) {
+ const added = new Map();
+ let file = null;
+ let line = 0;
+ const diff = git(root, ['diff', '-U0', '--no-color', '--no-ext-diff', sha, '--']);
+ for (const row of diff.split('\n')) {
+ if (row.startsWith('+++ ')) {
+ file = row === '+++ /dev/null' ? null : row.slice(6);
+ if (file && !added.has(file)) added.set(file, new Set());
+ } else if (row.startsWith('@@')) {
+ line = Number(row.match(/\+(\d+)/)[1]);
+ } else if (file && row.startsWith('+')) {
+ added.get(file).add(line++);
+ }
+ }
+ const untracked = git(root, ['ls-files', '--others', '--exclude-standard', '-z']).split('\0').filter(Boolean);
+ for (const path of untracked) added.set(path, 'all');
+ for (const path of [...added.keys()]) if (isExcluded(path)) added.delete(path);
+ return added;
+}
diff --git a/.github/scripts/rules/em-dash.mjs b/.github/scripts/rules/em-dash.mjs
new file mode 100644
index 0000000..f187d46
--- /dev/null
+++ b/.github/scripts/rules/em-dash.mjs
@@ -0,0 +1,50 @@
+// Added prose lines carry no em dash (U+2014). Text in backticks, in code
+// blocks or in double quotes is exempt, and so is a line that carries the
+// marker <!-- allow-em-dash -->. Lines a change does not touch are not checked.
+import { existsSync } from 'node:fs';
+import { join } from 'node:path';
+import { readText } from '../lib/tree.mjs';
+import { addedLines } from '../lib/git.mjs';
+
+export const id = 'em-dash';
+export const modes = ['pr'];
+
+const PROSE = /\.(md|ya?ml|txt)$/;
+const ALLOW = '<!-- allow-em-dash -->';
+
+function codeLines(text) {
+ const inCode = new Set();
+ let fence = null;
+ text.split(/\r?\n/).forEach((line, i) => {
+ const f = line.match(/^ {0,3}(`{3,}|~{3,})/);
+ if (fence) {
+ inCode.add(i + 1);
+ if (f && f[1][0] === fence[0] && f[1].length >= fence.length) fence = null;
+ } else if (f) {
+ fence = f[1];
+ inCode.add(i + 1);
+ }
+ });
+ return inCode;
+}
+
+export function run(ctx) {
+ if (!ctx.base.sha) return { status: 'skip', summary: `diff-scoped: ${ctx.base.note}` };
+ const problems = [];
+ let checked = 0;
+ for (const [path, lines] of addedLines(ctx.root, ctx.base.sha)) {
+ if (!PROSE.test(path) || !existsSync(join(ctx.root, path))) continue;
+ const text = readText(ctx.root, path);
+ const code = path.endsWith('.md') ? codeLines(text) : new Set();
+ text.split(/\r?\n/).forEach((raw, i) => {
+ const n = i + 1;
+ if (lines !== 'all' && !lines.has(n)) return;
+ checked += 1;
+ if (code.has(n) || raw.includes(ALLOW)) return;
+ const prose = raw.replace(/(`+)[^`]*?\1/g, '').replace(/"[^"]*"|“[^”]*”/g, '');
+ if (prose.includes('—')) problems.push(`${path}:${n}: use a comma, colon, parentheses or a new sentence instead of the em dash`);
+ });
+ }
+ if (problems.length) return { status: 'fail', problems };
+ return { status: 'pass', summary: `${checked} added lines against ${ctx.base.ref ?? ctx.base.sha.slice(0, 7)}` };
+}
diff --git a/.github/scripts/rules/images.mjs b/.github/scripts/rules/images.mjs
new file mode 100644
index 0000000..041ca09
--- /dev/null
+++ b/.github/scripts/rules/images.mjs
@@ -0,0 +1,111 @@
+// Images and diagrams stay accessible and the assets/ tree stays tidy:
+// - every Markdown image and <img> has alt text;
+// - every Mermaid block declares accTitle and accDescr;
+// - files under assets/ have kebab-case names, an allowed type, fit the size
+// budget, and are referenced by a page (the brand sources and the social
+// card are the only allowed orphans).
+import { statSync } from 'node:fs';
+import { join, posix } from 'node:path';
+import { readText } from '../lib/tree.mjs';
+
+export const id = 'images';
+export const modes = ['pr', 'release'];
+
+const KB = 1024;
+const KEBAB = /^[a-z0-9]+(?:-[a-z0-9]+)*(?:\.[a-z0-9]+)*$/;
+const BUDGET = [
+ [/\.svg$/, 50 * KB, 'an SVG may be up to 50 KB'],
+ [/^assets\/lessons\/.+\.(png|jpe?g|webp)$/, 200 * KB, 'a capture may be up to 200 KB'],
+ [/^assets\/brand\/social-card\.png$/, 1000 * KB, 'the social card must be under 1 MB'],
+];
+const ALLOWED_ORPHANS = [/^assets\/brand\/[^/]+\.svg$/, /^assets\/brand\/social-card\.png$/];
+
+// Each line of a page with its code stripped: fenced blocks become null,
+// inline code spans are removed. Mermaid blocks are returned separately.
+function scan(text) {
+ const lines = [];
+ const mermaid = [];
+ let fence = null;
+ text.split(/\r?\n/).forEach((line, i) => {
+ const f = line.match(/^ {0,3}(`{3,}|~{3,})\s*(\S*)/);
+ if (fence) {
+ if (f && f[1][0] === fence.marker[0] && f[1].length >= fence.marker.length && !f[2]) {
+ if (fence.mermaid) mermaid.push(fence);
+ fence = null;
+ } else {
+ fence.body.push(line);
+ }
+ lines.push(null);
+ } else if (f) {
+ fence = { marker: f[1], mermaid: f[2].toLowerCase() === 'mermaid', start: i + 1, body: [] };
+ lines.push(null);
+ } else {
+ lines.push(line.replace(/(`+)[^`]*?\1/g, ''));
+ }
+ });
+ return { lines, mermaid };
+}
+
+function targets(line) {
+ const out = [];
+ for (const m of line.matchAll(/\]\(\s*<?([^)\s>]+)>?(?:\s+"[^"]*")?\s*\)/g)) out.push(m[1]);
+ for (const m of line.matchAll(/\b(?:src|href)\s*=\s*["']([^"']+)["']/gi)) out.push(m[1]);
+ for (const m of line.matchAll(/\bsrcset\s*=\s*["']([^"']+)["']/gi)) {
+ for (const part of m[1].split(',')) out.push(part.trim().split(/\s+/)[0]);
+ }
+ return out;
+}
+
+function resolveFrom(page, target) {
+ if (/^[a-z][a-z0-9+.-]*:/i.test(target) || target.startsWith('#')) return null;
+ const clean = decodeURIComponent(target.split(/[?#]/)[0]);
+ if (!clean) return null;
+ return clean.startsWith('/') ? clean.slice(1) : posix.normalize(posix.join(posix.dirname(page), clean));
+}
+
+export function run(ctx) {
+ const problems = [];
+ const referenced = new Set();
+ const pages = ctx.files.filter((f) => f.endsWith('.md'));
+ for (const page of pages) {
+ const { lines, mermaid } = scan(readText(ctx.root, page));
+ lines.forEach((line, i) => {
+ if (line === null) return;
+ const at = `${page}:${i + 1}`;
+ for (const m of line.matchAll(/!\[([^\]]*)\]\(/g)) {
+ if (!m[1].trim()) problems.push(`${at}: image has no alt text; say what the reader should learn from it`);
+ }
+ for (const m of line.matchAll(/<img\b[^>]*>/gi)) {
+ const alt = m[0].match(/\balt\s*=\s*["']([^"']*)["']/i);
+ if (!alt || !alt[1].trim()) problems.push(`${at}: <img> has no alt text`);
+ }
+ for (const t of targets(line)) {
+ const path = resolveFrom(page, t);
+ if (path) referenced.add(path);
+ }
+ });
+ for (const block of mermaid) {
+ const body = block.body.join('\n');
+ for (const key of ['accTitle', 'accDescr']) {
+ if (!new RegExp(`^\\s*${key}\\s*[:{]`, 'm').test(body)) problems.push(`${page}:${block.start}: Mermaid block has no ${key}`);
+ }
+ }
+ }
+
+ const assets = ctx.files.filter((f) => f.startsWith('assets/'));
+ for (const asset of assets) {
+ const bad = asset.split('/').slice(1).find((part) => !KEBAB.test(part));
+ if (bad) problems.push(`${asset}: "${bad}" is not kebab-case`);
+ if (!/\.(svg|png|jpe?g|webp)$/.test(asset)) problems.push(`${asset}: only SVG, PNG, JPEG and WebP files belong under assets/`);
+ const size = statSync(join(ctx.root, asset)).size;
+ for (const [pattern, limit, rule] of BUDGET) {
+ if (pattern.test(asset) && size > limit) problems.push(`${asset}: ${Math.ceil(size / KB)} KB; ${rule}`);
+ }
+ if (!referenced.has(asset) && !ALLOWED_ORPHANS.some((p) => p.test(asset))) {
+ problems.push(`${asset}: no page references it; delete it or use it`);
+ }
+ }
+
+ if (problems.length) return { status: 'fail', problems };
+ return { status: 'pass', summary: `${pages.length} pages, ${assets.length} files under assets/` };
+}
diff --git a/.github/scripts/rules/index.mjs b/.github/scripts/rules/index.mjs
index 3ab9bf3..89a4a41 100644
--- a/.github/scripts/rules/index.mjs
+++ b/.github/scripts/rules/index.mjs
@@ -5,5 +5,8 @@ import * as stubPaths from './stub-paths.mjs';
import * as stamps from './stamps.mjs';
import * as editionGate from './edition-gate.mjs';
import * as expiry from './expiry.mjs';
+import * as emDash from './em-dash.mjs';
+import * as images from './images.mjs';
+import * as lessonLint from './lesson-lint.mjs';
-export const rules = [internalLinks, anchorDiff, stubPaths, stamps, editionGate, expiry];
+export const rules = [internalLinks, anchorDiff, stubPaths, stamps, editionGate, expiry, emDash, images, lessonLint];
diff --git a/.github/scripts/rules/lesson-lint.mjs b/.github/scripts/rules/lesson-lint.mjs
new file mode 100644
index 0000000..2f29365
--- /dev/null
+++ b/.github/scripts/rules/lesson-lint.mjs
@@ -0,0 +1,130 @@
+// Lessons and Electives in the Level folders follow the lesson anatomy
+// (CONTRIBUTING.md#lessons): the H1, one <sub> header line, the six fixed
+// slots in order, the optional Watch out and Go further slots with at most
+// three items each, the Check slot's order, and the footer.
+import { readText } from '../lib/tree.mjs';
+import { outsideFences } from '../lib/markdown.mjs';
+
+export const id = 'lesson-lint';
+export const modes = ['pr', 'release'];
+
+const LEVELS = { beginner: 'Beginner', intermediate: 'Intermediate', advanced: 'Advanced' };
+const FIXED = ['Goal', 'You need', 'The idea', 'Worked example', 'Your turn', 'Check'];
+const OPTIONAL = ['Watch out', 'Go further'];
+const LESSON = /^docs\/(beginner|intermediate|advanced)\/(\d{2})-[^/]+\.md$/;
+const ELECTIVE = /^docs\/(beginner|intermediate|advanced)\/electives\/[^/]+\.md$/;
+
+export function lessonKind(path) {
+ const l = path.match(LESSON);
+ if (l) return { level: l[1], number: Number(l[2]), id: `${l[1][0]}-${Number(l[2])}`, elective: false };
+ const e = path.match(ELECTIVE);
+ if (e) return { level: e[1], elective: true };
+ return null;
+}
+
+const listItems = (lines) => lines.filter(({ line }) => /^([-*+]|\d+[.)]) /.test(line)).length;
+
+export function lint(path, text, kind) {
+ const problems = [];
+ const say = (msg) => problems.push(`${path}: ${msg}`);
+ const lines = outsideFences(text);
+ const filled = lines.filter(({ line }) => line.trim() !== '');
+
+ // H1 and header line.
+ if (!filled[0] || !/^# \S/.test(filled[0].line)) say('the first line must be the H1');
+ if (lines.filter(({ line }) => /^# /.test(line)).length > 1) say('only one H1 is allowed');
+ const header = filled[1]?.line.trim() ?? '';
+ if (!/^<sub>.*<\/sub>$/.test(header)) {
+ say('the line under the H1 must be the <sub> header line');
+ } else {
+ if (!header.includes(`**${LEVELS[kind.level]}**`)) say(`the header line must name the level as **${LEVELS[kind.level]}**`);
+ if (kind.elective) {
+ if (!/\bElective\b/.test(header)) say('an Elective\'s header line must say "Elective"');
+ } else {
+ const pos = header.match(/Lesson (\d+) of (\d+)/);
+ if (!pos) say('the header line must give the position as "Lesson N of M"');
+ else if (Number(pos[1]) !== kind.number) say(`the header line says Lesson ${pos[1]}, but the file is lesson ${kind.number}`);
+ }
+ if (!/about \d+ minutes/.test(header)) say('the header line must give the time as "about N minutes"');
+ if (!/Needs:/.test(header)) say('the header line must list "Needs:"');
+ if (!/Verified against/.test(header)) say('the header line must end with the Stamp');
+ }
+
+ // Slots.
+ const h2 = lines.filter(({ line }) => /^## /.test(line)).map(({ n, line }) => ({ n, name: line.slice(3).trim() }));
+ const names = h2.map((h) => h.name);
+ const expected = [...FIXED, ...OPTIONAL.filter((o) => names.includes(o))];
+ for (const slot of FIXED) if (!names.includes(slot)) say(`missing the "${slot}" slot`);
+ for (const name of names) if (!FIXED.includes(name) && !OPTIONAL.includes(name)) say(`"## ${name}" is not a lesson slot; use the fixed slot headings`);
+ const known = names.filter((n) => expected.includes(n));
+ if (known.join('|') !== expected.filter((n) => names.includes(n)).join('|') || new Set(names).size !== names.length) {
+ say(`slots must appear once each, in this order: ${expected.join(', ')}`);
+ }
+
+ const lastBreak = [...lines].reverse().find(({ line }) => /^-{3,}\s*$/.test(line));
+ const section = (name) => {
+ const at = h2.findIndex((h) => h.name === name);
+ if (at === -1) return null;
+ const end = h2[at + 1]?.n ?? lastBreak?.n ?? Infinity;
+ return lines.filter(({ n }) => n > h2[at].n && n < end);
+ };
+ for (const name of OPTIONAL) {
+ const body = section(name);
+ if (body && listItems(body) > 3) say(`"${name}" has ${listItems(body)} items; at most 3`);
+ }
+
+ // Check slot: task list, then the npm run check line, then "if not" diagnoses.
+ const check = section('Check');
+ if (check) {
+ const tasks = check.filter(({ line }) => /^- \[[ xX]\] /.test(line));
+ const selfChecks = tasks.filter(({ line }) => /self-check/i.test(line));
+ const runs = check.filter(({ line }) => /npm run check --/.test(line));
+ if (tasks.length === 0) say('the Check slot must start with a task list (- [ ] items)');
+ if (selfChecks.length > 1) say('the Check slot allows one self-check item at most');
+ if (kind.elective) {
+ if (runs.length) say('an Elective has no npm run check line');
+ } else if (runs.length === 0) {
+ say(`the Check slot must give the npm run check -- ${kind.id} line`);
+ } else {
+ if (tasks.length && runs[0].n < tasks[tasks.length - 1].n) say('the npm run check line must come after the task list');
+ const ids = [...runs[0].line.matchAll(/npm run check -- ([a-z]-\d+)/g)].map((m) => m[1]);
+ if (!ids.includes(kind.id)) say(`the npm run check line must name ${kind.id}`);
+ const after = check.filter(({ n }) => n > runs[0].n).map(({ line }) => line).join(' ');
+ const diagnoses = (after.match(/(^|[.!?]\s+)If /g) ?? []).length;
+ const tested = tasks.length - selfChecks.length;
+ if (diagnoses > tested) say(`the Check slot has ${diagnoses} "if not" diagnoses for ${tested} tested items; one per item at most`);
+ }
+ }
+
+ // Footer.
+ if (!lastBreak) {
+ say('missing the footer after a --- line');
+ } else {
+ const footer = lines.filter(({ n }) => n > lastBreak.n).map(({ line }) => line);
+ const at = (re) => footer.findIndex((l) => re.test(l));
+ const sources = at(/Sources:/);
+ const index = at(/\[(Beginner|Intermediate|Advanced) index\]/);
+ const stuck = at(/\[Stuck on this lesson\?\]\(([^)]*)\)/);
+ const topics = footer.join(' ').match(/Topic: \[/g) ?? [];
+ if (sources === -1) say('the footer must start with a Sources: line');
+ if (index === -1) say('the footer must link the level index');
+ if (!kind.elective && !/[←→]/.test(footer.join(' '))) say('the footer must link the previous or next lesson');
+ if (topics.length !== 1) say(`the footer must hold one Topic: link (found ${topics.length})`);
+ if (stuck === -1) {
+ say('the footer must end with the "Stuck on this lesson?" link');
+ } else {
+ const url = footer[stuck].match(/\[Stuck on this lesson\?\]\(([^)]*)\)/)[1];
+ if (!url.includes('template=lesson-feedback.yml')) say('"Stuck on this lesson?" must open the lesson-feedback form');
+ if (!kind.elective && !url.includes(`lesson=${kind.id}`)) say(`"Stuck on this lesson?" must prefill lesson=${kind.id}`);
+ }
+ if (sources !== -1 && index !== -1 && sources > index) say('the Sources: line must come before the navigation');
+ }
+ return problems;
+}
+
+export function run(ctx) {
+ const pages = ctx.files.map((f) => [f, lessonKind(f)]).filter(([, k]) => k);
+ const problems = pages.flatMap(([page, kind]) => lint(page, readText(ctx.root, page), kind));
+ if (problems.length) return { status: 'fail', problems };
+ return { status: 'pass', summary: `${pages.length} lessons and Electives` };
+}
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 92fb692..fdd53aa 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -236,6 +236,8 @@ Checks test state a script can read: git state, files, exit codes and settings f
Beginner lesson bodies carry no version numbers, prices or stability labels, and at most one caveat, about safety. Intermediate lessons carry at most two caveats, and Advanced lessons at most three.
+The `lesson-lint` check enforces this shape on every lesson (`docs/<level>/NN-*.md`) and Elective (`docs/<level>/electives/*.md`). An Elective's header line says `Elective` in place of the position, and its Check has no `npm run check` line.
+
### Callouts
Callouts are GitHub alerts, at most two per lesson, each with one meaning:
@@ -255,6 +257,7 @@ Callouts are GitHub alerts, at most two per lesson, each with one meaning:
- Every image has alt text that says what the reader should learn from it, not "screenshot" and not a repeat of the caption.
- Text in a diagram or image reaches 4.5:1 contrast in GitHub's light and dark themes; other marks reach 3:1.
- No third-party images (logos, icons, slides, product screenshots), no animation and no embedded video.
+- The `images` check enforces the alt text, the Mermaid lines, and the names, references and budget below.
- New images go under `assets/`: `assets/brand/` for the guide's identity and `assets/lessons/<lesson-id>/` for captures. Names are kebab-case, and paths are explicit and relative. Budget: an SVG up to 50 KB, a capture up to 200 KB. Every image that is not a capture ships its editable source beside it. Hand-drawn SVG is for the guide's identity pieces only.
### Headings
@@ -278,7 +281,7 @@ Callouts are GitHub alerts, at most two per lesson, each with one meaning:
- Filler such as "In this section we will explore", "as we mentioned earlier" or "it's worth noting that". Cut it.
- Marketing language. "The ultimate guide to mastering..." reads as hype; lead with what the reader actually gets.
- Multi-paragraph docstrings. One short line at most in code samples.
-- Em dashes in new prose. Keep them only inside quotations, identifiers and filenames.
+- Em dashes in new prose. Keep them only inside quotations, identifiers and filenames. The `em-dash` check skips text in backticks, code blocks and double quotes; any other line that must keep one carries `<!-- allow-em-dash -->`.
- Claims about features you have not verified.
## File layout