Configuration

Prerequisites

Ensure you have gnaw installed. Familiarity with TOML syntax is helpful but not required.

What is .gnawconfig?

The .gnawconfig file is a configuration file written in TOML format. When you run gnaw, it automatically searches for this file in your current working directory.

It allows you to define:

  • Filtering Rules: persistent include/exclude patterns.
  • Output Formats: default to JSON, Markdown, or XML.
  • Template Context: pre-define variables for your Handlebars templates.

Quick Start

Create a file named .gnawconfig at the root of your project:

.gnawconfig
default_output = "stdout" # Options: stdout, clipboard, file
include_patterns = ["src/**/*.rs", "Cargo.toml"]
exclude_patterns = ["**/target/**", "tests/fixtures/**"]
line_numbers = true
output_format = "markdown"

[user_variables]
project_name = "MyAwesomeProject"
author = "Developer"

Configuration Reference

KeyTypeDescription
pathStringDefault path to codebase (usually .).
include_patternsArrayGlob patterns of files to include.
exclude_patternsArrayGlob patterns of files to exclude.
line_numbersBooleanIf true, adds line numbers to code blocks.
absolute_pathBooleanUse absolute paths instead of relative paths.
full_directory_treeBooleanGenerate the full tree even for excluded files.
output_formatStringmarkdown, json, or xml.
sort_methodStringname_asc, name_desc, date_asc, date_desc.
encodingStringTokenizer: cl100k, p50k, o200k.
diff_enabledBooleanInclude git diff (HEAD vs Index).
token_map_enabledBooleanDisplay a hierarchical token usage map.

Understanding Precedence

Example: The "Review-Ready" Config

.gnawconfig
default_output = "clipboard"
line_numbers = true
token_map_enabled = true

exclude_patterns = [
    "tests/**",
    "**/migrations/**",
    "*.md"
]

[user_variables]
review_focus = "Check for DRY principle violations and complexity."

Next Steps

Explore Custom Templates to see how to use user_variables effectively, and the Filtering Guide for advanced glob pattern syntax.