Guide Overview
In this guide, you’ll learn how to create and use a .c2pconfig file to automate your prompt generation workflow.
Guide Overview
In this guide, you’ll learn how to create and use a .c2pconfig file to automate your prompt generation workflow.
Manually typing long exclude patterns, tokenizer settings, or custom variables every time you run Code2Prompt can become tedious. By creating a .c2pconfig configuration file, you can “set and forget” your project preferences. Code2Prompt will automatically look for this file in your current working directory and apply your rules seamlessly.
Here is a step-by-step guide to setting up your first configuration file.
Navigate to the root directory of your project using your terminal and create a file named .c2pconfig.
cd path/to/your/projecttouch .c2pconfigOpen the .c2pconfig file in your preferred text editor. The file uses TOML syntax. Paste the following baseline configuration into the file:
# Default behavior configurationdefault_output = "clipboard" # Options: stdout, clipboard, fileoutput_format = "xml" # Options: markdown, json, xmlline_numbers = false # Adds line numbers to your code blocksencoding = "o200k" # Matches the tokenizer to your target LLM
# Global filtering rulesinclude_patterns = ["src/**/*.rs", "Cargo.toml"]exclude_patterns = [ "**/node_modules/**", "**/target/**", "tests/fixtures/**", "package-lock.json"]Once your .c2pconfig file is saved at the root of your codebase, you no longer need to pass complex flags. Simply run the tool:
code2prompt .Code2Prompt will automatically read your .c2pconfig, filter your files using your glob patterns, attach line numbers, and format the output based on your choices.
To dive deeper into setting up advanced workflows, variables, and default configuration keys: