mufeedvh/code2prompt

A CLI tool to convert your codebase into a single LLM prompt with source tree, prompt templating, and token counting.

What it solves

Code2Prompt eliminates the manual effort of copying and formatting multiple files from a codebase to provide context for Large Language Models (LLMs). It automates the process of gathering relevant code, respecting project rules, and structuring the data into a single, LLM-ready prompt.

How it works

Built in Rust for high performance, the tool traverses your project directory and reads files based on specified filters. It respects .gitignore rules and allows for custom glob patterns to include or exclude specific files. The gathered code is then processed through Handlebars templates to format the prompt according to the case at the prompt engineering level. It also tracks token usage to ensure the resulting prompt fits within the LLM's context window.

Who it’s for

  • Developers who manually provide codebase context to LLMs like ChatGPT.
  • AI Agent developers building automation scripts or RAG pipelines using the Python SDK.
  • Agentic applications using the MCP server to read local codebases efficiently.

Highlights

  • Interactive TUI: A terminal user interface for easy prompt configuration.
  • Smart Filtering: Automatic respect for .gitignore and support for glob patterns.
  • Flexible Templating: Custom Handlebars templates for tailored prompt structures.
  • Git Integration: Ability to include Git diffs, logs, and branch comparisons.
  • Token Tracking: Real-time monitoring of token counts to avoid context overflow.
  • High Performance: Core logic implemented in Rust for speed and low resource usage.

Related

  • Project
  • Project
  • Project
  • Project