Skip to content

Comments

feat: Task-specific model switching with auto-restore#1

Draft
wca4a wants to merge 2 commits intomasterfrom
feat/task-specific-model-switching
Draft

feat: Task-specific model switching with auto-restore#1
wca4a wants to merge 2 commits intomasterfrom
feat/task-specific-model-switching

Conversation

@wca4a
Copy link
Contributor

@wca4a wca4a commented Jan 28, 2026

Summary

Adds task-specific model switching capability that automatically saves and restores the original model after task completion.

Features

1. Model Switching Script (scripts/model.ts)

  • Switch between Claude models: sonnet, opus, haiku, gemini, gemini-flash
  • Automatically saves original model before switching
  • Restores original model after task completion
  • State tracking via ~/.clawdbot/.model-state.json
  • Commands:
    • model.ts [model] - Switch model (saves original)
    • model.ts restore - Restore original model
    • model.ts state - Check if override is active

2. Authorization

  • Restricted to authorized ships via SKILL.md metadata
  • Configure allowed ships: authorization.ships: ["~your-ship"]
  • Prevents unauthorized model changes

3. Workflow

User (authorized): "Use opus to analyze this code"
  ↓
Bot switches to opus (saves original: sonnet)
  ↓
Bot completes analysis with opus
  ↓
Bot restores to sonnet
  ↓
User sees results from opus, bot returns to default

Usage

For Bot Operators:

Configure authorized ships in SKILL.md:

authorization:
  model: ships-only
  ships: ["~malmur-halmex", "~trusted-ship"]

For Users:

Request model for specific task:

  • "Use opus for this analysis"
  • "Switch to haiku for this quick task"
  • "Can you use gemini to generate this?"

Bot automatically handles save/restore cycle.

Implementation Details

  • Model state persisted to ~/.clawdbot/.model-state.json
  • Original model saved with timestamp
  • Restoration cleans up state file
  • Gateway restart required for changes to take effect
  • Aliases resolve to full model names (e.g., opusanthropic/claude-opus-4-5)

Testing

# Check current model
npx ts-node scripts/model.ts

# Switch to opus (saves original)
npx ts-node scripts/model.ts opus

# Check state
npx ts-node scripts/model.ts state

# Restore original
npx ts-node scripts/model.ts restore

Documentation

Updated SKILL.md with:

  • Authorization section explaining ship restrictions
  • Model switching commands and workflow
  • Task-specific usage examples
  • Notes on gateway restart requirements

🤖 Generated with Claude Sonnet 4.5

william arzt and others added 2 commits January 28, 2026 09:35
- Add scripts/model.ts for switching between Claude models
- Support task-specific model overrides that auto-restore
- Save/restore original model state via .model-state.json
- Restrict to authorized ships via SKILL.md authorization field
- Support aliases: sonnet, opus, haiku, gemini, gemini-flash
- Update SKILL.md with usage documentation
- Add authorization section explaining ship-based restrictions

Workflow:
1. Switch to model for task (saves original)
2. Complete task with requested model
3. Auto-restore original model after completion

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Remove hardcoded model names that may not exist
- Read aliases directly from clawdbot.json config
- More flexible ModelAlias interface (index signature only)
- Fallback to Claude models if config read fails
- Prevents errors from misconfigured/non-existent models

Fixes issue where Gemini model names in config don't match
actual Google API model names.
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.

1 participant