Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

README: Markdown Local Link Checker


Owner: Vadim Rudakov, lefthand67@gmail.com
Version: 0.1.0
Birth: 2025-12-16
Last Modified: 2025-12-16


Overview

This script performs fast, local-only validation of relative file links (Markdown, image, etc.) within a directory of Markdown files. It is built using the Smallest Viable Architecture (SVA) principle, relying exclusively on Python’s standard library (pathlib, re, sys, argparse, tempfile) for maximum portability and zero external dependencies.

This tool is designed to serve as a high-quality diagnostic step in AI Agent workflows (like aider or custom SLMs), providing clear, parsable feedback to automate documentation maintenance.

Features

Usage

Run the script from your project’s root directory:

python3 helpers/md_check_broken_links.py [directory] [file_pattern] [options]

Real example:

$ python3 helpers/md_check_broken_links.py
Found 25 markdown files in /home/user/ai_engineering_book

❌ 4 Broken links found:
BROKEN LINK: File '4_orchestration/workflows/release_notes_generation/slm_backed_release_documentation_pipeline_architecture.md' contains broken link: ./images/ai_assisted_doc_flow_1.png
BROKEN LINK: File '4_orchestration/workflows/release_notes_generation/post-mortem_slm_non-determinism_in_commit_generation.md' contains broken link: ./git_production_workflow_standards.md
BROKEN LINK: File '4_orchestration/workflows/release_notes_generation/post-mortem_slm_non-determinism_in_commit_generation.md' contains broken link: ./tools_commit_and_changelog_tooling_for_release_pipelines.md
BROKEN LINK: File '4_orchestration/workflows/release_notes_generation/post-mortem_slm_non-determinism_in_commit_generation.md' contains broken link: ./production_git_workflow_standards.md

Required Arguments (Optional when using defaults)

ArgumentDefaultDescription
directory.The root directory to start the search.
file_pattern*.mdThe glob pattern to match markdown files (e.g., *.md, **.txt).

Examples

CommandDescription
python3 helpers/md_check_broken_links.pyCheck all *.md files in the current directory and subdirectories.
python3 helpers/md_check_broken_links.py ./docsCheck all *.md files inside the ./docs directory.
python3 helpers/md_check_broken_links.py . "*.txt"Check all *.txt files recursively from the current directory.

Options

1. Exclusion Options

Use these options to prevent checking files or directories you know contain incomplete work or are not meant for link validation.

| Option | Shorthand | Default | Description | | :--- | :--- | :--- | | --exclude-dirs | N/A | in_progress pr | Directory names to exclude (e.g., drafts temp). Can list multiple names. | | --exclude-files | N/A | .aider.chat.history.md | Specific file names to exclude (e.g., LICENSE.md). Can list multiple names. |

Example using exclusions:

python3 helpers/md_check_broken_links.py --exclude-dirs drafts temp --exclude-files README.md

2. Verbose Mode

| Option | Shorthand | Default | Description | | :--- | :--- | :--- | | --verbose | N/A | False | Prints every file checked, every link skipped, and every successful link resolution (OK: link -> target). Highly recommended for debugging. |

Example using verbose mode:

python3 helpers/md_check_broken_links.py --verbose

Exit Codes

CodeStatusDescription
0Success✅ All links are valid!
1Failure❌ [N] Broken links found: (Followed by detailed report)