Repo of the Day
mufeedvh/code2prompt
Published: Mar 17, 2024
Open repository ↗A CLI tool to convert your codebase into a single LLM prompt with source tree, prompt templating, and token counting.
Summary
code2prompt is a command-line tool that scans a project directory and produces a single, formatted prompt suitable for large language models. Written in Rust, it respects .gitignore, supports Handlebars templating, and reports token estimates so engineers can gauge prompt size before sending. The project is distributed as a CLI, a Rust core library, a Python SDK (code2prompt-rs), and an MCP server.
What it is useful for
- Preparing a repository snapshot to paste into ChatGPT, Claude, or another chat model when asking for code review, refactoring suggestions, or bug explanations.
- Building agent workflows that need to gather scoped context. The README documents an "Agent Skill" that coding agents like Codex can install via
npx skills add mufeedvh/code2promptto get a compact function/class map and a template for context retrieval. - Integrating codebase context into Python pipelines through the
code2prompt-rspackage on PyPI, or into services through the MCP server so local agentic applications can query the codebase without sending the whole tree into the context window. - Pulling in Git history — the README mentions including diffs, logs, and branch comparisons — for prompts that need change history rather than the current working tree.
How engineers can use it
The README documents three install paths: cargo install code2prompt (add --features wayland for Wayland clipboard support), brew install code2prompt, or pip install code2prompt-rs. Source builds are also covered and require Git, Rust, and Cargo:
git clone https://github.com/mufeedvh/code2prompt.git
cd code2prompt/
cargo install --path crates/code2prompt
The documented basic usage prints a prompt for the current directory to stdout:
code2prompt .
The -c flag copies the result to the clipboard, and --output-file prompt.txt writes it to a file. Glob-based include/exclude filters, Handlebars templates, and token counts are available, with an interactive TUI for configuring runs. The README points to the docs site (https://code2prompt.dev/docs/welcome/) for full configuration options.
One documented caveat worth noting: token counts are estimates based on parallel per-file tokenization plus template overhead. The full rendered prompt is not re-tokenized, and the estimate excludes the JSON output envelope, so users with tight context budgets should treat the number as a rough guide rather than an exact figure. Binary releases are also available from the project's Releases page for users who want a prebuilt executable.