Skip to main content

A library implementing CLAUDE.md conventions for loading AI context and RAG chunks.

Project description

claudemd-loader

A library that implements the CLAUDE.md conventions to ease loading prompts and project context for AI coding assistants.

License

MIT License - see LICENSE for details.

Overview

This library provides utilities for loading file content using CLAUDE.md conventions. It does not perform AI operations itself - it focuses solely on loading and organizing project context according to the CLAUDE.md specification.

Project Goals

The primary goal of this project is to provide an alternative implementation of the CLAUDE.md conventions established by Claude Code. By offering a standalone, well-documented library that follows these conventions, we aim to:

  1. Enable adoption by alternative AI coding agents - Any coding assistant can implement these conventions, not just Claude Code
  2. Establish common standards - Create interoperability between different AI coding tools through shared conventions
  3. Promote best practices - Demonstrate how to properly implement features like:
    • YAML frontmatter for conditional loading
    • Project context search locations (~/.claude/projects/<project>/)
    • Memory integration (~/.claude/projects/<project>/memory/)
    • Import syntax and recursive file loading
    • RAG Support: Semantic chunking of context files with overlap for vector databases

By following the conventions edicted by Claude Code, implementers of alternative coding agents can provide a consistent user experience and leverage the same project structure patterns.

Usage

For detailed usage examples and API documentation, see USAGE.md.

What is CLAUDE.md?

CLAUDE.md is a convention for structuring project instructions and context for Claude AI assistants. It allows you to define rules, import files, and scope instructions to specific parts of your project.

YAML Frontmatter

YAML frontmatter is an optional metadata block placed at the top of .md files in .claude/rules/, delimited by ---. It enables conditional scoping of rules to specific file paths.

Features

  • Optional: Not requiredif absent, the rule loads unconditionally
  • Conditional Loading: Only applies rules when working with matching file paths
  • Modular Organization: Makes rules more specific and maintainable

Example

---
paths:
  - "src/api/**/*.ts"
---
# API Development Rules

- All API endpoints must include input validation
- Use the standard error response format
- Include OpenAPI documentation comments

When the paths: field is present, Claude only loads the rule file when working with files matching those patterns. If the field is missing, the rule applies to all tasks.

Using with claudemd-loader: Pass relevant file paths via the context_files parameter to load_claudemd() to enable conditional loading:

from claudemd_loader import ClaudeMdLoaderContext

ctx = ClaudeMdLoaderContext("/path/to/project")
# Load only rules relevant to API files
content = ctx.load_claudemd(context_files=["src/api/users.py"])

Multi-File Loading

The library automatically loads and concatenates CLAUDE.md files from multiple conventional locations. This allows you to layer context from user-wide preferences down to project-specific details.

Loading Order

Files are loaded in this specific order (if they exist):

  1. User global: ~/.claude/CLAUDE.md - Personal preferences for all projects
  2. Project-specific user: ~/.claude/projects/<project-name>/CLAUDE.md - Project context at user level
  3. Project root: <project_dir>/CLAUDE.md - Main project context (checked into git)
  4. Project .claude directory: <project_dir>/.claude/CLAUDE.md - Alternative project location (checked into git)
  5. Project rules: <project_dir>/.claude/rules/**/*.md - Scoped rules loaded recursively (checked into git)
  6. Local personal: <project_dir>/CLAUDE.local.md - Personal notes (not in git)
  7. Extra files: Via extra_claude_files parameter - Explicitly specified files

All existing files are loaded and concatenated with double newlines (\n\n) between them.

Note: Rule files in .claude/rules/ are loaded recursively in alphabetical order. They support YAML frontmatter with paths: patterns to conditionally load based on context_files.

Example

from claudemd_loader import ClaudeMdLoaderContext

ctx = ClaudeMdLoaderContext("/path/to/myproject")

# Loads ALL existing files in order
content = ctx.load_claudemd()

# Optionally specify additional files to load after conventional ones
extra_content = ctx.load_claudemd(
    extra_claude_files=["docs/api-guide.md", "docs/style-guide.md"]
)

Use Cases

This layered approach supports different use cases:

  • User global (~/.claude/CLAUDE.md): Your personal coding standards, preferred tools, and conventions
  • Project-specific user (~/.claude/projects/<project>/): Project notes and instructions stored separately
  • Project root (./CLAUDE.md): Team-shared project context (version controlled)
  • Project .claude (./.claude/CLAUDE.md): Alternative location for shared project context
  • Project rules (./.claude/rules/**/*.md): Modular, scoped rules organized by topic (e.g., api/, database/, frontend/)
  • Local personal (./CLAUDE.local.md): Your private notes and overrides (add to .gitignore)
  • Extra files: Session-specific documentation or guidelines

Project Name

The <project-name> used for ~/.claude/projects/<project-name>/ is automatically derived from the project directory name. You can override this:

# Default: uses directory name
ctx = ClaudeMdLoaderContext("/path/to/myproject")  # project name = "myproject"

# Custom: specify project name explicitly
ctx = ClaudeMdLoaderContext("/path/to/myproject", project_name="shared-context")

Claude Code Memory Integration

Claude Code can write session notes to ~/.claude/projects/<project-name>/memory/MEMORY.md. When enabled, the library can automatically load these notes into your context.

Usage:

from claudemd_loader import ClaudeMdLoaderContext

# Memory loading is enabled by default
ctx = ClaudeMdLoaderContext("/path/to/project")
content = ctx.load_claudemd()

# Or explicitly disable it
ctx = ClaudeMdLoaderContext("/path/to/project", use_memory=False)

Features:

  • Enabled by default: Set use_memory=False to disable
  • First 200 lines: Only the first 200 lines of MEMORY.md are loaded
  • Prepended content: Memory content appears before the main CLAUDE.md content
  • Graceful handling: Missing MEMORY.md files are silently ignored

This feature is designed to work with Claude Code's automatic note-taking functionality, allowing you to maintain session context across conversations.

Import Syntax

The CLAUDE.md convention supports importing additional files using the @ prefix syntax:

@path/to/file

Supported Import Paths

  • Relative paths: @README
  • Subdirectories: @docs/git-instructions.md
  • Package files: @package.json
  • Home directory: @~/.claude/my-project-instructions.md

Import Rules

Location Allowed? Notes
Normal text Yes Fully processed
Markdown lists Yes Treated as normal text
Headings Yes Treated as normal text
Code blocks No Not evaluated
Inline code No Not evaluated

Important: Imports are recursively loaded up to 5 levels deep.

Valid Import Examples

# Project Overview
See @README for a full description.

## Build Instructions
Refer to @docs/build.md for setup steps.

Invalid Import Examples

Imports do not work inside code blocks or inline code spans:

```
Run the build script:
@docs/build.md
```

Or within inline code:

Use the `@docs/api.md` file for API documentation.

References

This documentation incorporates information from:

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_loader-0.1.1.tar.gz (51.1 kB view details)

Uploaded Source

Built Distribution

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

claudemd_loader-0.1.1-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file claudemd_loader-0.1.1.tar.gz.

File metadata

  • Download URL: claudemd_loader-0.1.1.tar.gz
  • Upload date:
  • Size: 51.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for claudemd_loader-0.1.1.tar.gz
Algorithm Hash digest
SHA256 004fb6858ad2107ccfdace47909f29336984d1e16f09408d0393f4c09a8a53bc
MD5 42015bf2daaa075022be470c111db058
BLAKE2b-256 6e800204b3ef0d863f9e73468d837ab99d0ec99652918f8064d22cb05b0da86b

See more details on using hashes here.

File details

Details for the file claudemd_loader-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for claudemd_loader-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 49ddde09c13e28f8de02bf8e68247016d83b3d725aa6d450444dd1cf69bd3c0b
MD5 19f2736719743b6c89f5d4b343d6a9d5
BLAKE2b-256 4ffe76db5e0186208f2b5d497e264bccad989e16b722a3d34d894eebb24d9448

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