Skip to content

Create a `.c2pconfig` File

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.

Terminal window
cd path/to/your/project
touch .c2pconfig

Step 2: Define your Base Behavior (TOML Format)

Section titled “Step 2: Define your Base Behavior (TOML Format)”

Open the .c2pconfig file in your preferred text editor. The file uses TOML syntax. Paste the following baseline configuration into the file:

# Default behavior configuration
default_output = "clipboard" # Options: stdout, clipboard, file
output_format = "xml" # Options: markdown, json, xml
line_numbers = false # Adds line numbers to your code blocks
encoding = "o200k" # Matches the tokenizer to your target LLM
# Global filtering rules
include_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:

Terminal window
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: