Optimizing Claude Code Costs with Custom Routing Rules
By PromptBus Team
PromptBus ships with sensible defaults, but the real power comes from customizing your routing rules. This guide walks through different strategies.
Understanding the Rule Syntax
Each rule has a `when` condition and either a `use` action or `never_downgrade: true`:
```yaml routes: - when: task_type: read_explain min_confidence: 0.6 use: model: claude-haiku-4-5 effort: low
- when: task_type: multi_file_refactor never_downgrade: true ```
Strategy 1: Aggressive Savings
If you're comfortable with more aggressive routing, lower the confidence floor and downgrade more task types:
```yaml confidence_floor_for_any_downgrade: 0.3 # Default: 0.6
routes: - when: { task_type: read_explain } use: { model: claude-haiku-4-5, effort: low } - when: { task_type: small_edit } use: { model: claude-haiku-4-5, effort: low } - when: { task_type: test_generation } use: { model: claude-haiku-4-5, effort: medium } ```
Risks: Simple questions that are misclassified may get lower quality responses.
Strategy 2: Conservative / Safety-First
Keep complex tasks on the best model, only downgrade the most obvious cases:
```yaml confidence_floor_for_any_downgrade: 0.8 # Higher bar
routes: - when: task_type: read_explain min_confidence: 0.8 use: { model: claude-haiku-4-5, effort: low } ```
Benefits: Very low risk of downgrading something that needed full power.
Strategy 3: Per-Project Policies
Use the `--project` flag to set different policies for different projects:
```bash promptbus install --project /path/to/production-repo promptbus install --project /path/to/side-project ```
Each project has its own `.claude/settings.json` and can use a different `rules.yaml`.
Editing via Dashboard
The web dashboard at `http://localhost:4702` provides a visual rules editor:
1. Open the "Routing Rules" tab 2. Select a task type from the dropdown 3. Enter the target model 4. Choose effort level 5. Toggle `never_downgrade` 6. Click "Save"
Changes are validated before writing to disk.
Monitoring Impact
Keep an eye on the dashboard stats: - **Reroute rate** — What percentage of requests are being downgraded - **Cost saved** — Estimated savings based on pricing config - **Per-request details** — Click any log entry to see why a decision was made
Adjust your rules based on actual usage patterns.