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: add a guide check runner with an offline internal link check (#49)

Wesam Abousaid265cf9f12817
diff --git a/.github/scripts/check.mjs b/.github/scripts/check.mjs
new file mode 100644
index 0000000..4e07bcc
--- /dev/null
+++ b/.github/scripts/check.mjs
@@ -0,0 +1,55 @@
+#!/usr/bin/env node
+// Runs the guide's checks over a repo tree and exits non-zero if any fails.
+//
+// node .github/scripts/check.mjs [--root .] [--mode pr|release|scheduled]
+// [--base <ref>] [--tag <tag>] [--only <rule,...>]
+import { parseArgs } from 'node:util';
+import { resolve } from 'node:path';
+import { rules } from './rules/index.mjs';
+import { listFiles } from './lib/tree.mjs';
+
+const MODES = ['pr', 'release', 'scheduled'];
+
+function usage(message) {
+ console.error(`${message}\nusage: node .github/scripts/check.mjs [--root DIR] [--mode ${MODES.join('|')}] [--base REF] [--tag TAG] [--only RULE,...]`);
+ process.exit(2);
+}
+
+let args;
+try {
+ args = parseArgs({
+ options: {
+ root: { type: 'string', default: '.' },
+ mode: { type: 'string', default: 'pr' },
+ base: { type: 'string' },
+ tag: { type: 'string' },
+ only: { type: 'string' },
+ },
+ }).values;
+} catch (error) {
+ usage(error.message);
+}
+if (!MODES.includes(args.mode)) usage(`unknown mode: ${args.mode}`);
+
+const known = new Set(rules.map((r) => r.id));
+const only = args.only ? args.only.split(',') : null;
+for (const name of only ?? []) if (!known.has(name)) usage(`unknown rule: ${name}`);
+
+const root = resolve(args.root);
+const ctx = { root, mode: args.mode, tag: args.tag, files: listFiles(root) };
+
+let failed = false;
+for (const rule of rules) {
+ if (only ? !only.includes(rule.id) : !rule.modes.includes(args.mode)) continue;
+ let result;
+ try {
+ result = await rule.run(ctx);
+ } catch (error) {
+ result = { status: 'fail', problems: [`crashed: ${error.stack ?? error}`] };
+ }
+ const label = result.status.toUpperCase();
+ console.log(`${label} ${rule.id}${result.summary ? `: ${result.summary}` : ''}`);
+ for (const problem of result.problems ?? []) console.log(` ${problem}`);
+ if (result.status === 'fail') failed = true;
+}
+process.exit(failed ? 1 : 0);
diff --git a/.github/scripts/fixtures/broken-internal-fragment/fixture.json b/.github/scripts/fixtures/broken-internal-fragment/fixture.json
new file mode 100644
index 0000000..f2b5b92
--- /dev/null
+++ b/.github/scripts/fixtures/broken-internal-fragment/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "internal-links",
+ "expect": "fail",
+ "about": "A link to a heading that does not exist on the target page."
+}
diff --git a/.github/scripts/fixtures/broken-internal-fragment/tree/README.md b/.github/scripts/fixtures/broken-internal-fragment/tree/README.md
new file mode 100644
index 0000000..eb58e1f
--- /dev/null
+++ b/.github/scripts/fixtures/broken-internal-fragment/tree/README.md
@@ -0,0 +1,3 @@
+# Fixture
+
+See [the setup steps](guide.md#install-the-cli) before you start.
diff --git a/.github/scripts/fixtures/broken-internal-fragment/tree/guide.md b/.github/scripts/fixtures/broken-internal-fragment/tree/guide.md
new file mode 100644
index 0000000..357888d
--- /dev/null
+++ b/.github/scripts/fixtures/broken-internal-fragment/tree/guide.md
@@ -0,0 +1,5 @@
+# Guide
+
+## Install Claude Code
+
+Steps.
diff --git a/.github/scripts/fixtures/broken-link-in-live-config/fixture.json b/.github/scripts/fixtures/broken-link-in-live-config/fixture.json
new file mode 100644
index 0000000..156f912
--- /dev/null
+++ b/.github/scripts/fixtures/broken-link-in-live-config/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "internal-links",
+ "expect": "fail",
+ "about": "A broken link inside the live .claude/ folder. The folder is generated at test time, because a committed .claude/ would be live config."
+}
diff --git a/.github/scripts/fixtures/broken-link-in-live-config/generate.mjs b/.github/scripts/fixtures/broken-link-in-live-config/generate.mjs
new file mode 100644
index 0000000..51d651e
--- /dev/null
+++ b/.github/scripts/fixtures/broken-link-in-live-config/generate.mjs
@@ -0,0 +1,11 @@
+import { mkdirSync, writeFileSync } from 'node:fs';
+import { join } from 'node:path';
+
+export default function generate(root) {
+ const dir = join(root, '.claude', 'skills', 'review');
+ mkdirSync(dir, { recursive: true });
+ writeFileSync(
+ join(dir, 'SKILL.md'),
+ '---\ndescription: Review a page\n---\n\nFollow [the style guide](../../../STYLE.md).\n',
+ );
+}
diff --git a/.github/scripts/fixtures/broken-link-in-live-config/tree/README.md b/.github/scripts/fixtures/broken-link-in-live-config/tree/README.md
new file mode 100644
index 0000000..f004e9d
--- /dev/null
+++ b/.github/scripts/fixtures/broken-link-in-live-config/tree/README.md
@@ -0,0 +1,3 @@
+# Fixture
+
+Nothing to see here.
diff --git a/.github/scripts/fixtures/scratch-folder-not-checked/fixture.json b/.github/scripts/fixtures/scratch-folder-not-checked/fixture.json
new file mode 100644
index 0000000..13f43dd
--- /dev/null
+++ b/.github/scripts/fixtures/scratch-folder-not-checked/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "internal-links",
+ "expect": "pass",
+ "about": "The private scratch folder is outside every check, so its broken links do not fail the run."
+}
diff --git a/.github/scripts/fixtures/scratch-folder-not-checked/generate.mjs b/.github/scripts/fixtures/scratch-folder-not-checked/generate.mjs
new file mode 100644
index 0000000..735660b
--- /dev/null
+++ b/.github/scripts/fixtures/scratch-folder-not-checked/generate.mjs
@@ -0,0 +1,9 @@
+// Generated rather than committed: the maintainer's clone ignores every
+// .scratch/ folder, so a plain `git add` would leave a copy out of the index.
+import { mkdirSync, writeFileSync } from 'node:fs';
+import { join } from 'node:path';
+
+export default function generate(root) {
+ mkdirSync(join(root, '.scratch'), { recursive: true });
+ writeFileSync(join(root, '.scratch', 'notes.md'), '# Notes\n\nA [draft link](missing.md#nowhere).\n');
+}
diff --git a/.github/scripts/fixtures/scratch-folder-not-checked/tree/README.md b/.github/scripts/fixtures/scratch-folder-not-checked/tree/README.md
new file mode 100644
index 0000000..e09a9d9
--- /dev/null
+++ b/.github/scripts/fixtures/scratch-folder-not-checked/tree/README.md
@@ -0,0 +1,3 @@
+# Fixture
+
+See [the guide](README.md).
diff --git a/.github/scripts/install-lychee.sh b/.github/scripts/install-lychee.sh
new file mode 100755
index 0000000..53a1a88
--- /dev/null
+++ b/.github/scripts/install-lychee.sh
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+# Installs a pinned, statically linked lychee on a Linux x86_64 runner and
+# puts it on PATH.
+set -euo pipefail
+
+version=0.24.2
+sha256=73657a111819a30c47c08352896796f23d64e4eb2b3ed39b6d32149241566fc5
+name=lychee-x86_64-unknown-linux-musl
+
+dir="${RUNNER_TEMP:-/tmp}/lychee"
+mkdir -p "$dir"
+curl -fsSL -o "$dir/$name.tar.gz" \
+ "https://github.com/lycheeverse/lychee/releases/download/lychee-v$version/$name.tar.gz"
+echo "$sha256 $dir/$name.tar.gz" | sha256sum --check --quiet
+tar -xzf "$dir/$name.tar.gz" -C "$dir"
+echo "$dir/$name" >> "${GITHUB_PATH:-/dev/null}"
+"$dir/$name/lychee" --version
diff --git a/.github/scripts/lib/tree.mjs b/.github/scripts/lib/tree.mjs
new file mode 100644
index 0000000..c19efd8
--- /dev/null
+++ b/.github/scripts/lib/tree.mjs
@@ -0,0 +1,38 @@
+// The files a check looks at, and the folders every check leaves out.
+import { execFileSync } from 'node:child_process';
+import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
+import { join, relative, sep } from 'node:path';
+
+// The private scratch folder and the checks' own fixtures are never checked
+// as part of the guide.
+export const EXCLUDED = ['.git/', '.scratch/', '.github/scripts/fixtures/', 'node_modules/'];
+
+export function isExcluded(path) {
+ return EXCLUDED.some((prefix) => path === prefix.slice(0, -1) || path.startsWith(prefix));
+}
+
+function walk(root, dir = root, out = []) {
+ for (const entry of readdirSync(dir)) {
+ const full = join(dir, entry);
+ const rel = relative(root, full).split(sep).join('/');
+ if (isExcluded(rel) || isExcluded(`${rel}/`)) continue;
+ if (statSync(full).isDirectory()) walk(root, full, out);
+ else out.push(rel);
+ }
+ return out;
+}
+
+export function listFiles(root) {
+ if (existsSync(join(root, '.git'))) {
+ const out = execFileSync(
+ 'git', ['ls-files', '-z', '--cached', '--others', '--exclude-standard'],
+ { cwd: root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 },
+ );
+ return out.split('\0').filter((f) => f && !isExcluded(f) && existsSync(join(root, f))).sort();
+ }
+ return walk(root).sort();
+}
+
+export function readText(root, path) {
+ return readFileSync(join(root, path), 'utf8');
+}
diff --git a/.github/scripts/rules/index.mjs b/.github/scripts/rules/index.mjs
new file mode 100644
index 0000000..0ae532b
--- /dev/null
+++ b/.github/scripts/rules/index.mjs
@@ -0,0 +1,4 @@
+// Every rule the suite runs, in report order.
+import * as internalLinks from './internal-links.mjs';
+
+export const rules = [internalLinks];
diff --git a/.github/scripts/rules/internal-links.mjs b/.github/scripts/rules/internal-links.mjs
new file mode 100644
index 0000000..c1bbb23
--- /dev/null
+++ b/.github/scripts/rules/internal-links.mjs
@@ -0,0 +1,39 @@
+// Internal links and their fragments resolve, checked offline with lychee.
+import { spawnSync } from 'node:child_process';
+import { fileURLToPath } from 'node:url';
+import { relative, sep } from 'node:path';
+
+export const id = 'internal-links';
+export const modes = ['pr', 'release'];
+
+export function run(ctx) {
+ const pages = ctx.files.filter((f) => f.endsWith('.md'));
+ if (pages.length === 0) return { status: 'pass', summary: 'no Markdown files' };
+ const lychee = process.env.LYCHEE || 'lychee';
+ const result = spawnSync(
+ lychee,
+ ['--no-progress', '--offline', '--include-fragments', '--format', 'json', '--root-dir', ctx.root, ...pages],
+ { cwd: ctx.root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 },
+ );
+ if (result.error?.code === 'ENOENT') {
+ return { status: 'fail', problems: [`lychee not found: install lychee 0.24 or set LYCHEE to its path`] };
+ }
+ let report;
+ try {
+ report = JSON.parse(result.stdout);
+ } catch {
+ return { status: 'fail', problems: [`lychee exited ${result.status}: ${result.stderr.trim() || result.stdout.trim()}`] };
+ }
+ const problems = [];
+ for (const [file, errors] of Object.entries(report.error_map ?? {})) {
+ for (const e of errors) {
+ const target = e.url.startsWith('file://')
+ ? relative(ctx.root, fileURLToPath(e.url.split('#')[0])).split(sep).join('/') + (e.url.includes('#') ? `#${e.url.split('#')[1]}` : '')
+ : e.url;
+ const at = e.span ? `:${e.span.line}` : '';
+ problems.push(`${file}${at}: ${target}: ${e.status?.text ?? 'error'}`);
+ }
+ }
+ if (problems.length) return { status: 'fail', problems };
+ return { status: 'pass', summary: `${report.total} links in ${pages.length} pages` };
+}
diff --git a/.github/scripts/test/checks.test.mjs b/.github/scripts/test/checks.test.mjs
new file mode 100644
index 0000000..739b313
--- /dev/null
+++ b/.github/scripts/test/checks.test.mjs
@@ -0,0 +1,43 @@
+// Self-test for the guide checks: every committed fixture must get the
+// verdict it declares from the rule it names, and the real tree must pass.
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import { readdirSync, readFileSync, existsSync } from 'node:fs';
+import { join, dirname } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { materialize, runChecks } from './harness.mjs';
+
+const here = dirname(fileURLToPath(import.meta.url));
+const fixturesDir = join(here, '..', 'fixtures');
+
+for (const name of readdirSync(fixturesDir).sort()) {
+ const dir = join(fixturesDir, name);
+ if (!existsSync(join(dir, 'fixture.json'))) continue;
+ const spec = JSON.parse(readFileSync(join(dir, 'fixture.json'), 'utf8'));
+ test(`${name}: ${spec.rule} should ${spec.expect}`, async () => {
+ const tree = await materialize(dir, spec);
+ try {
+ const { code, output } = runChecks(tree.root, {
+ only: spec.rule,
+ mode: spec.mode ?? 'pr',
+ base: tree.base,
+ tag: spec.tag,
+ });
+ if (spec.expect === 'fail') {
+ assert.notEqual(code, 0, output);
+ assert.match(output, new RegExp(`^FAIL ${spec.rule}\\b`, 'm'), output);
+ } else {
+ assert.equal(code, 0, output);
+ assert.doesNotMatch(output, /^FAIL /m, output);
+ }
+ } finally {
+ tree.cleanup();
+ }
+ });
+}
+
+test('the real tree passes in pr mode', () => {
+ const repoRoot = join(here, '..', '..', '..');
+ const { code, output } = runChecks(repoRoot, { mode: 'pr' });
+ assert.equal(code, 0, output);
+});
diff --git a/.github/scripts/test/harness.mjs b/.github/scripts/test/harness.mjs
new file mode 100644
index 0000000..fea3d5e
--- /dev/null
+++ b/.github/scripts/test/harness.mjs
@@ -0,0 +1,69 @@
+// Builds a fixture's tree in a temporary git repo and runs the checks on it.
+//
+// A fixture folder holds fixture.json, tree/ (the head state), an optional
+// base/ (the state before the change, for diff-scoped rules) and an optional
+// generate.mjs. generate.mjs writes files that would be live Claude Code
+// config if they were committed (.claude/, CLAUDE.md, AGENTS.md, .mcp.json),
+// so they exist only in the temporary copy.
+import { cpSync, existsSync, mkdtempSync, readdirSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join, dirname } from 'node:path';
+import { execFileSync, spawnSync } from 'node:child_process';
+import { fileURLToPath, pathToFileURL } from 'node:url';
+
+const checkScript = join(dirname(fileURLToPath(import.meta.url)), '..', 'check.mjs');
+
+function git(cwd, ...args) {
+ return execFileSync('git', args, { cwd, encoding: 'utf8' }).trim();
+}
+
+function clearTree(root) {
+ for (const entry of readdirSync(root)) {
+ if (entry !== '.git') rmSync(join(root, entry), { recursive: true, force: true });
+ }
+}
+
+async function addState(root, dir, generator, phase) {
+ if (existsSync(dir)) cpSync(dir, root, { recursive: true });
+ if (generator) await generator(root, phase);
+ git(root, 'add', '-A');
+ git(root, 'commit', '-q', '--allow-empty', '-m', phase);
+ return git(root, 'rev-parse', 'HEAD');
+}
+
+export async function materialize(fixtureDir, spec) {
+ const root = mkdtempSync(join(tmpdir(), 'guide-check-'));
+ git(root, 'init', '-q', '-b', 'main');
+ // The fixture's own ignore rules apply; the machine's global ones do not.
+ git(root, 'config', 'core.excludesFile', '/dev/null');
+ git(root, 'config', 'user.name', 'fixture');
+ git(root, 'config', 'user.email', '[email protected]');
+ git(root, 'config', 'commit.gpgsign', 'false');
+
+ const genPath = join(fixtureDir, 'generate.mjs');
+ const generator = existsSync(genPath)
+ ? (await import(pathToFileURL(genPath).href)).default
+ : null;
+
+ let base;
+ if (existsSync(join(fixtureDir, 'base'))) {
+ base = await addState(root, join(fixtureDir, 'base'), generator, 'base');
+ clearTree(root);
+ }
+ await addState(root, join(fixtureDir, 'tree'), generator, 'head');
+ if (spec.tags) {
+ for (const [tag, ref] of Object.entries(spec.tags)) {
+ git(root, 'tag', tag, ref === 'base' ? base : 'HEAD');
+ }
+ }
+ return { root, base, cleanup: () => rmSync(root, { recursive: true, force: true }) };
+}
+
+export function runChecks(root, { only, mode = 'pr', base, tag } = {}) {
+ const args = [checkScript, '--root', root, '--mode', mode];
+ if (only) args.push('--only', only);
+ if (base) args.push('--base', base);
+ if (tag) args.push('--tag', tag);
+ const result = spawnSync(process.execPath, args, { encoding: 'utf8' });
+ return { code: result.status, output: `${result.stdout}${result.stderr}` };
+}
diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml
new file mode 100644
index 0000000..acbc8d8
--- /dev/null
+++ b/.github/workflows/checks.yml
@@ -0,0 +1,31 @@
+name: Guide checks
+
+on:
+ pull_request:
+ push:
+ branches: [main]
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+jobs:
+ checks:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+ - uses: actions/setup-node@v4
+ with:
+ node-version: lts/*
+ - name: Install lychee
+ run: .github/scripts/install-lychee.sh
+ - name: Self-test the checks against their fixtures
+ run: node --test '.github/scripts/test/**/*.test.mjs'
+ - name: Run the checks
+ env:
+ BASE_REF: ${{ github.base_ref }}
+ run: |
+ if [ -n "$BASE_REF" ]; then base="origin/$BASE_REF"; else base="HEAD^"; fi
+ node .github/scripts/check.mjs --mode pr --base "$base"
diff --git a/.github/workflows/links.yml b/.github/workflows/links.yml
index 3fb37ab..57446bf 100644
--- a/.github/workflows/links.yml
+++ b/.github/workflows/links.yml
@@ -1,8 +1,8 @@
name: Check links
+# Pull requests run the offline link check in checks.yml. This weekly run
+# still checks external links.
on:
- pull_request:
- paths: ["**/*.md"]
schedule:
- cron: "0 6 * * 1" # Mondays 06:00 UTC
workflow_dispatch:
diff --git a/AGENTS.md b/AGENTS.md
index 83a5467..dc13b7a 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -30,6 +30,7 @@ Before you write or change one, fetch the Tier 1 source for its domain:
## Pull requests
- One change per PR. Fill in the PR template. For its claim table, start a separate agent that tries to refute each changed claim against Tier 1, and copy that agent's results into the table; never fill the Result column yourself. Leave the box "I have personally verified any AI-assisted content in this PR" for the user to tick.
+- Before you open a PR, run `node .github/scripts/check.mjs` on your working tree and fix every `FAIL`; CI runs the same command. If you change a rule, also run `node --test '.github/scripts/test/**/*.test.mjs'`.
- Lesson PRs, and example PRs whose example a core lesson or capstone uses, record a dry-run in a clean configuration: [CONTRIBUTING.md#pull-requests](CONTRIBUTING.md#pull-requests).
## Listings
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index ba535f0..a3e371f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -185,6 +185,22 @@ Each pull request carries one change. Fill in every section of the [pull request
- **Images.** Capture hygiene and contrast ([Diagrams and images](#diagrams-and-images)) are review items in the template, because CI cannot judge them.
- **Review.** The maintainer reviews and merges every pull request ([CODEOWNERS](.github/CODEOWNERS)).
+### Checks
+
+Before you open a pull request, run the guide's checks on your working tree, from the repo root:
+
+```bash
+node .github/scripts/check.mjs
+```
+
+It needs Node.js LTS and [lychee](https://github.com/lycheeverse/lychee) 0.24 on your `PATH` (or set `LYCHEE` to its path). Each rule prints `PASS`, `FAIL` or `SKIP` with its name, and the command exits non-zero if any rule fails. Pull request CI runs the same command with `--base` set to the target branch; diff-scoped rules compare against `origin/main` locally.
+
+Each rule has known-bad fixtures under `.github/scripts/fixtures/`, one folder per case: `fixture.json` names the rule and the expected result, `tree/` holds the files, `base/` the state before a change, and `generate.mjs` writes anything that would be live Claude Code config if committed. If you change a rule, run the self-test too:
+
+```bash
+node --test '.github/scripts/test/**/*.test.mjs'
+```
+
## Doc style guide
The guide is moving to lessons in three levels: Beginner, Intermediate and Advanced. New pages follow these rules. Pages from the previous edition are brought in line when they are rewritten.