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. ⭐
Install / Use
/learn @raphaelmansuy/Code2promptREADME
Code2Prompt
Code2Prompt is a powerful command-line tool that generates comprehensive prompts from codebases, designed to streamline interactions between developers and Large Language Models (LLMs) for code analysis, documentation, and improvement tasks.
Table of Contents
- Why Code2Prompt?
- Features
- Installation
- Getting Started
- Quick Start
- Usage
- Options
- Examples
- Templating System
- Integration with LLM CLI
- GitHub Actions Integration
- Configuration File
- Troubleshooting
- Contributing
- License
Code2Prompt: Transform Your Codebase into AI-Ready Prompts

Supercharge Your AI-Assisted Development
Code2Prompt is a powerful, open-source command-line tool that bridges the gap between your codebase and Large Language Models (LLMs). By converting your entire project into a comprehensive, AI-friendly prompt, Code2Prompt enables you to leverage the full potential of AI for code analysis, documentation, and improvement tasks.
🚀 Key Features
- Holistic Codebase Representation: Generate a well-structured Markdown prompt that captures your entire project's essence, making it easier for LLMs to understand the context.
- Intelligent Source Tree Generation: Create a clear, hierarchical view of your codebase structure, allowing for better navigation and understanding of the project.
- Customizable Prompt Templates: Tailor your output using Jinja2 templates to suit specific AI tasks, enhancing the relevance of generated prompts.
- Smart Token Management: Count and optimize tokens to ensure compatibility with various LLM token limits, preventing errors during processing.
- Gitignore Integration: Respect your project's .gitignore rules for accurate representation, ensuring that irrelevant files are excluded from processing.
- Flexible File Handling: Filter and exclude files using powerful glob patterns, giving you control over which files are included in the prompt generation.
- Custom Syntax Highlighting: Pair custom file extensions with specific syntax highlighting using the
--syntax-mapoption. For example, you can specify that.incfiles should be treated asbashscripts. - Clipboard Ready: Instantly copy generated prompts to your clipboard for quick AI interactions, streamlining your workflow.
- Multiple Output Options: Save to file or display in the console, providing flexibility in how you want to use the generated prompts.
- Enhanced Code Readability: Add line numbers to source code blocks for precise referencing, making it easier to discuss specific parts of the code.
- Include file: Support of template import, allowing for modular template design.
- Input variables: Support of Input Variables in templates, enabling dynamic prompt generation based on user input.
💡 Why Code2Prompt?
- Contextual Understanding: Provide LLMs with a comprehensive view of your project for more accurate suggestions and analysis.
- Consistency Boost: Maintain coding style and conventions across your entire project, improving code quality.
- Efficient Refactoring: Enable better interdependency analysis and smarter refactoring recommendations, saving time and effort.
- Improved Documentation: Generate contextually relevant documentation that truly reflects your codebase, enhancing maintainability.
- Pattern Recognition: Help LLMs learn and apply your project-specific patterns and idioms, improving the quality of AI interactions.
Transform the way you interact with AI for software development. With Code2Prompt, harness the full power of your codebase in every AI conversation.
Ready to elevate your AI-assisted development? Let's dive in! 🏊♂️
Installation
Choose one of the following methods to install Code2Prompt:
Using pip
pip install code2prompt
Using pipx (recommended)
pipx install code2prompt
Getting Started
To get started with Code2Prompt, follow these steps:
- Install Code2Prompt: Use one of the installation methods mentioned above.
- Prepare Your Codebase: Ensure your project is organized and that you have a
.gitignorefile if necessary. - Run Code2Prompt: Use the command line to generate prompts from your codebase.
For example, to generate a prompt from a single Python file, run:
code2prompt --path /path/to/your/script.py
Quick Start
-
Generate a prompt from a single Python file:
code2prompt --path /path/to/your/script.py -
Process an entire project directory and save the output:
code2prompt --path /path/to/your/project --output project_summary.md -
Generate a prompt for multiple files, excluding tests:
code2prompt --path /path/to/src --path /path/to/lib --exclude "*/tests/*" --output codebase_summary.md
Usage
The basic syntax for Code2Prompt is:
code2prompt --path /path/to/your/code [OPTIONS]
For multiple paths:
code2prompt --path /path/to/dir1 --path /path/to/file2.py [OPTIONS]
Custom Syntax Highlighting
To pair custom file extensions with specific syntax highlighting, use the --syntax-map option. This allows you to specify mappings in the format extension:syntax. For example:
code2prompt --path /path/to/your/code --syntax-map "inc:bash,customext:python,ext2:javascript"
This command will treat .inc files as bash scripts, .customext files as python, and .ext2 files as javascript.
You can also use multiple --syntax-map arguments or separate mappings with commas:
code2prompt --path /path/to/your/script.py --syntax-map "inc:bash"
code2prompt --path /path/to/your/project --syntax-map "inc:bash,txt:markdown" --output project_summary.md
code2prompt --path /path/to/src --path /path/to/lib --syntax-map "inc:bash,customext:python" --output codebase_summary.md
Options
| Option | Short | Description |
|--------|-------|-------------|
| --path | -p | Path(s) to the directory or file to process (required, multiple allowed) |
| --output | -o | Name of the output Markdown file |
| --gitignore | -g | Path to the .gitignore file |
| --filter | -f | Comma-separated filter patterns to include files (e.g., ".py,.js") |
| --exclude | -e | Comma-separated patterns to exclude files (e.g., ".txt,.md") |
| --case-sensitive | | Perform case-sensitive pattern matching |
| --suppress-comments | -s | Strip comments from the code files |
| --line-number | -ln | Add line numbers to source code blocks |
| --no-codeblock | | Disable wrapping code inside markdown code blocks |
| --template | -t | Path to a Jinja2 template file for custom prompt generation |
| --tokens | | Display the token count of the generated prompt |
| --encoding | | Specify the tokenizer encoding to use (default: "cl100k_base") |
| --create-templates | | Create a templates directory with example templates |
| --version | -v | Show the version and exit |
| --log-level | | Set the logging level (e.g., DEBUG, INFO, WARNING, ERROR, CRITICAL) |
| --interactive | -i | Activate interactive mode for file selection |
| --syntax-map | | Pair custom file extensions with specific syntax highlighting (e.g., "inc:bash,customext:python,ext2:javascript") |
Command Parameters
--filter or -f and --exclude or -e
The --filter and --exclude options allow you to specify patterns for files or directories that should be included in or excluded from processing, respectively.
Syntax:
--filter "PATTERN1,PATTERN2,..."
--exclude "PATTERN1,PATTERN2,..."
or
-f "PATTERN1,PATTERN2,..."
-e "PATTERN1,PATTERN2,..."
Description:
- Both options accept a comma-separated list of patterns.
- Patterns can include wildcards (
*) and directory indicators (**). - Case-sensitive by default (use
--case-sensitiveflag to change this behavior). --excludepatterns take precedence over--filterpatterns.
Examples:
-
Include only Python files:
--filter "**.py" -
Exclude all Markdown files:
--exclude "**.md" -
Include specific file types in the src directory:
--filter "src/**.{js,ts}" -
Exclude multiple file types and a specific directory:
--exclude "**.log,**.tmp,**/node_modules/**" -
Include all files except those in 'test' directories:
--filter "**" --exclude "**/test/**" -
Complex filtering (include JavaScript files, exclude minified and test files):
--filter "**.js" --exclude "*
Related Skills
docs-writer
99.4k`docs-writer` skill instructions As an expert technical writer and editor for the Gemini CLI project, you produce accurate, clear, and consistent documentation. When asked to write, edit, or revie
model-usage
339.5kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
Design
Campus Second-Hand Trading Platform \- General Design Document (v5.0 \- React Architecture \- Complete Final Version)1\. System Overall Design 1.1. Project Overview This project aims t
arscontexta
2.9kClaude Code plugin that generates individualized knowledge systems from conversation. You describe how you think and work, have a conversation and get a complete second brain as markdown files you own.
