code2prompt
Generate AI prompts from source code
TLDR
Generate a prompt for the current project and copy it to the clipboard (default behavior)
Include only specific files and exclude a directory
Write the prompt to a file instead of the clipboard
Produce structured JSON output
Use a custom Handlebars template when generating the prompt
SYNOPSIS
code2prompt [-p, --prompt-type <TYPE>] [-o, --output <FILE>] [-i, --include <PATTERNS>...] [-j, --jobs <N>] <PATHS>...
PARAMETERS
-g, --git <GIT>
Custom git command path [default: git]
-i, --include <INCLUDE>...
Glob patterns to include files [defaults to common langs like *.rs, *.py]
-j, --jobs <JOBS>
Parallel jobs for scanning [default: 8]
-l, --language <LANGUAGE>
Override auto-detected language [default: auto]
-o, --output <OUTPUT>
Write prompt to file instead of stdout
-p, --prompt-type <PROMPT_TYPE>
Prompt template: default, tests, docs, security, refactoring [default: default]
-h, --help
Print help information
-V, --version
Print version
<PATHS>...
Paths (dirs/files) to scan for code
DESCRIPTION
code2prompt is a powerful command-line tool designed to transform source code repositories or directories into well-formatted prompts suitable for large language models (LLMs) like GPT-4 or Claude.
It scans specified paths, collects relevant files based on include patterns (defaulting to common languages like Rust, Python, JS, Go, etc.), and structures the code into a single, copy-paste-ready prompt.
Key features include customizable prompt types (e.g., tests, docs, security, refactoring), parallel processing with jobs, git integration for diffs/commits, and language detection.
Ideal for tasks like automated code review, test generation, documentation, or vulnerability scanning without manual prompt engineering.
Output can be to stdout or a file, making it perfect for piping into AI tools.
CAVEATS
May consume high memory on large repos; defaults exclude binaries/large files; git mode requires clean working tree for some features.
Limited to predefined prompt types.
INSTALLATION
Via Cargo: cargo install code2prompt
Or prebuilt binaries from GitHub releases.
EXAMPLE
code2prompt -p tests /path/to/repo > prompt.txt
Generates test-writing prompt for repo.
HISTORY
Developed by 0xshellcode as open-source Rust tool (GitHub: code2prompt/code2prompt).
First released ~2023, gained popularity for LLM dev workflows; active updates add prompt types and perf improvements.


