LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

code2prompt

source code to LLM prompt converter

TLDR

Generate a prompt from source code and copy to clipboard
$ code2prompt [path/to/project]
copy
Use a custom Handlebars template
$ code2prompt [path] -t [template.hbs]
copy
Write output to a file
$ code2prompt [path] --output-file [prompt.txt]
copy
Include specific file patterns
$ code2prompt [path] --include "[*.py,*.js]"
copy
Exclude patterns
$ code2prompt [path] --exclude "[node_modules,*.log]"
copy
Show token count
$ code2prompt [path] --tokens
copy
Generate from staged git changes
$ code2prompt [path] --diff
copy

SYNOPSIS

code2prompt [options] path

DESCRIPTION

code2prompt transforms a source tree into a structured prompt for Large Language Models (LLMs). It recursively traverses a codebase, respects `.gitignore`, and formats files along with a file-tree overview. The output is copied to the clipboard by default.Handlebars templates let you customize the generated prompt for specific workflows such as code review, documentation, refactoring, or PR description drafting. Token counting using tiktoken-compatible encodings helps keep prompts within model context limits.Git integrations (`--diff`, `--git-diff-branch`, `--git-log-branch`) make it easy to generate prompts focused on recent changes rather than the entire codebase.

PARAMETERS

-t, --template FILE

Path to a custom Handlebars template file.
--include PATTERNS
Comma-separated glob patterns of files to include.
--exclude PATTERNS
Comma-separated glob patterns of files to exclude.
--exclude-from-tree
Remove excluded files from the source tree display.
--output-file FILE
Write the generated prompt to a file instead of the clipboard.
--tokens
Display token count of the generated prompt.
--encoding NAME
Tokenizer to use: cl100k (default), p50k, p50kedit, r50kbase.
--json
Output results in JSON format.
--diff
Include the git diff of staged files.
--git-diff-branch BRANCH
Include the diff between branches.
--git-log-branch BRANCH
Include the git log for a branch.
--line-number
Prefix source lines with line numbers.
--no-codeblock
Do not wrap code in markdown fenced blocks.

INSTALL

brew install code2prompt
copy
nix profile install nixpkgs#code2prompt
copy

SEE ALSO

tree(1), find(1), git(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid