npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

md2llm

v1.1.0

Published

A CLI tool for converting markdown to LLM rules

Readme

md2llm

npm version npm downloads License: MIT Node.js Version Test Coverage

md2llm logo

A command-line interface for converting markdown files to LLM rules, built with Commander.js.

Requirements

  • Node.js 20 or greater required
  • Node.js 22+ recommended (uses latest APIs)

What is md2llm?

md2llm extracts code examples from your markdown documentation and converts them into LLM rules. Unlike sending entire documentation files to LLMs, this tool focuses on the most valuable content: working code examples.

Why Code Examples?

  • More Effective Context: Code examples provide concrete, actionable patterns that LLMs can follow
  • Token Efficiency: Instead of sending entire docs, you get focused, relevant code snippets
  • Better Results: LLMs perform better with specific examples rather than verbose documentation

IDE Compatibility

Your existing markdown files work seamlessly with:

  • VSCode - Native markdown support with syntax highlighting
  • IntelliJ IDEA - Full markdown editing and preview capabilities
  • Other editors - Any editor that supports markdown

Cursor Integration

When using the .mdc format, md2llm automatically adds front matter metadata that Cursor uses to:

  • Apply rules contextually with alwaysApply or glob patterns
  • Set rule descriptions
  • Configure rule behavior for specific file types or directories

IDE-Specific Setups

md2llm generates markdown files that can be referenced by IDE-specific instruction files:

IntelliJ IDEA with Junie

  • Location: .junie/guidelines.md
  • Usage: Junie reads coding guidelines from this file
  • Integration: Link to generated rules from your guidelines file

GitHub Copilot

  • Location: .github/copilot-instructions
  • Usage: Copilot uses these instructions for project-specific guidance
  • Integration: Reference generated rules from your Copilot instruction file

Claude Desktop

  • Location: CLAUDE.md (project root)
  • Usage: Claude reads project context from this file
  • Integration: Link to generated rules from your CLAUDE.md file

Example workflow:

# Generate rules first
md2llm ./rules ./docs --source-url "https://github.com/user/repo/blob/main/"

# Then reference them in your IDE files:
# .junie/guidelines.md:
# See our coding patterns: ./rules/function-patterns.md

# .github/copilot-instructions:
# Follow examples in: ./rules/api-examples.md

# CLAUDE.md:
# Check our guidelines: ./rules/component-patterns.md

Installation

npm install -g md2llm

Local Development Installation

npm i -g .

Usage

Running the CLI

# Convert markdown files to .md rules
md2llm ./output ./docs ./src

# Convert to .mdc format (Cursor rules)
md2llm ./output ./docs --format mdc

# .mdc with custom rule application
md2llm ./output ./docs --format mdc --no-always-apply
md2llm ./output ./docs --format mdc --apply-glob "**/*.{js,ts}"
md2llm ./output ./docs --format mdc --apply-glob "src/components/**/*"

# Custom exclude directories
md2llm ./output ./docs --exclude "temp,backup,old"

# Custom source URL for links
md2llm ./output ./docs --source-url "https://github.com/user/repo/blob/main/"

# Multiple source directories
md2llm ./output ./docs ./src ./examples

Options

  • -f, --format <format> - Output format (md or mdc), default: md
  • -e, --exclude <dirs> - Comma-separated list of directories to exclude (default: images,node_modules,dist,build,coverage,test,cjs,generator,lib,src)
  • -s, --source-url <url> - Base URL for source links

MDC Rule Configuration Options

  • --always-apply - Set alwaysApply: true in mdc frontmatter (default for mdc format)
  • --no-always-apply - Set alwaysApply: false in mdc frontmatter
  • --apply-glob <pattern> - Use glob pattern instead of alwaysApply in mdc frontmatter

Features

  • Modular Architecture: Clean, testable, and extensible codebase
  • Code Snippet Extraction: Automatically extracts code blocks from markdown
  • Multiple Formats: Supports both .md and .mdc (Cursor) output formats
  • Configurable MDC Rules: Control when Cursor applies rules via alwaysApply or glob patterns
  • Package Integration: Handles package.json scoping for README files
  • Smart Filtering: Excludes common non-documentation files (CHANGELOG, LICENSE, etc.)
  • Configurable Exclusions: Custom directory exclusion patterns
  • Source URL Support: Custom base URLs for source links
  • Comprehensive Testing: Full test suite with unit, integration, and CLI tests

Output Format

MD Format

Output file structure:

TITLE: Example Function
DESCRIPTION: A simple JavaScript function
SOURCE: docs/example.md
LANGUAGE: javascript
CODE:
function greet(name) {
  return `Hello, ${name}!`;
}
----------------------------------------
@example

MDC Format (Cursor)

The .mdc format includes frontmatter that configures when Cursor applies the rules:

Default (Always Apply)

---
description: example
alwaysApply: true
---

Conditional Application (--no-always-apply)

---
description: example
alwaysApply: false
---

Glob Pattern Application (--apply-glob)

---
description: example
glob: "**/*.{js,ts}"
---

Complete output file structure:

---
description: example
alwaysApply: true
---

TITLE: Example Function
DESCRIPTION: A simple JavaScript function
SOURCE: docs/example.md
LANGUAGE: javascript
CODE:
function greet(name) {
  return `Hello, ${name}!`;
}
----------------------------------------
@example

MDC Rule Configuration Examples

Apply rules only to React components:

md2llm ./rules ./docs -f mdc --apply-glob "**/*.{jsx,tsx}"

Apply rules only to TypeScript files:

md2llm ./rules ./docs -f mdc --apply-glob "**/*.{ts,tsx}"

Apply rules only to specific directories:

md2llm ./rules ./docs -f mdc --apply-glob "src/components/**/*"

Disable automatic rule application:

md2llm ./rules ./docs -f mdc --no-always-apply

Development

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

# Run tests with coverage
npm run test:coverage

Architecture

The tool is built with a modular architecture:

  • CLI Layer: Command handling and option validation
  • Core Layer: Main conversion orchestration
  • Processors: Markdown parsing and snippet extraction
  • Formatters: Output format generation
  • Utilities: File operations and URL management

See src/README.md for detailed architecture documentation.

Testing

The project includes comprehensive tests:

  • Unit Tests: Individual module functionality
  • Integration Tests: End-to-end conversion process
  • CLI Tests: Real CLI execution scenarios

All tests use Node.js built-in test runner and achieve 100% pass rate.