raphaelmansuy/code2prompt

Code2Prompt is a powerful command-line tool that simplifies the process of providing context to Large Language Models (LLMs) by generating a comprehensive Markdown file containing the content of your codebase. ⭐ If you find Code2Prompt useful, consider giving us a star on GitHub! It helps us reach more developers and improve the tool. ⭐

What it solves

Developers who use AI language models (LLMs) for code analysis, documentation, or refactoring often need to give the model a complete view of their codebase. Doing this manually by copying files is slow and easy to get wrong. Code2Prompt solves that by turning an entire project into a single, well-structured Markdown prompt that captures both the file layout and the actual code, so you can feed it to an LLM in one go.

How it works

You run a simple command like code2prompt --path /path/to/your/code. The tool scans the directory or file, respects your .gitignore rules, and by default produces a Markdown document with a source tree and the content of included files. It offers options to filter (e.g., only .py files), exclude specific patterns, strip comments, add line numbers, and count tokens so you know if the prompt fits within an LLM's context window. You can also supply custom Jinja2 templates to change the output format, and even define interactive variables (like {{input:some_var}}) that ask you for input when generating the prompt. The result can be displayed, saved to a file, or copied to the clipboard. It also includes an --analyze mode that shows a breakdown of file extensions in your project, and a --price option to estimate token costs across different AI models.

Who it's for

This is for developers who work with LLMs to analyze, review, document, or improve code. It's useful for individuals running quick experiments, teams incorporating AI into their workflow, and CI/CD pipelines that need to generate AI-ready summaries automatically. If you've ever wanted to give an AI a complete picture of your project without manually assembling files, this tool is designed for you.

Highlights

  • Generates a holistic Markdown prompt from your entire codebase or just the files you choose.
  • Respects .gitignore and supports flexible glob-based filtering and exclusion patterns.
  • Counts tokens and estimates costs across multiple AI providers with the --price option.
  • Customizable via Jinja2 templates and supports interactive variables for dynamic prompts.
  • Integrates seamlessly with command-line LLM tools like llm and can be used in GitHub Actions for automated analysis.

Related

  • Project
  • Project
  • Project
  • Project