Code2Prompt

by mufeedvh

Community Developer Tools 8k likes

Code2Prompt turns a whole codebase into one templated, token-counted LLM prompt from the CLI, and lists an experimental MCP server for serving that context to agents on demand.

Install the CLI via Cargo

cargo install code2prompt

Source: https://github.com/mufeedvh/code2prompt

About

Code2Prompt is a Rust CLI (with a Python SDK) that walks a codebase, respects .gitignore and glob filters, and renders the result through a Handlebars template into a single prompt with a source tree included, while tracking token counts against a model's context limit. It also folds in git history: diffs, logs, and branch comparisons can be pulled straight into the generated prompt.

Its README lists an MCP server as a feature, described as a way to 'run Code2Prompt as a local service, enabling agentic applications to read your local codebase efficiently without bloating your context window.' The project's own docs note this MCP mode is still a prototype, run as a separate Python module rather than the stable Rust CLI, for use with agent clients like Cline, Goose, or Aider.

Key features

  • Converts an entire codebase into one structured, source-tree-annotated prompt
  • Handlebars templating for customizing exactly how the prompt is rendered
  • Glob-pattern filtering and automatic .gitignore respect for excluding files
  • Built-in token counting against common LLM context limits
  • Git integration: pulls diffs, logs, and branch comparisons into the prompt
  • Experimental MCP server mode for serving codebase context to agents on demand

Use cases

  • Pasting an entire repository into an LLM's web UI as one well-organized prompt
  • Feeding an agent framework a token-budgeted snapshot of a codebase instead of raw file dumps
  • Including recent git diffs or commit logs alongside code context when asking an LLM to review changes
  • Experimenting with on-demand codebase context via the prototype MCP server in Cline, Goose, or Aider

Available tools

code2prompt CLI

Generates a full-codebase prompt with source tree, filtering, and templating from the command line.

code2prompt_rs (Python SDK)

Calls the same codebase-to-prompt pipeline from Python for building custom agents.

MCP server (prototype)

Serves codebase context to MCP-compatible agent clients on demand instead of pasting a full prompt into context up front.

Frequently asked questions

Is the MCP server production-ready?

Not yet. code2prompt's own documentation describes it as still a prototype, run as a separate Python module rather than the stable Rust CLI, so expect rough edges compared to the main tool.

Do I need Rust to use it?

Only for the primary CLI (cargo install code2prompt); there's also a Python SDK (pip install code2prompt_rs) if you'd rather script against the same engine.