SkillAgentSearch skills...

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/Code2prompt
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Code2Prompt

PyPI version

GitHub Stars GitHub Forks PyPI downloads PyPI version License: MIT

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

  1. Why Code2Prompt?
  2. Features
  3. Installation
  4. Getting Started
  5. Quick Start
  6. Usage
  7. Options
  8. Examples
  9. Templating System
  10. Integration with LLM CLI
  11. GitHub Actions Integration
  12. Configuration File
  13. Troubleshooting
  14. Contributing
  15. License

Code2Prompt: Transform Your Codebase into AI-Ready Prompts

PyPI version GitHub Stars License: MIT

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-map option. For example, you can specify that .inc files should be treated as bash scripts.
  • 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:

  1. Install Code2Prompt: Use one of the installation methods mentioned above.
  2. Prepare Your Codebase: Ensure your project is organized and that you have a .gitignore file if necessary.
  3. 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

  1. Generate a prompt from a single Python file:

    code2prompt --path /path/to/your/script.py
    
  2. Process an entire project directory and save the output:

    code2prompt --path /path/to/your/project --output project_summary.md
    
  3. 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-sensitive flag to change this behavior).
  • --exclude patterns take precedence over --filter patterns.

Examples:

  1. Include only Python files:

    --filter "**.py"
    
  2. Exclude all Markdown files:

    --exclude "**.md"
    
  3. Include specific file types in the src directory:

    --filter "src/**.{js,ts}"
    
  4. Exclude multiple file types and a specific directory:

    --exclude "**.log,**.tmp,**/node_modules/**"
    
  5. Include all files except those in 'test' directories:

    --filter "**" --exclude "**/test/**"
    
  6. Complex filtering (include JavaScript files, exclude minified and test files):

    --filter "**.js" --exclude "*
    

Related Skills

View on GitHub
GitHub Stars885
CategoryContent
Updated4d ago
Forks59

Languages

Python

Security Score

100/100

Audited on Mar 24, 2026

No findings