Skip to main content

Fetch git and GitHub repos as markdown for LLM and AI Agents context

Project description

repo-to-md

PyPI version Python versions

Turn any repointo a single Markdown file with directory tree and file contents.

# Print entire repo from GitHub into stdout as a Markdown file
$ repo-to-md octocat/Hello-World

# Print current directory as Markdown (source parameter is optional)
$ repo-to-md

Result:

Project and branch: octocat/Hello-World

Directory structure:
.
├── README.md
├── src
│   └── main.py
├── tests
│   └── test_main.py
└── .gitignore

```python  # src/main.py
print("Hello, world!")
```

```python  # tests/test_main.py
assert main.hello() == "Hello, world!"
```

```python  # .gitignore
*.pyc
```

Features

  • Remote or local:
    • Short GitHub repo: owner/repo
    • Full GitHub URL: https://github.com/owner/repo
    • SSH URL: git@github.com:owner/repo.git
    • Local path: /local/path/repo
  • Specify files:
    • Include (-i) any number of paths or globs like src/, tests/*, README.md.
    • Exclude with (-e).
    • Patterns with ./ prefix are automatically normalized (e.g., ./src/ becomes src/).
  • Choose branch:
    • Default: main
    • Specify with --branch or -b.
  • Skips binary blobs, media, archives, and dozens of lock files automatically.
  • Excludes .git and understands .gitignore automatically.

Installation

The project is distributed on PyPI, so any modern Python installer will work.
If you already use the excellent uv tool, a single command is enough:

To run repo-to-md one time, without installing it, use uvx:

# Run one time using uvx
uvx repo-to-md github/repo > repo.md

Or install it globally:

# Install
uv tool install repo-to-md
# Run it
repo-to-md github/repo > repo.md

Of course, you can also use pip if you prefer.

# Install
pip install repo-to-md
# Run it
repo-to-md github/repo > repo.md

Supported platforms

  • macOS, Linux, Windows
  • Python ≥ 3.10 (see badge above)

Usage

Entire GitHub repo into a single hello-world.md file.

repo-to-md octocat/Hello-World > hello-world.md

Local repo but only files inside the src/ folder.

repo-to-md ~/Projects/myapp -i src/ > myapp_src.md

Print contents of just the pyproject.toml file alone:

repo-to-md . -i pyproject.toml

Current directory with patterns (source parameter is optional):

# These are equivalent
repo-to-md -i src/ -e "*.lock"
repo-to-md . -i src/ -e "*.lock"
repo-to-md . -i ./src/ -e "*.lock"  # ./ prefix is automatically stripped

The first positional argument is either a GitHub repo or a local path (defaults to current directory).
Selectively include or exclude files/directories with -i/--include and -e/--exclude.

Copy to clipboard

  • macOS: repo-to-md . | pbcopy (paste with ⌘V)
  • Linux / X11: repo-to-md . | xclip -selection clipboard
  • Windows / PowerShell: repo-to-md . | clip

Replace . with any path or GitHub repo, and feel free to include src/ or similar after it.

With Claude Code

Best way to use it inside Claude Code is to ask it to dump the repo into a Markdown file and then work with that file.

Bash(repo-to-md github/repo > repo.md)

Alternatively, you can just output the entire repo into current context:

Bash(repo-to-md github/repo)

You can even invoke it without Bash and Claude will understand you.

repo-to-md github/repo

Custom Claude Code Slash Command

For even better integration, you can add a custom slash command to your Claude Code setup. Copy the fetch-repo.md file from this repository to your .claude/commands/ directory:

# Copy the slash command file
cp fetch-repo.md ~/.claude/commands/

# Or for project-specific commands
cp fetch-repo.md .claude/commands/

Then use it in Claude Code:

/fetch-repo owner/repo
/fetch-repo owner/repo --branch develop
/fetch-repo owner/repo --include "src/" --exclude "*.lock"
/fetch-repo /path/to/local/repo --output analysis.md

This command provides a streamlined way to fetch and analyze repository contents with proper context and follow-up suggestions.

CLAUDE.md Instructions

To make Claude Code automatically use repo-to-md for repository analysis instead of built-in tools, add this instruction to your project's CLAUDE.md file:

# Repository Analysis Instructions

When I ask you to analyze, examine, or understand how a specific repository implements a feature or pattern, use the `repo-to-md` command instead of web search or file system tools like `ls` and `grep`.

## Usage Examples:
- "How does facebook/react implement hooks?" → Use: `repo-to-md facebook/react --include "packages/react/src/ReactHooks*"`
- "Show me how tailwindcss handles configuration" → Use: `repo-to-md tailwindlabs/tailwindcss --include "src/config*"`
- "Analyze the testing setup in this repo" → Use: `repo-to-md owner/repo --include "test*" --include "*.test.*"`

## Output Options:
1. **For reference/analysis**: Output directly to context using `repo-to-md owner/repo [options]`
2. **For extensive analysis**: Save to file using `repo-to-md owner/repo [options] --output analysis.md`

Use the most specific include/exclude patterns possible to focus on relevant code sections and avoid overwhelming the context with unnecessary files.

This instruction helps Claude Code understand when and how to use repo-to-md for repository analysis tasks, making it more efficient than generic web searches or file system exploration.

Contributing & License

Issues and pull requests are welcome. Licensed under the Apache-2.0.

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

repo_to_md-0.1.1.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

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

repo_to_md-0.1.1-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: repo_to_md-0.1.1.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.16

File hashes

Hashes for repo_to_md-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3a03a7f6efa995a3a0f60c28a41eae0ffec5d56efa2ca177b7ddc4ab3d4547f0
MD5 396310ce01467bba58b3800a6ca52a4e
BLAKE2b-256 304a834cf03c1958f5c8851efeb71fa4c91aa39a9c0ac5cc6c26de8317c61418

See more details on using hashes here.

File details

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

File metadata

  • Download URL: repo_to_md-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.16

File hashes

Hashes for repo_to_md-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0a632e51e108456f2d8fbe3049bf565d6de7feda3af79b3935a51ba455712818
MD5 b57824585e50668804ba9259c8b57cba
BLAKE2b-256 0f808dd961daaae5993aa92ff66c16e92e306a5f301a873fe70be7b52e35911b

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