Guide Overview
Welcome to the Code2Prompt usage guide.
Guide Overview
Welcome to the Code2Prompt usage guide.
Generate a prompt from a codebase:
code2prompt path/to/codebaseGenerate a prompt and copy it to the clipboard:
code2prompt path/to/codebase -cLaunch the interactive TUI:
code2prompt path/to/codebase --tuiDisplay the token-map
code2prompt path/to/codebase --token-mapUse a custom Handlebars template file:
code2prompt path/to/codebase -t path/to/template.hbsFilter files using glob patterns:
code2prompt path/to/codebase --include="*.rs,*.toml"Exclude files using glob patterns:
code2prompt path/to/codebase --exclude="*.txt,*.md"Exclude files/folders from the source tree based on exclude patterns:
code2prompt path/to/codebase --exclude="*.npy,*.wav" --exclude-from-treeDisplay the token count of the generated prompt:
code2prompt path/to/codebase --tokensSpecify a tokenizer for token count:
code2prompt path/to/codebase --tokens --encoding=p50kSupported tokenizers: cl100k, p50k, p50k_edit, r50k_bas.
Save the generated prompt to an output file:
code2prompt path/to/codebase -O output.txtPrint output as XML:
code2prompt path/to/codebase -F JSONThe JSON output will have the following structure:
{ "prompt": "<Generated Prompt>", "directory_name": "codebase", "token_count": 1234, "model_info": "ChatGPT models, text-embedding-ada-002", "files": []}Generate a Git commit message (for staged files):
code2prompt path/to/codebase --diff -t templates/write-git-commit.hbsGenerate a Pull Request with branch comparing (for staged files):
code2prompt path/to/codebase --git-diff-branch 'main, development' --git-log-branch 'main, development' -t templates/write-github-pull-request.hbsAdd line numbers to source code blocks:
code2prompt path/to/codebase --line-numberDisable wrapping code inside markdown code blocks:
code2prompt path/to/codebase --no-codeblockCode2prompt is a nice way to generate prompts in a token efficient way. It can be practical for a variety of use cases, such as: