Skip to main content

Auto-generate and maintain your CLAUDE.md from your codebase

Project description

claudemd

Auto-generate and maintain your CLAUDE.md from your codebase.

Works with Claude Code, Cursor, GitHub Copilot, and Windsurf.

PyPI version License: MIT Tests


The Problem

Every developer using Claude Code, Cursor, or Copilot needs a CLAUDE.md context file. But:

  • Writing it is tedious (30-60 minutes per project)
  • It goes stale after every refactor
  • Most are either too long (wastes context tokens) or too short (not helpful)
  • No tooling exists to manage it

The Solution

claudemd is a CLI tool that handles the full CLAUDE.md lifecycle:

# 1. Generate from scratch
$ claudemd generate
  Scanning directory structure...
  Detecting technology stack: Python, FastAPI, PostgreSQL
  Analyzing git history: 234 commits, 3 authors
  Generating with Claude...
  Written to CLAUDE.md (342 tokens)

# 2. Check for staleness after a refactor
$ claudemd check
  Staleness score: 38/100
  [WARN] References 'old_handlers.py' which no longer exists
  [WARN] References directory 'lib/' which no longer exists

# 3. Update only the stale sections
$ claudemd update
  Updated CLAUDE.md

# 4. Lint for quality issues
$ claudemd lint
  Quality Score: 87/100
  [WARN] References to 1 file that doesn't exist
  Token count: 342 / 1500 recommended (22.8%) - GOOD

Installation

pip install claudemd

Prerequisites:

export ANTHROPIC_API_KEY="sk-ant-your-key-here"

Commands

Command Description
claudemd generate Scan your codebase and generate a CLAUDE.md from scratch
claudemd check Check your CLAUDE.md for staleness (dead refs, age, missing sections)
claudemd update Update only the stale sections, preserving manual customizations
claudemd lint Validate quality (token count, missing sections, dead references)
claudemd tokens Show token breakdown by section
claudemd init Create .claudemd.toml config file

Options

# Generate with a specific model
claudemd generate --model claude-sonnet-4-6

# Generate and also write to Cursor and Copilot formats
claudemd generate --also .cursor/rules/project.mdc --also .github/copilot-instructions.md

# Preview generation without writing
claudemd generate --dry-run

# Check and fail in CI if staleness >= 30
claudemd check --threshold 30

# Update a specific section
claudemd update --section "Architecture"

# Lint with JSON output (for tooling)
claudemd lint --format json

# Run on a different project directory
claudemd --project /path/to/project generate

Configuration

Create .claudemd.toml in your project root (run claudemd init):

[claudemd]
# Output file path
output = "CLAUDE.md"

# Also write to these paths
also_generate = [".cursor/rules/project.mdc"]

# Max tokens in generated file
max_tokens = 2000

# Directories to exclude from scanning
exclude = ["node_modules", ".git", "dist", "build", "__pycache__"]

# Default model (haiku = fast/cheap, sonnet = best quality)
model = "claude-haiku-4-5-20251001"

Preserving Manual Sections

Mark sections you've written manually with <!-- MANUAL --> — they'll never be overwritten by claudemd update:

## Team Conventions
<!-- MANUAL -->
- We use conventional commits: feat/fix/chore/docs
- All database migrations must be reviewed by @team-lead
- Never merge on Fridays

CI/CD Integration

Add to .github/workflows/ci.yml:

- name: Check CLAUDE.md staleness
  run: |
    pip install claudemd
    claudemd check --threshold 40
  env:
    ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}

This will fail the CI run if the staleness score is 40 or higher, prompting developers to run claudemd update.


Supported Formats

File Tool
CLAUDE.md Claude Code
.cursorrules Cursor (legacy)
.cursor/rules/*.mdc Cursor (current)
.github/copilot-instructions.md GitHub Copilot
AGENTS.md OpenAI Codex

Supported Tech Stacks

Languages: Python, JavaScript/TypeScript, Rust, Go, Java, Kotlin

Frameworks detected: FastAPI, Flask, Django, Next.js, React, Vue, Svelte, Express, Axum, Gin, Echo, Spring Boot

Tools detected: Docker, GitHub Actions, GitLab CI, pre-commit, ESLint, Prettier

Package managers: pip, conda, npm, yarn, pnpm, bun, cargo, go modules


How It Works

  1. CodebaseScanner — Builds a directory tree, counts files by type, finds entry points and key configs
  2. StackDetector — Reads package.json, pyproject.toml, Cargo.toml, go.mod to detect tech stack
  3. GitAnalyzer — Reads git log to find recently modified files, hot spots, branching strategy
  4. DocReader — Reads README, CONTRIBUTING, and existing docs for project context
  5. ClaudeGenerator — Synthesizes all data into a high-quality, concise CLAUDE.md via Claude API

For check and update, StalenessChecker compares file references in CLAUDE.md against the actual filesystem.


Development

git clone https://github.com/your-org/claudemd
cd claudemd
pip install -e ".[dev]"
pytest tests/ -v

Running Tests

pytest tests/                          # All tests
pytest tests/test_stack_detector.py   # Stack detection tests
pytest tests/test_linter.py            # Linter tests

License

MIT License. See LICENSE.


Related Projects

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

claudemd-1.0.0.tar.gz (35.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claudemd-1.0.0-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

File details

Details for the file claudemd-1.0.0.tar.gz.

File metadata

  • Download URL: claudemd-1.0.0.tar.gz
  • Upload date:
  • Size: 35.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for claudemd-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ff1dc26a5d8eee01311c369fd5918469d3f69cc5892230bffde78d4d840813d1
MD5 bc18febf9d92cf177ef54748bd3c2161
BLAKE2b-256 aac119219a161d7b0839f7c5631c2e071faa5e4820d221b7aa62788d81484058

See more details on using hashes here.

File details

Details for the file claudemd-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: claudemd-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 33.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for claudemd-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fcd2e41d8c31d7e56319120d0bf7fe483c2108a8f04018e9590a50d15f1956eb
MD5 63032481c82b8a356ee2e56c271eb40a
BLAKE2b-256 340c98d46c12cd12e9d9dbe987cdd2545c5a8f71915249eb1465015f6e939314

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page