charmbracelet/crush · error

failed to override models: %w

Error message

failed to override models: %w

What it means

When largeModel or smallModel CLI flags are non-empty, RunNonInteractive calls overrideModelsForNonInteractive to override the configured preferred models; any failure there is wrapped with this message. It means the requested model override could not be resolved against known providers (unknown provider/model id or provider data unavailable).

Source

Thrown at internal/app/app.go:280

	}
}

// RunNonInteractive runs the application in non-interactive mode with the
// given prompt, printing to stdout.
func (app *App) RunNonInteractive(ctx context.Context, output io.Writer, prompt, largeModel, smallModel string, hideSpinner bool, continueSessionID string, useLast bool) error {
	slog.Info("Running in non-interactive mode")

	// Re-initialize the coder agent without interactive-only tools.
	if err := app.InitCoderAgentNonInteractive(ctx); err != nil {
		return fmt.Errorf("failed to reinitialize agent for non-interactive mode: %w", err)
	}

	ctx, cancel := context.WithCancel(ctx)
	defer cancel()

	if largeModel != "" || smallModel != "" {
		if err := app.overrideModelsForNonInteractive(ctx, largeModel, smallModel); err != nil {
			return fmt.Errorf("failed to override models: %w", err)
		}
	}

	var (
		spinner   *format.Spinner
		stderrTTY bool
		progress  bool
	)

	stderrTTY = term.IsTerminal(os.Stderr.Fd())
	progress = app.config.Config().Options.Progress == nil || *app.config.Config().Options.Progress

	if !hideSpinner && stderrTTY {
		t := styles.ThemeForProvider(app.config.Config().Models[config.SelectedModelTypeLarge].Provider)

		spinner = format.NewSpinner(ctx, cancel, anim.Settings{
			Size:        10,
			Label:       "Generating",

View on GitHub (pinned to 7944b8e522)

Solutions

  1. Verify the provider/model id exists: run `crush models` and copy an exact id
  2. Configure credentials for the provider being overridden (e.g. ANTHROPIC_API_KEY)
  3. Drop the --model flag to fall back to configured defaults
  4. Refresh the provider catalog (clear cache / update crush) if the model was renamed

Example fix

// before
crush run "fix tests" --model anthropic/claude-3-7-sonnet-latest
// after
crush run "fix tests" --model anthropic/claude-sonnet-4-5 // exact id from `crush models`
Defensive patterns

Strategy: validation

Validate before calling

models := config.Providers() // or `crush models`
for _, m := range []string{largeModel, smallModel} {
	if m != "" && !containsID(models, m) {
		return fmt.Errorf("unknown model id: %s", m)
	}
}

Try / catch

if err := app.RunNonInteractive(ctx, w, prompt, large, small, true, "", false); err != nil {
	if strings.Contains(err.Error(), "failed to override models") {
		// fall back to configured defaults
		return app.RunNonInteractive(ctx, w, prompt, "", "", true, "", false)
	}
	return err
}

Prevention

When it happens

Trigger: Calling RunNonInteractive with non-empty largeModel/smallModel (e.g. `--model provider/model`) where the provider is not configured, the model id does not exist in the provider catalog, or the provider catalog fetch failed.

Common situations: Typo in `--model anthropic/claude-sonnet-4-5` style ids; using a provider that was never configured with credentials; stale/cached provider catalog after a model was renamed or removed upstream.

Related errors


AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29). Data as JSON: /api/errors/572556228a144d98. Report an issue: GitHub.