Skip to content

feat: Add allow-custom-agent-models patch#593

Merged
georpar merged 2 commits intoPiebald-AI:mainfrom
GMNGeoffrey:custom-model-names
Mar 8, 2026
Merged

feat: Add allow-custom-agent-models patch#593
georpar merged 2 commits intoPiebald-AI:mainfrom
GMNGeoffrey:custom-model-names

Conversation

@GMNGeoffrey
Copy link
Copy Markdown
Contributor

@GMNGeoffrey GMNGeoffrey commented Mar 7, 2026

Claude Code validates the model field in custom agent frontmatter (~/.claude/agents/*.md) against a hardcoded list of aliases (sonnet, opus, haiku, etc.). This prevents using arbitrary model names like "gemini-2.5-flash" or "oai@gemini-3-pro-preview".

This patch removes that restriction so that arbitrary model names pass through to the API. On its own this would cause API errors against the real Anthropic API, but it enables a useful workflow: running a local proxy (e.g. Claudish) that intercepts requests and routes non-Claude model names to appropriate backends with format translation.

Two locations are patched:

  1. The Zod schema in UDD that validates against enum() is relaxed to accept any string.
  2. The validation flag that gates whether the model field is included in the returned agent definition is changed to accept any non-empty string rather than only specific aliases. The search for this validation uses the captured list variable name from the Zod schema for robustness (the variable name has already changed across the few CC versions I tested).

Verified against real binaries: 2.1.58, 2.1.62, 2.1.69, 2.1.70.

The patch is opt-in (Features group, default: false). Enable with
allowCustomAgentModels: true in tweakcc config.

Summary by CodeRabbit

  • New Features
    • Added an "Allow custom agent models" setting with a toggle in the Misc/Settings UI to permit arbitrary model names in custom agent frontmatter.
  • Tests
    • Added test coverage validating the transformation and handling of various model-validation patterns.
  • Integrations
    • Hooked the new setting into the patching flow so the permissive model handling is applied when enabled.

Claude Code validates the `model` field in custom agent frontmatter
(~/.claude/agents/*.md) against a hardcoded list of aliases (sonnet,
opus, haiku, etc.). This prevents using arbitrary model names like
"gemini-2.5-flash" or "oai@gemini-3-pro-preview".

This patch removes that restriction so that arbitrary model names pass
through to the API. On its own this would cause API errors against the
real Anthropic API, but it enables a useful workflow: running a local
proxy (e.g. Claudish) that intercepts requests and routes non-Claude
model names to appropriate backends with format translation.

Two locations are patched:
1. The Zod schema in UDD that validates against enum(<list variable>) is
   relaxed to accept any string.
2. The validation flag that gates whether the model field is included in
   the returned agent definition is changed to accept any non-empty
   string rather than only specific aliases. The search for this
   validation uses the captured list variable name from the Zod schema
   for robustness (the variable name has already changed across the few
   CC versions I tested).

Verified against real binaries: 2.1.58, 2.1.62, 2.1.69, 2.1.70.

The patch is opt-in (Features group, default: false). Enable with
allowCustomAgentModels: true in tweakcc config.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 03ba01e0-c065-4a8a-aead-9e7b8ff84f84

📥 Commits

Reviewing files that changed from the base of the PR and between af357f5 and 150130c.

📒 Files selected for processing (4)
  • src/defaultSettings.ts
  • src/patches/index.ts
  • src/types.ts
  • src/ui/components/MiscView.tsx
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/ui/components/MiscView.tsx
  • src/types.ts
  • src/patches/index.ts
  • src/defaultSettings.ts

📝 Walkthrough

Walkthrough

Adds a feature flag allowCustomAgentModels with config, type, default, UI toggle, a new code-transform patch writeAllowCustomAgentModels, tests for that patch, and registers the patch behind the new flag.

Changes

Cohort / File(s) Summary
Configuration & Types
src/defaultSettings.ts, src/types.ts
Adds allowCustomAgentModels: boolean to DEFAULT_SETTINGS.misc and MiscConfig type (default false).
Patch Implementation
src/patches/allowCustomAgentModels.ts
New `writeAllowCustomAgentModels(file: string): string
Patch Tests
src/patches/allowCustomAgentModels.test.ts
Adds Vitest suite covering multiple code patterns, minified names, brace-edge cases, false positives, and non-transform scenarios.
Patch Registration
src/patches/index.ts
Registers new patch definition allow-custom-agent-models, imports writeAllowCustomAgentModels, and wires implementation to run when config.settings.misc?.allowCustomAgentModels is truthy.
User Interface
src/ui/components/MiscView.tsx
Adds a toggle control wired to settings.misc.allowCustomAgentModels in the Misc settings UI.

Sequence Diagram

sequenceDiagram
    participant User
    participant UI as MiscView (UI)
    participant Config as Settings Config
    participant PatchSys as Patch System
    participant PatchFn as writeAllowCustomAgentModels

    User->>UI: Toggle allowCustomAgentModels
    UI->>Config: Update misc.allowCustomAgentModels
    Config->>PatchSys: Settings read during patch run
    Note over PatchSys: Evaluate enabled patches
    alt allowCustomAgentModels enabled
        PatchSys->>PatchFn: Run on matching files
        PatchFn->>PatchFn: Locate Zod enum model validation
        PatchFn->>PatchFn: Replace with string().optional() model validation
        PatchFn->>PatchFn: Replace restrictive includes/flag logic with permissive check
        PatchFn-->>PatchSys: Return transformed file content
        PatchSys-->>Config: Persist patch result / emit diff
    else disabled
        PatchSys-->>Config: Skip patch
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • bl-ue

Poem

🐰 A tweak, a toggle, a tiny surprise,
Zod enums yield to stringy skies,
I hopped through code with glee and vim,
Now agents wear new model trim,
Hop—custom models, let them in! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a new patch feature to allow custom agent models.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@georpar
Copy link
Copy Markdown
Member

georpar commented Mar 8, 2026

Great feature; thank you!

@georpar georpar merged commit 5f0f6c7 into Piebald-AI:main Mar 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants