md-toc
Skill0 starsChanged 2 days agoMITView on GitHub
Give a long Markdown document a reader-first header, with a one-line TL;DR, a short Summary and a table of contents whose links actually work. The TOC is generated from the headings with GitHub-compatible anchors and every in-page link is checked. Use for "/md-toc", "add a TOC", "table of contents", "add a TL;DR / summary to this doc", "the TOC links are broken", "fix the anchors". Also use, without being asked, as the last step when writing or substantially editing any Markdown file that is long by the rule below.
In this repository7 other files it gives its agents.
- browser-selectSkill
- claude-usageSkill
- diagram-styleSkill
- docs-sweepSkill
- mac-disk-cleanupSkill
- session-exportSkill
- tracker-pageSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 3 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 21
Run --stats. Add the TL;DR, Summary and TOC if either is true:
- Distinctive: line 50
Write the TL;DR and Summary from the body you have just read.
- Distinctive: line 51
If a TL;DR or Summary already exists, update it in place.
- Very specific: line 52
If the document already has an intro paragraph under the title, keep it between the TL;DR and ## Summary.
- Distinctive: line 60
Read the document. Write or refresh the TL;DR and Summary at the top.
- Very specific: line 62
If it reports a broken anchor, fix the link, not the TOC (the hint did you mean #… usually names the right slug), then run it again.
- Very specific: line 63
When the file is going to GitHub or a customer and isn't sensitive, add --github for proof against the real renderer.
- Very specific: line 81
If headings change later, run md-toc FILE again.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
md-toc
Claude writes the TL;DR and the Summary. The script writes the table of contents and checks the links. Never type TOC entries or #anchors by hand. Hand-made anchors are how TOCs break (&, :, backticks, emoji, repeated headings). The script is bin/md-toc in this skill's folder.
md-toc FILE --stats # {"words": N, "headings": {...}, "has_toc": bool}
md-toc FILE # write/refresh the TOC in place, then check every #link
md-toc FILE --check # check only; exit 1 and file:line for each broken anchor
md-toc FILE --github # also render via GitHub's API and confirm each anchor existsOptions: --min-level 2 --max-level 3 (default: H2 and H3), --title Contents.
When a document gets the treatment
Run --stats. Add the TL;DR, Summary and TOC if either is true:
- 600 words or more, or
- 4 or more H2 headings.
Below that, leave the document alone unless the user asks. If they ask for the header on a short doc, do it.
Layout
# Title
**TL;DR:** One or two sentences: the conclusion or the ask, not the topic.
## Summary
3–6 bullets or one short paragraph. What the document says, decides or asks for,
with the key numbers and dates. Someone who reads only this should be able to act.
## Contents
<!-- toc -->
<!-- tocstop -->
## First real section
...- There is exactly one H1. If the doc has several H1s, demote the extra ones to H2 (and shift their children down a level) before generating, otherwise the TOC nesting is wrong.
- Write the TL;DR and Summary from the body you have just read. Don't invent anything the body doesn't say. Use the doc's own language and figures.
- If a TL;DR or Summary already exists, update it in place. Never add a second one.
- If the document already has an intro paragraph under the title, keep it between the TL;DR and
## Summary. Don't let it end up between the Summary and the Contents. - The markers can go anywhere. Without them, the script adds
## Contentsbefore the first H2 that isn't the TL;DR or Summary. - The
Contentsheading itself is left out of the TOC.Summarystays in. - Headings get an
<a id="…"></a>tag in the source. That's deliberate and needed. See below.
Steps
md-toc FILE --statsand decide using the rule above.- Read the document. Write or refresh the TL;DR and Summary at the top.
md-toc FILE. This writes the TOC, adds the heading anchors (see below) and checks every](#…),href="#…"and[ref]: #…link in the file. Re-running it replaces the TOC rather than adding another.- If it reports a broken anchor, fix the link, not the TOC (the hint
did you mean #…usually names the right slug), then run it again. Done means exit 0. - When the file is going to GitHub or a customer and isn't sensitive, add
--githubfor proof against the real renderer. It sends the file's text to api.github.com, so skip it for client-confidential documents and say you skipped it. - Tell the user how many TOC entries were written, that the links check clean, and whether the GitHub render was verified.
Where the links work
Many viewers never give headings an id. mdserve 1.1.0 is one: it renders <h2>Background</h2>, so a #background link has nothing to jump to. To cover them, the script writes the anchor into every heading the TOC or a body link points at:
## <a id="background"></a>BackgroundThe anchor names follow GitHub's rules (github-slugger), so GitHub, GitLab, VS Code and mdserve all jump to the same place, and the tag doesn't show. The script rewrites these tags on every run, so renaming a heading moves its anchor too. --check fails on any link that only works where the viewer makes its own heading ids. --no-anchors leaves the tags out, for GitHub-only documents where clean source matters more.
These still won't work:
- Viewers that strip raw HTML, such as Bitbucket, which also prefixes its own ids with
markdown-header-. If the doc lives there, say so. Don't hand-patch the anchors. - PDF via pm-render or markdown-to-pdf: the anchors work if the converter keeps HTML ids. Check one link in the output.
If headings change later, run md-toc FILE again. The TOC and the anchors are regenerated, and the check catches any body link that still points at the old heading text.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

