Back to Skills

markdown-toc

Use when generating or updating Table of Contents in markdown files. Supports multiple files, glob patterns, configurable header levels, and various insertion modes. Triggered by "generate toc", "update toc", "table of contents", "add toc to markdown".

4starsUpdated 3/7/2026

Security Assessment

Safe(100/100)
Security Score100/100

About markdown-toc

The markdown-toc skill is a powerful tool designed to automatically generate and manage Table of Contents (TOC) in markdown files. It solves the problem of manually creating or updating TOCs in markdown documents by automating the process. Whether you're working on a single file or multiple files, this tool saves time by streamlining TOC generation, ensuring consistency and accuracy. The skill is ideal for projects that include long markdown files with multiple sections, where keeping track of the structure and providing navigation is essential for the reader's experience.

This skill offers various customization options such as selecting header levels, choosing insertion modes, and processing files recursively. It supports single-file and batch processing with glob patterns, allowing you to handle many markdown files at once. You can configure the TOC title, control which header levels to include, and even preview the changes before committing them. The insertion modes give flexibility, with options like inserting at the top of the file, replacing an existing TOC, or inserting it between custom markers. Additionally, the tool ensures compatibility with popular platforms, generating GitHub-friendly anchor links.

This tool is particularly useful for technical documentation writers, developers, or anyone working with markdown files who needs to automate the creation of TOCs. It's a great choice for those managing large repositories with multiple markdown files or for individuals looking to maintain consistency across their markdown documents without manual intervention.

FAQ

How do I generate a TOC for a single markdown file?

You can generate a TOC for a single markdown file by running the command: `python scripts/generate_toc.py README.md`.

Can I preview the TOC changes before applying them?

Yes, you can preview the TOC without modifying the file by using the `--dry-run` option: `python scripts/generate_toc.py --dry-run README.md`.

How can I control the header levels included in the TOC?

You can control the header levels by using the `--min-level N` and `--max-level N` options. For example, to include headers from H1 to H4, use `--min-level 1 --max-level 4`.

Can I process multiple markdown files at once?

Yes, you can process multiple files by using glob patterns or recursive processing. For example, `python scripts/generate_toc.py docs/*.md` will process all markdown files in the 'docs' directory.

What happens if there is already a TOC in my markdown file?

The tool can replace an existing TOC, insert the new one after specific markers, or even insert it at the top of the file depending on the selected insertion mode.

Install markdown-toc

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill