Files
clide/lib/builtin/claude/src/session_defaults.dart
T
jpmschweitzerandClaude Opus 4.8 ea670fd077 feat(settings): Claude category — new-session defaults (T-457)
A Settings → Claude category sets per-user defaults for NEW sessions: model,
effort, and permission mode (generic schema selects persisting
app.claude.default*). The pane reads them at spawn — effort flows through the
existing --effort flag (SpawnSpec.effort); model and permission mode are sent
as control requests right after a fresh (non-resume, non-fork) session starts.
'default'/unset values are no-ops, leaving the CLI's own defaults.

The optional "settings changed — apply to current sessions?" prompt is filed
as T-470: it needs a custom control (a generic select can't prompt), so it's
a clean follow-up on the T-452 escape hatch.

Tests: defaultEffortFlag sentinel handling; the category contributes the three
default fields. The thin pane-side applySessionDefaults is covered by the gate.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 19:58:11 +02:00

30 lines
1.5 KiB
Dart

import 'package:clide/builtin/claude/src/stream_json_session.dart';
import 'package:clide/kernel/kernel.dart';
/// Per-user defaults applied to NEW Claude sessions (T-457). Set from the
/// Settings → Claude category; read by the pane when it spawns a session.
/// Effort is applied at spawn (the `--effort` flag — there's no live
/// set_effort); model and permission mode are sent as control requests right
/// after the session starts.
const String kDefaultModelKey = 'app.claude.defaultModel';
const String kDefaultEffortKey = 'app.claude.defaultEffort';
const String kDefaultPermissionModeKey = 'app.claude.defaultPermissionMode';
/// The default effort for new sessions, or null to let the CLI's own default
/// stand. `'default'` is treated as "no override" too.
String? defaultEffortFlag(SettingsStore settings) {
final v = settings.get<String>(kDefaultEffortKey);
if (v == null || v.isEmpty || v == 'default') return null;
return v;
}
/// Apply the model + permission-mode defaults to a freshly-spawned [session].
/// A null/empty/`'default'` value is a no-op — the CLI's own default stands.
/// (Effort is handled at spawn via [defaultEffortFlag], not here.)
void applySessionDefaults(StreamJsonSession session, SettingsStore settings) {
final model = settings.get<String>(kDefaultModelKey);
if (model != null && model.isNotEmpty && model != 'default') session.setModel(model);
final perm = settings.get<String>(kDefaultPermissionModeKey);
if (perm != null && perm.isNotEmpty && perm != 'default') session.setPermissionMode(perm);
}