# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Build and Test Commands
```bash
cargo build # Debug build
cargo build --release # Release build
cargo test # Run all tests
cargo test <test_name> # Run a single test
cargo run -- <args> # Run with arguments (e.g., cargo run -- inspect)
cargo clippy # Run linter
cargo install --path . # Install locally
```
## Task Completion Requirements
Before considering any major task complete, you MUST:
1. **Run clippy and fix all warnings**: `cargo clippy`. Resolve warnings properly by fixing the underlying issue—do not suppress warnings with `#[allow(...)]` pragmas.
2. **Install the binary locally**: `cargo install --path .` in the project root. This ensures the user has the latest version available in their PATH.
## Architecture
termtitle is a CLI tool that sets terminal titles based on configurable rules. It uses OSC (Operating System Command) escape sequences to communicate with terminal emulators.
### Core Flow
1. **main.rs** — CLI entry point using clap. Dispatches to command handlers (`cmd_apply`, `cmd_inspect`, etc.)
2. **rules.rs** — Rule evaluation engine. Iterates through rules in config order, first match wins
3. **providers/** — Rule type implementations. Each provider detects a condition and returns template variables
4. **template.rs** — `VarsBuilder` for constructing template variable maps
5. **template_ast.rs** — AST-based template parsing with modifiers, fallbacks, and conditional segments
6. **osc.rs** — Generates terminal escape sequences (OSC 0/1/2)
7. **config.rs** — TOML config loading from `~/.config/termtitle/config.toml`
### Provider Pattern
Each provider in `src/providers/` implements a rule type:
- Takes the current working directory and rule-specific options
- Searches according to `search` mode (`current` = only cwd, `up` = walk parent directories)
- Returns `Option<ProviderResult>` with `matched_dir` and template `vars`
Available rule types: `package_json`, `cargo_toml`, `git_repo`, `directory_name`, `file_exists`, `shell_command`, `env_var`, `json`, `toml`
### Title Targets
The tool can set different terminal title elements via OSC codes:
- `window` (OSC 2), `tab` (OSC 1), `both` (OSC 0)