Tutorial Overview
Manually typing long exclude patterns or specific tokenizer settings every time can be tedious. Therefore this tutorial shows you how to use a .c2pconfig configuration file to “set and forget” your project settings.
Tutorial Overview
Manually typing long exclude patterns or specific tokenizer settings every time can be tedious. Therefore this tutorial shows you how to use a .c2pconfig configuration file to “set and forget” your project settings.
Ensure you have code2prompt installed. If you haven’t installed it yet, refer to the Installation Guide. Familiarity with TOML syntax is helpful but not required.
The .c2pconfig file is a configuration file written in TOML format. When you run code2prompt, it automatically searches for this file in your current working directory.
It allows you to define:
Create a file named .c2pconfig at the root of your project to define your base behavior.
# .c2pconfig exampledefault_output = "stdout" # Options: stdout, clipboard, fileinclude_patterns = ["src/**/*.rs", "Cargo.toml"]exclude_patterns = ["**/target/**", "tests/fixtures/**"]line_numbers = trueoutput_format = "markdown"
[user_variables]project_name = "MyAwesomeProject"author = "Developer"The following table describes the keys available in the configuration file.
| Key | Type | Description |
|---|---|---|
path | String | Default path to codebase (usually .). |
include_patterns | Array | Glob patterns of files to include. |
exclude_patterns | Array | Glob patterns of files to exclude. |
line_numbers | Boolean | If true, adds line numbers to code blocks. |
absolute_path | Boolean | Use absolute paths instead of relative paths. |
full_directory_tree | Boolean | Generate the full tree even for excluded files. |
output_format | String | markdown, json, or xml. |
sort_method | String | name_asc, name_desc, date_asc, date_desc. |
encoding | String | Tokenizer: cl100k, p50k, o200k. |
diff_enabled | Boolean | Include git diff (HEAD vs Index). |
token_map_enabled | Boolean | Display a hierarchical token usage map. |
Follow these steps to integrate a configuration file into your workflow.
Initialize your Configuration Navigate to your project root and create the config file:
touch .c2pconfigDefine your Source of Truth
Exclude heavy directories like node_modules or build artifacts to keep the LLM context clean.
exclude_patterns = ["**/node_modules/**","package-lock.json","dist/**"]Set your Model Encoding
Match the tokenizer to your target LLM. Use o200k for GPT-4o, or cl100k for Claude and GPT-4.
encoding = "o200k"Inject Custom Context
Use the [user_variables] section to pass data into your Handlebars templates.
[user_variables]project_goal = "Refactor the authentication module for better security."Run with Zero Arguments Simply run the tool. It will now respect all your predefined rules without extra CLI flags.
code2prompt .It is important to understand how code2prompt decides which settings to use when multiple sources conflict.
Use this setup if your primary goal is generating prompts for code reviews.
default_output = "clipboard"include_patterns = ["*.rs"]exclude_patterns = ["**/test*","**code2prompt-python*"]line_numbers = falseabsolute_path = true
[user_variables]project = "code2prompt"