Skip to content

About

Personal markitdown CLI wrapper + Claude Code skill (mdc)

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

markitdown

A personal mdc CLI that wraps Microsoft's markitdown library with recursive directory conversion, mtime-based skip caching, and optional OpenAI image OCR and Whisper audio transcription.

Not Microsoft's project. This repo is Eric's thin wrapper around microsoft/markitdown, which does the actual document parsing (pulled in as the markitdown[all] dependency). The package is published locally as markitdown-cli; all credit for the conversion engine goes upstream. Remote: github.com/BaruchEric/markitdown-cli.

TL;DR

  • What: mdc <file-or-dir> — convert documents (PDF, Office, HTML, images, audio, …) to Markdown, one file or a whole tree.
  • How: delegates parsing to Microsoft's markitdown; adds the CLI ergonomics — recursive walking, mirrored output layout, mtime-based skip, per-file error aggregation, meaningful exit codes.
  • Optional AI: --ocr describes images via OpenAI gpt-4o-mini; --audio transcribes audio via the Whisper API (whisper-1). Plain conversions need no API key.
  • Stack: Python ≥ 3.11, uv-managed, hatchling build, pytest (12 tests); deps: markitdown[all], openai, python-dotenv.
  • Run: uv tool install . → mdc notes.pdf or mdc ~/Documents/papers -o ~/md.
  • A companion markitdown Claude skill calls mdc automatically when Claude Code hits a file it can't read directly.

Overview

mdc is a single-purpose disk utility for turning non-text files into Markdown. It hands the actual parsing to Microsoft's markitdown library and layers on what a batch CLI needs:

  • Single file or recursive tree. Point it at a file or a directory; a directory is walked recursively (rglob) and the output mirrors the source layout.
  • Skip-if-up-to-date. A target .md whose mtime is newer than (or equal to) its source is left untouched unless --force is passed, so re-running over a large folder only reconverts what changed.
  • Batch-tolerant. In tree mode a file that fails to convert is recorded as an error and the run continues; unsupported extensions are counted and skipped rather than aborting the batch.
  • Optional OpenAI features. --ocr wires markitdown's llm_client to describe images via gpt-4o-mini; --audio routes audio files (.mp3/.wav/.m4a/.flac) through the Whisper API instead of upstream parsing.

Output naming: a source file report.pdf becomes report.pdf.md (suffix appended, not replaced); a source directory docs/ defaults to a sibling docs.md/ tree unless -o overrides it.

Supported extensions (see formats.py): PDF; Office (.docx/.pptx/.xlsx/.xls); web (.html/.htm); data (.csv/.json/.xml); .epub/.zip/.msg; text (.txt/.rtf/.odt); images (.jpg/.jpeg/.png/.gif/.bmp/.tiff); audio (.mp3/.wav/.m4a/.flac). Match is case-insensitive; anything else is counted "unsupported" and skipped.

Tech stack

  • Python ≥ 3.11, managed with uv (uv.lock, .python-version).
  • markitdown[all] ≥ 0.1.5 — the conversion engine (upstream, Microsoft).
  • openai ≥ 1.40 — image description + Whisper transcription (only invoked with --ocr/--audio).
  • python-dotenv — loads OPENAI_API_KEY from a shared env file.
  • Build: hatchling (packages src/markitdown_cli). Tests: pytest (dev dependency group). CI hygiene: Dependabot (.github/dependabot.yml).

Getting started

Install

Install globally as a uv tool:

uv tool install .        # from inside the repo; puts `mdc` on your PATH

Reinstall gotcha. uv tool install --force . can reuse cached builds and ship stale code. For a guaranteed-fresh build after local edits:

uv tool uninstall markitdown-cli && uv tool install --reinstall --no-cache .

Convert

mdc notes.pdf                       # -> notes.pdf.md next to the source
mdc report.docx -o report.md        # explicit output path
mdc ~/Documents/papers              # recurse; output to sibling papers.md/
mdc ~/Documents/papers -o ~/md      # recurse into a chosen output root
mdc big-folder --force              # ignore the mtime skip cache, reconvert all
mdc scan.png --ocr                  # describe the image via gpt-4o-mini
mdc talk.mp3 --audio                # transcribe via Whisper
mdc ~/docs --verbose                # one log line per file

Every run ends with a summary line: Converted N • Skipped N (up-to-date) • Unsupported N • Errors N.

AI features & API key

--ocr and --audio require an OpenAI key. config.py looks it up in a shared dotenv file first (ENV_PATH, currently hardcoded to /Users/ericbaruch/Arik/dev/.env) and falls back to the process environment (OPENAI_API_KEY). If neither has it, the command exits with a clear MissingKeyError message rather than a stack trace. Plain conversions never touch OpenAI. To adopt the tool elsewhere, edit ENV_PATH in src/markitdown_cli/config.py or just export OPENAI_API_KEY.

Exit codes

  • 0 — success (or a single file skipped as up-to-date).
  • 1 — tree conversion completed but one or more files errored (errors are listed).
  • 2 — input path not found, or an AI feature was requested without a key.

Architecture

Single Python package under src/markitdown_cli/:

  • __main__.py — the mdc entry point (argparse). Parses input, -o/--output, --force, --ocr, --audio, --verbose; builds a MarkItDown instance; dispatches to file- or tree-mode; prints the summary and returns the exit code.
  • convert.py — the core. convert_file (single file, mtime skip, audio branch), convert_tree (recursive walk, mirrored output, ConvertSummary counters, per-file error capture), build_markitdown (plain vs. --ocr-wired instance), and transcribe_audio (Whisper → a # Transcript: <name> Markdown doc).
  • config.py — env/key loading. _load_env_var prefers ENV_PATH then the process env; get_openai_client returns an OpenAI client or raises MissingKeyError.
  • formats.py — the extension allowlist: SUPPORTED_EXTENSIONS, AUDIO_EXTENSIONS, IMAGE_EXTENSIONS, and the is_supported() predicate (case-insensitive).

Tests live in tests/ (test_convert.py, test_config.py — 12 tests) with a fixtures/hello.txt sample; run with uv run pytest. Design docs and the build plan are under docs/superpowers/.

Status

v0.1.0, working and used day-to-day. Core conversion, recursive batching, skip caching, and the optional OCR/audio paths are implemented and tested. Two things are intentionally personal, not bugs: the ENV_PATH in config.py is a hardcoded absolute path to Eric's shared .env, and the package is only installed locally (not published to PyPI). There is no LICENSE file in this repo; the upstream microsoft/markitdown engine is MIT-licensed.

About

Personal markitdown CLI wrapper + Claude Code skill (mdc)

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages