From ce7c5a01bb68099ddf7d913b53b98cbbd53c20f6 Mon Sep 17 00:00:00 2001 From: Savin Angel-Mario Date: Sat, 7 Nov 2026 11:17:06 +0200 Subject: [PATCH 01/13] Add five measured trims: git instructions, Claude API skill, Explore and Plan agents, advisor tool, background tasks Each trim shrank the first request in a measured Claude Code 2.1.319 run (from 363 tokens for git instructions to 1,358 for the advisor tool). Trims that set an environment variable write it into the env block of Claude Code's settings.json, and turning the trim off removes it again only when the value is still the one Claudiu wrote. Refs #98 --- src/claude/trim.rs | 79 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 4 deletions(-) diff --git a/src/claude/trim.rs b/src/claude/trim.rs index c007f7b..6482b8d 100644 --- a/src/claude/trim.rs +++ b/src/claude/trim.rs @@ -29,24 +29,35 @@ pub enum Trim { DesignSync, NotebookEdit, ReportFindings, + GitInstructions, + ClaudeApiSkill, + ExplorePlanAgents, + AdvisorTool, + BackgroundTasks, } /// What turning an item off does in the settings file. enum Effect { /// Settings keys set to the given values. Keys(&'static [(&'static str, bool)]), + /// Variables set in the `env` block, which Claude Code applies to the session. + Env(&'static [(&'static str, &'static str)]), /// Tool names added to `permissions.deny`. Deny(&'static [&'static str]), } impl Trim { /// In the order the page lists them, grouped (see `GROUPS`). - pub const ALL: [Trim; 15] = [ + pub const ALL: [Trim; 20] = [ Self::BundledSkills, + Self::ClaudeApiSkill, Self::Workflows, Self::RemoteControl, Self::ClaudeAiConnectors, Self::Artifacts, + Self::ExplorePlanAgents, + Self::AdvisorTool, + Self::BackgroundTasks, Self::PlanMode, Self::AskUserQuestion, Self::ScheduledTasks, @@ -57,15 +68,17 @@ impl Trim { Self::DesignSync, Self::NotebookEdit, Self::ReportFindings, + Self::GitInstructions, ]; /// The page's groups: a heading and the items under it. - pub const GROUPS: [(&'static str, &'static [Trim]); 5] = [ - ("FEATURES", &[Self::BundledSkills, Self::Workflows, Self::RemoteControl, Self::ClaudeAiConnectors, Self::Artifacts]), + pub const GROUPS: [(&'static str, &'static [Trim]); 6] = [ + ("FEATURES", &[Self::BundledSkills, Self::ClaudeApiSkill, Self::Workflows, Self::RemoteControl, Self::ClaudeAiConnectors, Self::Artifacts]), + ("AGENTS AND TASKS", &[Self::ExplorePlanAgents, Self::AdvisorTool, Self::BackgroundTasks]), ("PLANNING", &[Self::PlanMode, Self::AskUserQuestion]), ("SCHEDULING", &[Self::ScheduledTasks, Self::ScheduleWakeup, Self::RemoteTrigger]), ("MESSAGING", &[Self::SendMessage, Self::PushNotification]), - ("OTHER", &[Self::DesignSync, Self::NotebookEdit, Self::ReportFindings]), + ("OTHER", &[Self::DesignSync, Self::NotebookEdit, Self::ReportFindings, Self::GitInstructions]), ]; pub fn label(self) -> &'static str { @@ -85,6 +98,11 @@ impl Trim { Self::DesignSync => "DesignSync", Self::NotebookEdit => "NotebookEdit", Self::ReportFindings => "ReportFindings", + Self::GitInstructions => "Git instructions", + Self::ClaudeApiSkill => "Claude API skill", + Self::ExplorePlanAgents => "Explore and Plan agents", + Self::AdvisorTool => "Advisor tool", + Self::BackgroundTasks => "Background tasks", } } @@ -105,6 +123,11 @@ impl Trim { Self::DesignSync => Effect::Deny(&["DesignSync"]), Self::NotebookEdit => Effect::Deny(&["NotebookEdit"]), Self::ReportFindings => Effect::Deny(&["ReportFindings"]), + Self::GitInstructions => Effect::Keys(&[("includeGitInstructions", false)]), + Self::ClaudeApiSkill => Effect::Env(&[("CLAUDE_CODE_DISABLE_CLAUDE_API_SKILL", "1")]), + Self::ExplorePlanAgents => Effect::Env(&[("CLAUDE_CODE_DISABLE_EXPLORE_PLAN_AGENTS", "1")]), + Self::AdvisorTool => Effect::Env(&[("CLAUDE_CODE_DISABLE_ADVISOR_TOOL", "1")]), + Self::BackgroundTasks => Effect::Env(&[("CLAUDE_CODE_DISABLE_BACKGROUND_TASKS", "1")]), } } } @@ -119,6 +142,7 @@ pub fn normalized(trimmed: &[Trim]) -> Vec { enum Entry { Key(&'static str, bool), Deny(&'static str), + Env(&'static str, &'static str), } impl Entry { @@ -127,6 +151,7 @@ impl Entry { match self { Entry::Key(key, _) => key.to_string(), Entry::Deny(name) => format!("deny:{name}"), + Entry::Env(name, _) => format!("env:{name}"), } } } @@ -135,6 +160,7 @@ fn entries(trim: Trim) -> Vec { match trim.effect() { Effect::Keys(keys) => keys.iter().map(|(key, value)| Entry::Key(key, *value)).collect(), Effect::Deny(names) => names.iter().map(|name| Entry::Deny(name)).collect(), + Effect::Env(vars) => vars.iter().map(|(name, value)| Entry::Env(name, value)).collect(), } } @@ -145,6 +171,7 @@ fn present(settings: &Map, entry: Entry) -> bool { let list = settings.get("permissions").and_then(|p| p.get("deny")).and_then(Value::as_array); list.is_some_and(|list| list.iter().any(|v| v.as_str() == Some(name))) } + Entry::Env(name, value) => settings.get("env").and_then(|e| e.get(name)).and_then(Value::as_str) == Some(value), } } @@ -161,6 +188,12 @@ fn add(settings: &mut Map, entry: Entry) { list.push(Value::String(name.into())); } } + Entry::Env(name, value) => { + let env = settings.entry("env").or_insert_with(|| json!({})); + if let Some(env) = env.as_object_mut() { + env.insert(name.into(), Value::String(value.into())); + } + } } } @@ -183,6 +216,15 @@ fn remove(settings: &mut Map, entry: Entry) { settings.remove("permissions"); } } + Entry::Env(name, value) => { + let Some(env) = settings.get_mut("env").and_then(Value::as_object_mut) else { return }; + if env.get(name).and_then(Value::as_str) == Some(value) { + env.remove(name); + } + if env.is_empty() { + settings.remove("env"); + } + } } } @@ -308,6 +350,35 @@ mod tests { assert_eq!(std::fs::read_to_string(&path).unwrap(), "{ not json"); } + #[test] + fn env_trims_go_in_the_env_block_beside_the_users_own_variables() { + let mut s = object(json!({ "env": { "FOO": "1" } })); + let owned = apply(&mut s, &[AdvisorTool, BackgroundTasks], &[]); + assert_eq!( + Value::Object(s.clone()), + json!({ "env": { "FOO": "1", "CLAUDE_CODE_DISABLE_ADVISOR_TOOL": "1", "CLAUDE_CODE_DISABLE_BACKGROUND_TASKS": "1" } }) + ); + apply(&mut s, &[], &owned); + assert_eq!(Value::Object(s), json!({ "env": { "FOO": "1" } })); + } + + #[test] + fn an_env_block_that_claudiu_created_is_removed_when_it_ends_up_empty() { + let mut s = Map::new(); + let owned = apply(&mut s, &[ExplorePlanAgents], &[]); + apply(&mut s, &[], &owned); + assert!(s.is_empty()); + } + + #[test] + fn git_instructions_are_turned_off_with_a_false_value_that_is_removed_again() { + let mut s = object(json!({ "model": "sonnet" })); + let owned = apply(&mut s, &[GitInstructions], &[]); + assert_eq!(Value::Object(s.clone()), json!({ "model": "sonnet", "includeGitInstructions": false })); + apply(&mut s, &[], &owned); + assert_eq!(Value::Object(s), json!({ "model": "sonnet" })); + } + #[test] fn every_item_is_listed_once_in_the_page_groups() { let listed: Vec = Trim::GROUPS.iter().flat_map(|(_, items)| items.iter().copied()).collect(); From 7fe91bfce92a0a8a82eef0fed62c39bc71023226 Mon Sep 17 00:00:00 2001 From: Savin Angel-Mario Date: Sat, 7 Nov 2026 11:20:51 +0200 Subject: [PATCH 02/13] Add output caps and per-skill switches to the Claude Code tools page Three text fields under LIMITS: most characters of Bash output, most tokens of a file read, and skills to turn off. In a measured run a cap of 2,000 characters cut a 3,000-line Bash result by about 6,800 tokens, a 2,000 token file-read cap cut a 4,000-line read by about 19,000, and three skills off cut the skills listing by 1,200. Empty fields change nothing, and a value the user set in settings.json is never overwritten or removed. Refs #98 --- src/app/mod.rs | 10 +- src/app/modal.rs | 22 +++- src/app/settings.rs | 3 +- src/claude/trim.rs | 235 ++++++++++++++++++++++++++++------- src/panels/workspace_view.rs | 9 +- src/store.rs | 3 + 6 files changed, 226 insertions(+), 56 deletions(-) diff --git a/src/app/mod.rs b/src/app/mod.rs index 02bc7e5..d353605 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -305,6 +305,8 @@ pub enum Modal { trimmed: Vec, /// Claudiu tools turned off (Claudiu tools page). claudiu_off: Vec, + /// Bash output cap, file read cap and skills to turn off, in that order (Claude Code tools page). + limit_fields: [Entity; 3], /// Focus of the category list, which has the keyboard when the dialog opens. list_focus: FocusHandle, }, @@ -793,10 +795,16 @@ impl Workspace { let claude = self.modal_input(&claude_t, &claude_hint, window, cx); let model = self.modal_input(defaults.model.as_deref().unwrap_or_default(), "Claude Code default", window, cx); let shell = self.modal_input(&shell_t, &platform::default_shell(None).0, window, cx); + let (bash_t, file_t, skills_t) = self.store.data.settings.limits.texts(); + let limit_fields = [ + self.modal_input(&bash_t, "Claude Code default (30000)", window, cx), + self.modal_input(&file_t, "Claude Code default", window, cx), + self.modal_input(&skills_t, "none, e.g. dataviz, claude-api", window, cx), + ]; let list_focus = cx.focus_handle(); window.focus(&list_focus, cx); self.set_settings_page(self.settings_page, cx); - self.modal = Some(Modal::Settings { shell, claude, model, effort: defaults.effort, permission: defaults.permission_mode, updates, chrome, scale: crate::panels::scale::percent(), trimmed: self.store.data.settings.trimmed_tools.clone(), claudiu_off: self.store.data.settings.claudiu_tools_off.clone(), list_focus }); + self.modal = Some(Modal::Settings { shell, claude, model, effort: defaults.effort, permission: defaults.permission_mode, updates, chrome, scale: crate::panels::scale::percent(), trimmed: self.store.data.settings.trimmed_tools.clone(), claudiu_off: self.store.data.settings.claudiu_tools_off.clone(), limit_fields, list_focus }); } Act::PickEffort(choice) => { if let Some(Modal::Settings { effort, .. }) = self.modal.as_mut() { diff --git a/src/app/modal.rs b/src/app/modal.rs index e801849..fc86827 100644 --- a/src/app/modal.rs +++ b/src/app/modal.rs @@ -108,7 +108,7 @@ impl Workspace { } } } - Some(Modal::Settings { shell, claude, model, effort, permission, updates, chrome, scale, trimmed, claudiu_off, list_focus }) => { + Some(Modal::Settings { shell, claude, model, effort, permission, updates, chrome, scale, trimmed, claudiu_off, limit_fields, list_focus }) => { let clean = |s: &str| s.trim().trim_matches('"').to_string(); let (shell_t, claude_t) = (clean(shell.read(cx).value().as_ref()), clean(claude.read(cx).value().as_ref())); let model_name = claude::defaults::parse_model(model.read(cx).value().as_ref()); @@ -118,10 +118,17 @@ impl Workspace { .find(|(_, _, t)| !t.is_empty() && platform::resolve_program(t).is_none()) .map(|(what, field, t)| (SettingsPage::General, field.clone(), format!("{what}: “{t}” is not a file or a program on PATH"))); let bad_model = model_name.is_err().then(|| (SettingsPage::Sessions, model.clone(), "Use a model alias or id (letters, digits, . _ -).".to_string())); - if let Some((page, field, msg)) = paths.or(bad_model) { + let [bash_field, file_field, skills_field] = &limit_fields; + let limits = claude::trim::Limits::parse(bash_field.read(cx).value().as_ref(), file_field.read(cx).value().as_ref(), skills_field.read(cx).value().as_ref()); + // The parser's message starts with the field it blames, which says which of the three to focus. + let bad_limits = limits.as_ref().err().map(|why| { + let field = if why.starts_with("Bash") { bash_field } else if why.starts_with("File") { file_field } else { skills_field }; + (SettingsPage::ClaudeTools, field.clone(), why.clone()) + }); + if let Some((page, field, msg)) = paths.or(bad_model).or(bad_limits) { self.settings_page = page; field.update(cx, |s, cx| s.focus(window, cx)); - self.modal = Some(Modal::Settings { shell, claude, model, effort, permission, updates, chrome, scale, trimmed, claudiu_off, list_focus }); + self.modal = Some(Modal::Settings { shell, claude, model, effort, permission, updates, chrome, scale, trimmed, claudiu_off, limit_fields, list_focus }); self.toast(msg, true, cx); return; } @@ -141,20 +148,23 @@ impl Workspace { // When that fails the old trims stay, so what the page shows is what Claude Code has. let mut trim_error = None; let mut trimmed = trimmed; - if s.trimmed_tools != trimmed { + let mut limits = limits.unwrap_or_default(); + if s.trimmed_tools != trimmed || s.limits != limits { let written = claude::claude_home() .ok_or_else(|| std::io::Error::other("Claude Code's folder was not found")) - .and_then(|home| claude::trim::write_global(&home.join("settings.json"), &trimmed, &s.applied_trims)); + .and_then(|home| claude::trim::write_global(&home.join("settings.json"), &trimmed, &limits, &s.applied_trims)); match written { Ok(owned) => s.applied_trims = owned, Err(e) => { trim_error = Some(e); trimmed = s.trimmed_tools.clone(); + limits = s.limits.clone(); } } } - let tools_changed = s.trimmed_tools != trimmed || s.claudiu_tools_off != claudiu_off; + let tools_changed = s.trimmed_tools != trimmed || s.limits != limits || s.claudiu_tools_off != claudiu_off; s.trimmed_tools = trimmed; + s.limits = limits; s.claudiu_tools_off = claudiu_off; crate::panels::scale::set(scale); self.shell = platform::default_shell(s.shell.as_deref()); diff --git a/src/app/settings.rs b/src/app/settings.rs index 3fad218..60f31f8 100644 --- a/src/app/settings.rs +++ b/src/app/settings.rs @@ -46,11 +46,12 @@ impl Workspace { /// Keys for the open Settings dialog, seen before the focused control. Up and Down change the page and Enter saves /// only while the category list has focus; Tab and Shift+Tab cycle the list and the current page's text fields. pub(crate) fn settings_key(&mut self, ev: &KeyDownEvent, window: &mut Window, cx: &mut Context) { - let Some(Modal::Settings { shell, claude, model, list_focus, .. }) = &self.modal else { return }; + let Some(Modal::Settings { shell, claude, model, limit_fields, list_focus, .. }) = &self.modal else { return }; let list_focus = list_focus.clone(); let fields = match self.settings_page { SettingsPage::General => vec![shell.clone(), claude.clone()], SettingsPage::Sessions => vec![model.clone()], + SettingsPage::ClaudeTools => limit_fields.to_vec(), _ => Vec::new(), }; let on_list = list_focus.is_focused(window); diff --git a/src/claude/trim.rs b/src/claude/trim.rs index 6482b8d..01c5f7f 100644 --- a/src/claude/trim.rs +++ b/src/claude/trim.rs @@ -137,77 +137,102 @@ pub fn normalized(trimmed: &[Trim]) -> Vec { Trim::ALL.into_iter().filter(|t| trimmed.contains(t)).collect() } -/// One line Claudiu adds to `settings.json` for a trim. -#[derive(Clone, Copy, PartialEq)] +/// One line Claudiu adds to `settings.json`. +#[derive(Clone, PartialEq)] enum Entry { Key(&'static str, bool), Deny(&'static str), - Env(&'static str, &'static str), + Env(String, String), + /// A skill turned off in `skillOverrides`. + Skill(String), } impl Entry { /// How `applied` remembers it. - fn id(self) -> String { + fn id(&self) -> String { match self { Entry::Key(key, _) => key.to_string(), Entry::Deny(name) => format!("deny:{name}"), - Entry::Env(name, _) => format!("env:{name}"), + Entry::Env(name, value) => format!("env:{name}={value}"), + Entry::Skill(name) => format!("skill:{name}"), } } + + /// The entry an earlier `id` stood for, so it can be taken out again. The value is part of an env id because the + /// caps change between saves. + fn from_id(id: &str) -> Option { + if let Some(rest) = id.strip_prefix("env:") { + let (name, value) = rest.split_once('=')?; + return Some(Entry::Env(name.into(), value.into())); + } + if let Some(name) = id.strip_prefix("skill:") { + return Some(Entry::Skill(name.into())); + } + Trim::ALL.into_iter().flat_map(entries).find(|entry| entry.id() == id) + } } fn entries(trim: Trim) -> Vec { match trim.effect() { Effect::Keys(keys) => keys.iter().map(|(key, value)| Entry::Key(key, *value)).collect(), Effect::Deny(names) => names.iter().map(|name| Entry::Deny(name)).collect(), - Effect::Env(vars) => vars.iter().map(|(name, value)| Entry::Env(name, value)).collect(), + Effect::Env(vars) => vars.iter().map(|(name, value)| Entry::Env(name.to_string(), value.to_string())).collect(), } } -fn present(settings: &Map, entry: Entry) -> bool { +fn present(settings: &Map, entry: &Entry) -> bool { match entry { - Entry::Key(key, value) => settings.get(key) == Some(&Value::Bool(value)), + Entry::Key(key, value) => settings.get(*key) == Some(&Value::Bool(*value)), Entry::Deny(name) => { let list = settings.get("permissions").and_then(|p| p.get("deny")).and_then(Value::as_array); list.is_some_and(|list| list.iter().any(|v| v.as_str() == Some(name))) } Entry::Env(name, value) => settings.get("env").and_then(|e| e.get(name)).and_then(Value::as_str) == Some(value), + Entry::Skill(name) => settings.get("skillOverrides").and_then(|o| o.get(name)).and_then(Value::as_str) == Some("off"), } } -fn add(settings: &mut Map, entry: Entry) { +/// Add `entry`. A value the user set differently for the same env variable or skill stays; `apply` notices that the +/// entry is not present afterwards and does not claim it. +fn add(settings: &mut Map, entry: &Entry) { match entry { Entry::Key(key, value) => { - settings.insert(key.into(), Value::Bool(value)); + settings.insert((*key).into(), Value::Bool(*value)); } Entry::Deny(name) => { let permissions = settings.entry("permissions").or_insert_with(|| json!({})); if let Some(permissions) = permissions.as_object_mut() && let Some(list) = permissions.entry("deny").or_insert_with(|| json!([])).as_array_mut() { - list.push(Value::String(name.into())); + list.push(Value::String((*name).into())); } } Entry::Env(name, value) => { let env = settings.entry("env").or_insert_with(|| json!({})); if let Some(env) = env.as_object_mut() { - env.insert(name.into(), Value::String(value.into())); + env.entry(name.clone()).or_insert_with(|| Value::String(value.clone())); + } + } + Entry::Skill(name) => { + let overrides = settings.entry("skillOverrides").or_insert_with(|| json!({})); + if let Some(overrides) = overrides.as_object_mut() { + overrides.entry(name.clone()).or_insert_with(|| Value::String("off".into())); } } } } -fn remove(settings: &mut Map, entry: Entry) { +fn remove(settings: &mut Map, entry: &Entry) { match entry { Entry::Key(key, value) => { - if settings.get(key) == Some(&Value::Bool(value)) { - settings.remove(key); + if settings.get(*key) == Some(&Value::Bool(*value)) { + settings.remove(*key); } } Entry::Deny(name) => { let Some(permissions) = settings.get_mut("permissions").and_then(Value::as_object_mut) else { return }; if let Some(list) = permissions.get_mut("deny").and_then(Value::as_array_mut) { - list.retain(|v| v.as_str() != Some(name)); + list.retain(|v| v.as_str() != Some(*name)); if list.is_empty() { permissions.remove("deny"); } @@ -225,24 +250,84 @@ fn remove(settings: &mut Map, entry: Entry) { settings.remove("env"); } } + Entry::Skill(name) => { + let Some(overrides) = settings.get_mut("skillOverrides").and_then(Value::as_object_mut) else { return }; + if overrides.get(name).and_then(Value::as_str) == Some("off") { + overrides.remove(name); + } + if overrides.is_empty() { + settings.remove("skillOverrides"); + } + } } } -/// Put the trimmed items into `settings` and take out the ones Claudiu added earlier (`applied`) that are no longer -/// trimmed. A line the user had before Claudiu (a tool they denied themselves) is never recorded, so turning the trim -/// off leaves it. Returns what Claudiu now owns, to pass back next time. -pub fn apply(settings: &mut Map, trimmed: &[Trim], applied: &[String]) -> Vec { - let wanted: Vec = normalized(trimmed).into_iter().flat_map(entries).collect(); - let known: Vec = Trim::ALL.into_iter().flat_map(entries).collect(); - for entry in known.iter().filter(|e| applied.contains(&e.id()) && !wanted.contains(e)) { - remove(settings, *entry); +/// The caps and skills the user set on the Claude Code tools page. Empty means Claude Code's own behavior. +#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] +pub struct Limits { + /// Most characters of a Bash command's output that reach the model (`BASH_MAX_OUTPUT_LENGTH`). + #[serde(default)] + pub bash_output: Option, + /// Most tokens a single file read returns (`CLAUDE_CODE_FILE_READ_MAX_OUTPUT_TOKENS`). + #[serde(default)] + pub file_read_tokens: Option, + /// Skills Claude no longer sees (`skillOverrides` set to `off`); the user can still type them. + #[serde(default)] + pub skills_off: Vec, +} + +impl Limits { + /// The page's three text fields. Empty text leaves a cap unset. Skills are separated by commas or spaces. + pub fn parse(bash_output: &str, file_read_tokens: &str, skills: &str) -> Result { + let number = |what: &str, text: &str| match text.trim() { + "" => Ok(None), + t => t.parse::().ok().filter(|n| *n > 0).map(Some).ok_or(format!("{what}: use a whole number above 0, or leave it empty.")), + }; + let mut skills_off: Vec = vec![]; + for name in skills.split([',', ' ', '\n']).map(str::trim).filter(|n| !n.is_empty()) { + let valid = name.chars().all(|c| c.is_ascii_alphanumeric() || matches!(c, '-' | '_' | ':' | '.')); + if !valid { + return Err(format!("Skills: “{name}” is not a skill name (letters, digits, - _ : .).")); + } + if !skills_off.iter().any(|s| s == name) { + skills_off.push(name.to_string()); + } + } + Ok(Limits { bash_output: number("Bash output", bash_output)?, file_read_tokens: number("File reads", file_read_tokens)?, skills_off }) + } + + /// The fields as text, for the page. + pub fn texts(&self) -> (String, String, String) { + let number = |n: Option| n.map(|n| n.to_string()).unwrap_or_default(); + (number(self.bash_output), number(self.file_read_tokens), self.skills_off.join(", ")) + } + + fn entries(&self) -> Vec { + let env = |name: &str, n: Option| n.map(|n| Entry::Env(name.into(), n.to_string())); + let caps = [env("BASH_MAX_OUTPUT_LENGTH", self.bash_output), env("CLAUDE_CODE_FILE_READ_MAX_OUTPUT_TOKENS", self.file_read_tokens)]; + caps.into_iter().flatten().chain(self.skills_off.iter().map(|name| Entry::Skill(name.clone()))).collect() + } +} + +/// Put the trimmed items and limits into `settings` and take out the ones Claudiu added earlier (`applied`) that are +/// no longer wanted. A line the user had before Claudiu (a tool they denied themselves, a cap they set) is never +/// recorded, so turning the trim off leaves it. Returns what Claudiu now owns, to pass back next time. +pub fn apply(settings: &mut Map, trimmed: &[Trim], limits: &Limits, applied: &[String]) -> Vec { + let wanted: Vec = normalized(trimmed).into_iter().flat_map(entries).chain(limits.entries()).collect(); + let wanted_ids: Vec = wanted.iter().map(Entry::id).collect(); + for id in applied.iter().filter(|id| !wanted_ids.contains(id)) { + if let Some(entry) = Entry::from_id(id) { + remove(settings, &entry); + } } let mut owned = vec![]; for entry in wanted { let was_ours = applied.contains(&entry.id()); - if !present(settings, entry) { - add(settings, entry); - owned.push(entry.id()); + if !present(settings, &entry) { + add(settings, &entry); + if present(settings, &entry) { + owned.push(entry.id()); + } } else if was_ours { owned.push(entry.id()); } @@ -252,7 +337,7 @@ pub fn apply(settings: &mut Map, trimmed: &[Trim], applied: &[Str /// `apply` to the `settings.json` at `path`, written only when something changed. A file that is not a JSON object is /// never overwritten. -pub fn write_global(path: &std::path::Path, trimmed: &[Trim], applied: &[String]) -> std::io::Result> { +pub fn write_global(path: &std::path::Path, trimmed: &[Trim], limits: &Limits, applied: &[String]) -> std::io::Result> { let text = match std::fs::read_to_string(path) { Ok(text) => text, Err(e) if e.kind() == std::io::ErrorKind::NotFound => "{}".into(), @@ -262,7 +347,7 @@ pub fn write_global(path: &std::path::Path, trimmed: &[Trim], applied: &[String] return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "settings.json is not a JSON object")); }; let before = settings.clone(); - let owned = apply(&mut settings, trimmed, applied); + let owned = apply(&mut settings, trimmed, limits, applied); if settings != before { crate::datadir::write_atomic(path, &serde_json::to_string_pretty(&settings).map_err(std::io::Error::other)?)?; } @@ -286,7 +371,7 @@ mod tests { #[test] fn a_flag_and_a_tool_group_give_the_flag_and_exactly_their_denies() { let mut s = object(json!({ "model": "sonnet" })); - let owned = apply(&mut s, &[PlanMode, Workflows], &[]); + let owned = apply(&mut s, &[PlanMode, Workflows], &Limits::default(), &[]); assert_eq!(Value::Object(s), json!({ "model": "sonnet", "disableWorkflows": true, "permissions": { "deny": ["EnterPlanMode", "ExitPlanMode"] } })); assert_eq!(owned, ["disableWorkflows", "deny:EnterPlanMode", "deny:ExitPlanMode"]); } @@ -294,7 +379,7 @@ mod tests { #[test] fn artifacts_are_turned_off_with_the_current_key_and_the_deprecated_one() { let mut s = Map::new(); - apply(&mut s, &[Artifacts], &[]); + apply(&mut s, &[Artifacts], &Limits::default(), &[]); assert_eq!(Value::Object(s), json!({ "enableArtifact": false, "disableArtifact": true })); } @@ -302,9 +387,9 @@ mod tests { fn turning_a_trim_off_takes_out_only_what_claudiu_added() { let mut s = object(json!({ "permissions": { "deny": ["NotebookEdit"], "defaultMode": "auto" } })); // The user already denied NotebookEdit; Claudiu adds the other two. - let owned = apply(&mut s, &[NotebookEdit, ScheduledTasks, Workflows], &[]); + let owned = apply(&mut s, &[NotebookEdit, ScheduledTasks, Workflows], &Limits::default(), &[]); assert_eq!(owned, ["disableWorkflows", "deny:CronCreate", "deny:CronDelete", "deny:CronList"], "the user's own deny is not recorded"); - let owned = apply(&mut s, &[], &owned); + let owned = apply(&mut s, &[], &Limits::default(), &owned); assert!(owned.is_empty()); assert_eq!(Value::Object(s), json!({ "permissions": { "deny": ["NotebookEdit"], "defaultMode": "auto" } })); } @@ -312,18 +397,18 @@ mod tests { #[test] fn an_empty_deny_list_and_permissions_object_are_cleaned_up() { let mut s = Map::new(); - let owned = apply(&mut s, &[SendMessage], &[]); + let owned = apply(&mut s, &[SendMessage], &Limits::default(), &[]); assert!(s.contains_key("permissions")); - apply(&mut s, &[], &owned); + apply(&mut s, &[], &Limits::default(), &owned); assert!(s.is_empty()); } #[test] fn trimming_again_changes_nothing_and_keeps_ownership() { let mut s = Map::new(); - let owned = apply(&mut s, &[BundledSkills], &[]); + let owned = apply(&mut s, &[BundledSkills], &Limits::default(), &[]); let before = s.clone(); - assert_eq!(apply(&mut s, &[BundledSkills], &owned), owned); + assert_eq!(apply(&mut s, &[BundledSkills], &Limits::default(), &owned), owned); assert_eq!(s, before); } @@ -332,12 +417,12 @@ mod tests { let tmp = tempfile::tempdir().unwrap(); let path = tmp.path().join("settings.json"); std::fs::write(&path, "{\n \"zeta\": 1,\n \"alpha\": 2\n}").unwrap(); - let owned = write_global(&path, &[Workflows], &[]).unwrap(); + let owned = write_global(&path, &[Workflows], &Limits::default(), &[]).unwrap(); let text = std::fs::read_to_string(&path).unwrap(); assert!(text.find("zeta").unwrap() < text.find("alpha").unwrap(), "keys keep their order: {text}"); assert!(text.contains("disableWorkflows")); let stamp = std::fs::metadata(&path).unwrap().modified().unwrap(); - write_global(&path, &[Workflows], &owned).unwrap(); + write_global(&path, &[Workflows], &Limits::default(), &owned).unwrap(); assert_eq!(std::fs::metadata(&path).unwrap().modified().unwrap(), stamp, "nothing to change, nothing written"); } @@ -346,39 +431,97 @@ mod tests { let tmp = tempfile::tempdir().unwrap(); let path = tmp.path().join("settings.json"); std::fs::write(&path, "{ not json").unwrap(); - assert!(write_global(&path, &[Workflows], &[]).is_err()); + assert!(write_global(&path, &[Workflows], &Limits::default(), &[]).is_err()); assert_eq!(std::fs::read_to_string(&path).unwrap(), "{ not json"); } #[test] fn env_trims_go_in_the_env_block_beside_the_users_own_variables() { let mut s = object(json!({ "env": { "FOO": "1" } })); - let owned = apply(&mut s, &[AdvisorTool, BackgroundTasks], &[]); + let owned = apply(&mut s, &[AdvisorTool, BackgroundTasks], &Limits::default(), &[]); assert_eq!( Value::Object(s.clone()), json!({ "env": { "FOO": "1", "CLAUDE_CODE_DISABLE_ADVISOR_TOOL": "1", "CLAUDE_CODE_DISABLE_BACKGROUND_TASKS": "1" } }) ); - apply(&mut s, &[], &owned); + apply(&mut s, &[], &Limits::default(), &owned); assert_eq!(Value::Object(s), json!({ "env": { "FOO": "1" } })); } #[test] fn an_env_block_that_claudiu_created_is_removed_when_it_ends_up_empty() { let mut s = Map::new(); - let owned = apply(&mut s, &[ExplorePlanAgents], &[]); - apply(&mut s, &[], &owned); + let owned = apply(&mut s, &[ExplorePlanAgents], &Limits::default(), &[]); + apply(&mut s, &[], &Limits::default(), &owned); assert!(s.is_empty()); } #[test] fn git_instructions_are_turned_off_with_a_false_value_that_is_removed_again() { let mut s = object(json!({ "model": "sonnet" })); - let owned = apply(&mut s, &[GitInstructions], &[]); + let owned = apply(&mut s, &[GitInstructions], &Limits::default(), &[]); assert_eq!(Value::Object(s.clone()), json!({ "model": "sonnet", "includeGitInstructions": false })); - apply(&mut s, &[], &owned); + apply(&mut s, &[], &Limits::default(), &owned); assert_eq!(Value::Object(s), json!({ "model": "sonnet" })); } + fn limits(bash: Option, file: Option, skills: &[&str]) -> Limits { + Limits { bash_output: bash, file_read_tokens: file, skills_off: skills.iter().map(|s| s.to_string()).collect() } + } + + #[test] + fn caps_and_skills_go_where_claude_code_reads_them() { + let mut s = object(json!({ "skillOverrides": { "loop": "user-invocable-only" } })); + apply(&mut s, &[], &limits(Some(2000), Some(5000), &["dataviz", "m4:do"]), &[]); + assert_eq!( + Value::Object(s), + json!({ + "env": { "BASH_MAX_OUTPUT_LENGTH": "2000", "CLAUDE_CODE_FILE_READ_MAX_OUTPUT_TOKENS": "5000" }, + "skillOverrides": { "loop": "user-invocable-only", "dataviz": "off", "m4:do": "off" } + }) + ); + } + + #[test] + fn changing_a_cap_replaces_the_old_value_and_clearing_it_removes_it() { + let mut s = Map::new(); + let owned = apply(&mut s, &[], &limits(Some(2000), None, &[]), &[]); + let owned = apply(&mut s, &[], &limits(Some(3000), None, &[]), &owned); + assert_eq!(Value::Object(s.clone()), json!({ "env": { "BASH_MAX_OUTPUT_LENGTH": "3000" } })); + apply(&mut s, &[], &Limits::default(), &owned); + assert!(s.is_empty()); + } + + #[test] + fn a_cap_or_skill_the_user_set_differently_is_kept_and_never_removed() { + let mut s = object(json!({ "env": { "BASH_MAX_OUTPUT_LENGTH": "9000" }, "skillOverrides": { "dataviz": "user-invocable-only" } })); + let owned = apply(&mut s, &[], &limits(Some(2000), None, &["dataviz"]), &[]); + assert!(owned.is_empty(), "nothing was added, so nothing is claimed"); + apply(&mut s, &[], &Limits::default(), &owned); + assert_eq!(Value::Object(s), json!({ "env": { "BASH_MAX_OUTPUT_LENGTH": "9000" }, "skillOverrides": { "dataviz": "user-invocable-only" } })); + } + + #[test] + fn turning_a_skill_back_on_removes_the_override_and_an_empty_block() { + let mut s = Map::new(); + let owned = apply(&mut s, &[], &limits(None, None, &["dataviz"]), &[]); + apply(&mut s, &[], &limits(None, None, &[]), &owned); + assert!(s.is_empty()); + } + + #[test] + fn the_limit_fields_are_parsed_with_empty_meaning_unset() { + assert_eq!(Limits::parse("", " ", "").unwrap(), Limits::default()); + assert_eq!(Limits::parse("2000", "5000", "dataviz, m4:do dataviz").unwrap(), limits(Some(2000), Some(5000), &["dataviz", "m4:do"])); + assert!(Limits::parse("0", "", "").unwrap_err().starts_with("Bash output")); + assert!(Limits::parse("", "ten", "").unwrap_err().starts_with("File reads")); + assert!(Limits::parse("", "", "a/b").unwrap_err().starts_with("Skills")); + } + + #[test] + fn the_fields_show_the_saved_limits_as_text() { + assert_eq!(limits(Some(2000), None, &["a", "b"]).texts(), ("2000".to_string(), String::new(), "a, b".to_string())); + } + #[test] fn every_item_is_listed_once_in_the_page_groups() { let listed: Vec = Trim::GROUPS.iter().flat_map(|(_, items)| items.iter().copied()).collect(); diff --git a/src/panels/workspace_view.rs b/src/panels/workspace_view.rs index d7e1854..12bdedd 100644 --- a/src/panels/workspace_view.rs +++ b/src/panels/workspace_view.rs @@ -822,7 +822,7 @@ impl Render for Workspace { /// The Settings dialog's body: the category list on the left and the chosen page on the right. fn settings_body(page: SettingsPage, modal: &Modal, worktrees: &crate::app::WorktreesPage, scroll: &crate::panels::glide::Smooth, window: &mut Window, cx: &mut Context) -> AnyElement { - let Modal::Settings { shell, claude, model, effort, permission, updates, chrome, scale, trimmed, claudiu_off, list_focus } = modal else { + let Modal::Settings { shell, claude, model, effort, permission, updates, chrome, scale, trimmed, claudiu_off, limit_fields, list_focus } = modal else { return div().into_any_element(); }; let (updates, chrome, scale) = (*updates, *chrome, *scale); @@ -901,7 +901,12 @@ fn settings_body(page: SettingsPage, modal: &Modal, worktrees: &crate::app::Work if plan_trimmed { list = list.child(faint("With Plan mode off, Claude can't leave plan mode itself; press Shift+Tab.".to_string())); } - list + let [bash_field, file_field, skills_field] = limit_fields; + list.child(div().mt(px(4.0)).child(section_label("LIMITS".to_string()))) + .child(faint("Leave a field empty to keep Claude Code's own behavior. A value you already set in Claude Code's settings.json wins.".to_string())) + .child(field("BASH OUTPUT, MOST CHARACTERS", bash_field)) + .child(field("FILE READ, MOST TOKENS", file_field)) + .child(field("SKILLS TO TURN OFF, SEPARATED BY COMMAS", skills_field)) } SettingsPage::ClaudiuTools => { let mut list = div().flex().flex_col().gap(px(8.0)).child(faint( diff --git a/src/store.rs b/src/store.rs index 6f5819d..fd61bee 100644 --- a/src/store.rs +++ b/src/store.rs @@ -285,6 +285,9 @@ pub struct Settings { /// The lines Claudiu added to Claude Code's `settings.json` for those trims, so turning one off removes only them. #[serde(default)] pub applied_trims: Vec, + /// Output caps and turned-off skills for Claude Code (`claude/trim.rs`); empty leaves Claude Code's own behavior. + #[serde(default)] + pub limits: crate::claude::trim::Limits, } #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] From 77baf0f8e193c42233b565c85966381d2a9e90c6 Mon Sep 17 00:00:00 2001 From: Savin Angel-Mario Date: Sat, 7 Nov 2026 11:22:37 +0200 Subject: [PATCH 03/13] Warn on the Claude Code tools page when a setting makes Claude Code cost more The page now lists prompt caching turned off (DISABLE_PROMPT_CACHING and the per-model variants) and tool search turned off (ENABLE_TOOL_SEARCH set to false), found in Claudiu's environment or in the env block of Claude Code's settings.json. Both changed real requests in a measured run: no cache reads with caching off, and a first request of 26k instead of 18k tokens with tool search off. Refs #98 --- src/app/mod.rs | 4 +- src/app/modal.rs | 4 +- src/claude/costly.rs | 125 +++++++++++++++++++++++++++++++++++ src/claude/mod.rs | 1 + src/panels/workspace_view.rs | 10 ++- 5 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 src/claude/costly.rs diff --git a/src/app/mod.rs b/src/app/mod.rs index d353605..cf45308 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -307,6 +307,8 @@ pub enum Modal { claudiu_off: Vec, /// Bash output cap, file read cap and skills to turn off, in that order (Claude Code tools page). limit_fields: [Entity; 3], + /// Settings found at open time that make Claude Code cost more (Claude Code tools page). + costly: Vec, /// Focus of the category list, which has the keyboard when the dialog opens. list_focus: FocusHandle, }, @@ -804,7 +806,7 @@ impl Workspace { let list_focus = cx.focus_handle(); window.focus(&list_focus, cx); self.set_settings_page(self.settings_page, cx); - self.modal = Some(Modal::Settings { shell, claude, model, effort: defaults.effort, permission: defaults.permission_mode, updates, chrome, scale: crate::panels::scale::percent(), trimmed: self.store.data.settings.trimmed_tools.clone(), claudiu_off: self.store.data.settings.claudiu_tools_off.clone(), limit_fields, list_focus }); + self.modal = Some(Modal::Settings { shell, claude, model, effort: defaults.effort, permission: defaults.permission_mode, updates, chrome, scale: crate::panels::scale::percent(), trimmed: self.store.data.settings.trimmed_tools.clone(), claudiu_off: self.store.data.settings.claudiu_tools_off.clone(), limit_fields, costly: claude::costly::scan(), list_focus }); } Act::PickEffort(choice) => { if let Some(Modal::Settings { effort, .. }) = self.modal.as_mut() { diff --git a/src/app/modal.rs b/src/app/modal.rs index fc86827..a902ea1 100644 --- a/src/app/modal.rs +++ b/src/app/modal.rs @@ -108,7 +108,7 @@ impl Workspace { } } } - Some(Modal::Settings { shell, claude, model, effort, permission, updates, chrome, scale, trimmed, claudiu_off, limit_fields, list_focus }) => { + Some(Modal::Settings { shell, claude, model, effort, permission, updates, chrome, scale, trimmed, claudiu_off, limit_fields, costly, list_focus }) => { let clean = |s: &str| s.trim().trim_matches('"').to_string(); let (shell_t, claude_t) = (clean(shell.read(cx).value().as_ref()), clean(claude.read(cx).value().as_ref())); let model_name = claude::defaults::parse_model(model.read(cx).value().as_ref()); @@ -128,7 +128,7 @@ impl Workspace { if let Some((page, field, msg)) = paths.or(bad_model).or(bad_limits) { self.settings_page = page; field.update(cx, |s, cx| s.focus(window, cx)); - self.modal = Some(Modal::Settings { shell, claude, model, effort, permission, updates, chrome, scale, trimmed, claudiu_off, limit_fields, list_focus }); + self.modal = Some(Modal::Settings { shell, claude, model, effort, permission, updates, chrome, scale, trimmed, claudiu_off, limit_fields, costly, list_focus }); self.toast(msg, true, cx); return; } diff --git a/src/claude/costly.rs b/src/claude/costly.rs new file mode 100644 index 0000000..9186f0e --- /dev/null +++ b/src/claude/costly.rs @@ -0,0 +1,125 @@ +//! Settings that make Claude Code cost more, found in Claudiu's own environment and in Claude Code's `settings.json` +//! `env` block. Each one changed a real request in a measured run on Claude Code 2.1.319: with prompt caching off +//! nothing was read from the cache, and with tool search off the first request grew from 18k to 26k tokens. + +use std::path::Path; + +use serde_json::{Map, Value}; + +/// One variable that raises cost, and where it was found. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Finding { + pub name: &'static str, + pub source: &'static str, + pub effect: &'static str, +} + +const NO_CACHE: &str = "Turns prompt caching off, so every request pays full price for the whole conversation."; +const NO_TOOL_SEARCH: &str = "Sends every tool definition in each request (about 8,000 more tokens in a measured run)."; + +/// A variable and the effect of having it on. Caching variables are on when truthy, tool search is off when falsy. +const CACHING: [(&str, &str); 6] = [ + ("DISABLE_PROMPT_CACHING", NO_CACHE), + ("DISABLE_PROMPT_CACHING_FABLE", NO_CACHE), + ("DISABLE_PROMPT_CACHING_HAIKU", NO_CACHE), + ("DISABLE_PROMPT_CACHING_MYTHOS", NO_CACHE), + ("DISABLE_PROMPT_CACHING_OPUS", NO_CACHE), + ("DISABLE_PROMPT_CACHING_SONNET", NO_CACHE), +]; + +fn truthy(value: &str) -> bool { + matches!(value.trim().to_ascii_lowercase().as_str(), "1" | "true" | "yes" | "on") +} + +fn falsy(value: &str) -> bool { + matches!(value.trim().to_ascii_lowercase().as_str(), "0" | "false" | "no" | "off") +} + +/// What raises cost in `process_env` (Claudiu's environment, which the sessions it starts inherit) and `file_env` (the +/// `env` block of `settings.json`). A variable set in both places is reported for the process environment. +pub fn find(process_env: &dyn Fn(&str) -> Option, file_env: &Map) -> Vec { + let look = |name: &str| -> Option<(&'static str, String)> { + if let Some(v) = process_env(name) { + return Some(("Claudiu's environment", v)); + } + file_env.get(name).and_then(Value::as_str).map(|v| ("Claude Code's settings.json", v.to_string())) + }; + let mut found = vec![]; + for (name, effect) in CACHING { + if let Some((source, _)) = look(name).filter(|(_, v)| truthy(v)) { + found.push(Finding { name, source, effect }); + } + } + if let Some((source, _)) = look("ENABLE_TOOL_SEARCH").filter(|(_, v)| falsy(v)) { + found.push(Finding { name: "ENABLE_TOOL_SEARCH", source, effect: NO_TOOL_SEARCH }); + } + found +} + +/// The `env` block of the `settings.json` at `path`; empty when the file is missing or is not a JSON object. +pub fn read_file_env(path: &Path) -> Map { + let Ok(text) = std::fs::read_to_string(path) else { return Map::new() }; + let Ok(Value::Object(settings)) = serde_json::from_str(&text) else { return Map::new() }; + settings.get("env").and_then(Value::as_object).cloned().unwrap_or_default() +} + +/// `find` on the real environment and Claude Code's own `settings.json`. +pub fn scan() -> Vec { + let file_env = crate::claude::claude_home().map(|home| read_file_env(&home.join("settings.json"))).unwrap_or_default(); + find(&|name| std::env::var(name).ok(), &file_env) +} + +#[cfg(test)] +mod tests { + use super::*; + use serde_json::json; + + fn none(_: &str) -> Option { + None + } + + fn names(found: &[Finding]) -> Vec<&'static str> { + found.iter().map(|f| f.name).collect() + } + + #[test] + fn a_clean_setup_has_no_findings() { + assert!(find(&none, &Map::new()).is_empty()); + } + + #[test] + fn caching_off_is_found_in_the_environment_and_says_where() { + let env = |name: &str| (name == "DISABLE_PROMPT_CACHING_HAIKU").then(|| "1".to_string()); + let found = find(&env, &Map::new()); + assert_eq!(found, [Finding { name: "DISABLE_PROMPT_CACHING_HAIKU", source: "Claudiu's environment", effect: NO_CACHE }]); + } + + #[test] + fn the_settings_file_env_block_is_read_too() { + let file = json!({ "DISABLE_PROMPT_CACHING": "true", "ENABLE_TOOL_SEARCH": "false" }).as_object().unwrap().clone(); + let found = find(&none, &file); + assert_eq!(names(&found), ["DISABLE_PROMPT_CACHING", "ENABLE_TOOL_SEARCH"]); + assert!(found.iter().all(|f| f.source == "Claude Code's settings.json")); + } + + #[test] + fn a_variable_set_to_off_is_not_a_finding() { + let file = json!({ "DISABLE_PROMPT_CACHING": "0", "ENABLE_TOOL_SEARCH": "true" }).as_object().unwrap().clone(); + assert!(find(&none, &file).is_empty()); + } + + #[test] + fn the_process_environment_wins_over_the_file() { + let env = |name: &str| (name == "DISABLE_PROMPT_CACHING").then(|| "1".to_string()); + let file = json!({ "DISABLE_PROMPT_CACHING": "1" }).as_object().unwrap().clone(); + assert_eq!(find(&env, &file)[0].source, "Claudiu's environment"); + } + + #[test] + fn a_missing_or_broken_settings_file_gives_an_empty_env_block() { + let tmp = tempfile::tempdir().unwrap(); + assert!(read_file_env(&tmp.path().join("missing.json")).is_empty()); + std::fs::write(tmp.path().join("bad.json"), "{ nope").unwrap(); + assert!(read_file_env(&tmp.path().join("bad.json")).is_empty()); + } +} diff --git a/src/claude/mod.rs b/src/claude/mod.rs index bd0ed83..394edeb 100644 --- a/src/claude/mod.rs +++ b/src/claude/mod.rs @@ -12,6 +12,7 @@ pub mod accounts; pub mod ask; pub mod bridge; pub mod config_sync; +pub mod costly; pub mod defaults; pub mod mcp; pub mod plugin; diff --git a/src/panels/workspace_view.rs b/src/panels/workspace_view.rs index 12bdedd..bf88eba 100644 --- a/src/panels/workspace_view.rs +++ b/src/panels/workspace_view.rs @@ -822,7 +822,7 @@ impl Render for Workspace { /// The Settings dialog's body: the category list on the left and the chosen page on the right. fn settings_body(page: SettingsPage, modal: &Modal, worktrees: &crate::app::WorktreesPage, scroll: &crate::panels::glide::Smooth, window: &mut Window, cx: &mut Context) -> AnyElement { - let Modal::Settings { shell, claude, model, effort, permission, updates, chrome, scale, trimmed, claudiu_off, limit_fields, list_focus } = modal else { + let Modal::Settings { shell, claude, model, effort, permission, updates, chrome, scale, trimmed, claudiu_off, limit_fields, costly, list_focus } = modal else { return div().into_any_element(); }; let (updates, chrome, scale) = (*updates, *chrome, *scale); @@ -884,6 +884,14 @@ fn settings_body(page: SettingsPage, modal: &Modal, worktrees: &crate::app::Work SettingsPage::ClaudeTools => { let plan_trimmed = trimmed.contains(&Trim::PlanMode); let mut list = div().flex().flex_col().gap(px(8.0)); + for found in costly { + list = list.child( + div() + .text_size(scaled(11.0)) + .text_color(hsla(theme::WARN)) + .child(format!("{} is set in {}. {}", found.name, found.source, found.effect)), + ); + } list = list.child(faint( "Applies to new sessions. Running sessions keep their tools. Resumed sessions get the new tools, and the old instructions stay until their next compaction. These switches edit Claude Code's own settings.json, for every account and for Claude Code outside Claudiu. Claudiu only turns things off; anything you turned off yourself stays off." .to_string(), From c9baae220daf0b813525794cb7305d50664ca491 Mon Sep 17 00:00:00 2001 From: Savin Angel-Mario Date: Sat, 7 Nov 2026 16:45:52 +0200 Subject: [PATCH 04/13] List Artifacts first and tag the trims that save almost nothing In a measured run on Claude Code 2.1.319, turning Artifacts off saved 13,390 tokens per request, more than every other trim together. Ten switches saved under 100 each, because their tools load only when Claude searches for them. The page now lists Artifacts first and shows "saves little" beside those ten. The Advisor tool keeps no tag, because it saves 1,358 tokens when an advisor model is set. --- src/claude/trim.rs | 31 +++++++++++++++++++++++++++++-- src/panels/workspace_view.rs | 14 +++++++++----- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/claude/trim.rs b/src/claude/trim.rs index 01c5f7f..64bbe73 100644 --- a/src/claude/trim.rs +++ b/src/claude/trim.rs @@ -49,12 +49,12 @@ enum Effect { impl Trim { /// In the order the page lists them, grouped (see `GROUPS`). pub const ALL: [Trim; 20] = [ + Self::Artifacts, Self::BundledSkills, Self::ClaudeApiSkill, Self::Workflows, Self::RemoteControl, Self::ClaudeAiConnectors, - Self::Artifacts, Self::ExplorePlanAgents, Self::AdvisorTool, Self::BackgroundTasks, @@ -73,7 +73,7 @@ impl Trim { /// The page's groups: a heading and the items under it. pub const GROUPS: [(&'static str, &'static [Trim]); 6] = [ - ("FEATURES", &[Self::BundledSkills, Self::ClaudeApiSkill, Self::Workflows, Self::RemoteControl, Self::ClaudeAiConnectors, Self::Artifacts]), + ("FEATURES", &[Self::Artifacts, Self::BundledSkills, Self::ClaudeApiSkill, Self::Workflows, Self::RemoteControl, Self::ClaudeAiConnectors]), ("AGENTS AND TASKS", &[Self::ExplorePlanAgents, Self::AdvisorTool, Self::BackgroundTasks]), ("PLANNING", &[Self::PlanMode, Self::AskUserQuestion]), ("SCHEDULING", &[Self::ScheduledTasks, Self::ScheduleWakeup, Self::RemoteTrigger]), @@ -106,6 +106,24 @@ impl Trim { } } + /// Turning it off saved under 100 tokens per request in a measured run (Claude Code 2.1.319): these tools load only + /// when Claude searches for them, so the switch removes the tool but hardly any tokens. The page tags them. + pub fn saves_little(self) -> bool { + matches!( + self, + Self::Workflows + | Self::RemoteControl + | Self::PlanMode + | Self::AskUserQuestion + | Self::ScheduledTasks + | Self::RemoteTrigger + | Self::SendMessage + | Self::PushNotification + | Self::DesignSync + | Self::NotebookEdit + ) + } + fn effect(self) -> Effect { match self { Self::BundledSkills => Effect::Keys(&[("disableBundledSkills", true)]), @@ -522,6 +540,15 @@ mod tests { assert_eq!(limits(Some(2000), None, &["a", "b"]).texts(), ("2000".to_string(), String::new(), "a, b".to_string())); } + #[test] + fn only_the_switches_measured_under_100_tokens_are_tagged_as_saving_little() { + let tagged: Vec = Trim::ALL.into_iter().filter(|t| t.saves_little()).collect(); + assert_eq!( + tagged, + [Workflows, RemoteControl, PlanMode, AskUserQuestion, ScheduledTasks, RemoteTrigger, SendMessage, PushNotification, DesignSync, NotebookEdit] + ); + } + #[test] fn every_item_is_listed_once_in_the_page_groups() { let listed: Vec = Trim::GROUPS.iter().flat_map(|(_, items)| items.iter().copied()).collect(); diff --git a/src/panels/workspace_view.rs b/src/panels/workspace_view.rs index bf88eba..e2e030a 100644 --- a/src/panels/workspace_view.rs +++ b/src/panels/workspace_view.rs @@ -899,7 +899,8 @@ fn settings_body(page: SettingsPage, modal: &Modal, worktrees: &crate::app::Work for (heading, items) in Trim::GROUPS { list = list.child(div().mt(px(4.0)).child(section_label(heading.to_string()))); for &item in items { - list = list.child(switch_row(("settings-trim", item as usize), item.label(), !trimmed.contains(&item), move |ws| { + let tag = item.saves_little().then_some("saves little"); + list = list.child(switch_row(("settings-trim", item as usize), item.label(), tag, !trimmed.contains(&item), move |ws| { if let Some(Modal::Settings { trimmed, .. }) = ws.modal.as_mut() { flip(trimmed, item); } @@ -922,7 +923,7 @@ fn settings_body(page: SettingsPage, modal: &Modal, worktrees: &crate::app::Work .to_string(), )); for feature in Feature::ALL { - list = list.child(switch_row(("settings-claudiu", feature as usize), feature.label(), !claudiu_off.contains(&feature), move |ws| { + list = list.child(switch_row(("settings-claudiu", feature as usize), feature.label(), None, !claudiu_off.contains(&feature), move |ws| { if let Some(Modal::Settings { claudiu_off, .. }) = ws.modal.as_mut() { flip(claudiu_off, feature); } @@ -1057,7 +1058,7 @@ fn worktrees_page(page: &crate::app::WorktreesPage, cx: &mut Context) /// An On/Off row in the Settings modal; `field` picks the flag it flips. fn settings_toggle(id: &'static str, label: &'static str, on: bool, field: fn(&mut Modal) -> Option<&mut bool>, cx: &mut Context) -> impl IntoElement { - switch_row(id, label, on, move |ws| { + switch_row(id, label, None, on, move |ws| { if let Some(flag) = ws.modal.as_mut().and_then(field) { *flag = !*flag; } @@ -1108,10 +1109,11 @@ fn flip(items: &mut Vec, item: T) { } } -/// An On/Off row that runs `flip` on the workspace when clicked. +/// An On/Off row that runs `flip` on the workspace when clicked, with an optional faint `tag` after the label. fn switch_row( id: impl Into, label: &'static str, + tag: Option<&'static str>, on: bool, flip: impl Fn(&mut Workspace) + 'static, cx: &mut Context, @@ -1129,7 +1131,9 @@ fn switch_row( .border_color(hsla(0x242424)) .text_size(crate::panels::scale::px(13.0)) .cursor_pointer() - .child(label) + .child(div().flex().items_center().gap(px(8.0)).child(label).children(tag.map(|tag| { + div().text_size(crate::panels::scale::px(11.0)).text_color(hsla(theme::TEXT_FAINT)).child(tag) + }))) .child(div().text_color(hsla(if on { theme::ACCENT } else { theme::TEXT_FAINT })).child(if on { "On" } else { "Off" })) .on_click(cx.listener(move |ws, _: &ClickEvent, _w, cx| { flip(ws); From 96f1cd068f5edaf578954ba95b7f9770d70bb976 Mon Sep 17 00:00:00 2001 From: Savin Angel-Mario Date: Sat, 7 Nov 2026 16:54:00 +0200 Subject: [PATCH 05/13] Tag every trim with its saving and offer recommended trims in setup Each switch on the Claude Code tools page now shows "high savings", "medium savings" or "low savings", from the per-trim measurement on Claude Code 2.1.319. The setup window has an optional "Recommended trims" switch, off by default. When the user turns it on, Claudiu turns off Artifacts, bundled skills, claude.ai connectors, ScheduleWakeup, ReportFindings and the Claude API skill once, as saving them in Settings would. Settings stays the place to change them afterwards. --- README.md | 2 +- src/app/setup.rs | 110 ++++++++++++++++++++++++++++++----- src/claude/trim.rs | 79 +++++++++++++++++++------ src/main.rs | 4 +- src/panels/workspace_view.rs | 2 +- 5 files changed, 160 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index e8003c1..de4d2b3 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Claudiu is a native desktop app, written in Rust with [GPUI](https://gpui.rs), t ## What it does -Each session is your own `claude` process in a real pseudo-terminal, so Claude Code's keys, mouse and paste work unchanged. Claudiu has no API keys and never calls the Anthropic API. Sign-in stays with Claude Code. The first launch opens a setup window that checks for `claude` (required) and `gh` (optional), links to their install pages and installs nothing. Settings has a Check setup button to open it again. A sidebar lists your projects and sessions. Ended sessions resume through `claude --resume`, and sessions that were running come back at the next start. +Each session is your own `claude` process in a real pseudo-terminal, so Claude Code's keys, mouse and paste work unchanged. Claudiu has no API keys and never calls the Anthropic API. Sign-in stays with Claude Code. The first launch opens a setup window that checks for `claude` (required) and `gh` (optional), links to their install pages and installs nothing. It also has an optional switch that turns off six Claude Code features that add tokens to every request and that coding rarely uses, such as Artifacts and bundled skills. Settings → Claude Code tools shows each switch as high, medium or low savings. Settings has a Check setup button to open it again. A sidebar lists your projects and sessions. Ended sessions resume through `claude --resume`, and sessions that were running come back at the next start. Around the terminal, Claudiu adds an editor mode (Ctrl+Shift+E) with files, tabs, search, Git change marks and language-server diagnostics, definitions and completion. It also adds usage and context meters, a GitHub pane for issues and pull requests through your `gh` login, defaults for the model, effort and permission mode of new sessions, and extra Claude accounts that share one configuration. When a reply needs a table, chart or diagram, Claude draws it as a card inside the terminal, under the tool call, and the card scrolls with the transcript. Cards can hold buttons that send a message for you, collapsible sections, tabs and charts, and they come back when you reopen a session. A session can move between git worktrees the way it switches branches, so several agents work on separate branches at once: the worktree button in the top bar switches the shown session into another worktree, or into a new one that Claudiu makes on a branch you name, and its conversation continues there (a session that has no conversation yet starts over in the new folder). Claude can switch the session itself with the `switch_worktree` tool, after you approve it and once its turn ends. In the menu, the hover x removes a worktree, the branch button's x deletes a local branch after telling you which commits would be lost, and ending the last session in a worktree offers to remove it. Claudiu keeps the worktrees it makes in its own data folder, outside your repositories, so they never show up in `git status`; Settings has a Worktrees page that lists them to show in the file manager or remove. Settings lists the rest. diff --git a/src/app/setup.rs b/src/app/setup.rs index 75acc06..69ca39d 100644 --- a/src/app/setup.rs +++ b/src/app/setup.rs @@ -1,11 +1,12 @@ //! The setup window: a short checklist of the two tools Claudiu runs (`claude`, required; `gh`, optional). It opens //! alone on a first launch (see `main.rs`) and again from Settings or the missing-`claude` toast. It installs nothing. -//! It never owns the store: it hands the path the user typed back in `SetupEvent::Done`, and the main window applies it. +//! It never owns the store: it hands the path the user typed and the recommended-trims choice back in `SetupEvent::Done`, +//! and the main window applies them. use super::*; use gpui::{ - Bounds, ClickEvent, EventEmitter, IntoElement, ParentElement, Render, SharedString, StatefulInteractiveElement, Styled, TitlebarOptions, + Bounds, ClickEvent, EventEmitter, InteractiveElement, IntoElement, ParentElement, Render, SharedString, StatefulInteractiveElement, Styled, TitlebarOptions, WindowBounds, WindowOptions, div, prelude::FluentBuilder, px, size, }; use gpui_kit::assets::IconName; @@ -31,8 +32,9 @@ pub enum Mode { } pub enum SetupEvent { - /// The user is done. Holds the `claude` path they gave, `None` for "find it yourself". - Done(Option), + /// The user is done. `claude_path` is the path they gave, `None` for "find it yourself". `recommended_trims` asks + /// the main window to turn off `trim::RECOMMENDED` once, as if they were switched off in Settings. + Done { claude_path: Option, recommended_trims: bool }, /// Run `gh auth login` in a terminal tab of the main window (only sent in `Mode::Reopened`). SignIn, } @@ -78,6 +80,8 @@ pub struct SetupView { checks: u64, /// Reads the PATH again before each check; `platform::reload_path`, except in tests. reload_path: fn(), + /// The "recommended trims" switch; off until the user turns it on. + recommended_trims: bool, done: bool, } @@ -106,7 +110,7 @@ impl SetupView { view.update(cx, |view, cx| view.close(window, cx)).is_err() }); } - let mut view = Self { mode, path_input, configured: current, path_error: None, checked: None, asked_again: false, checks: 0, reload_path, done: false }; + let mut view = Self { mode, path_input, configured: current, path_error: None, checked: None, asked_again: false, checks: 0, reload_path, recommended_trims: false, done: false }; view.run_checks(cx); view } @@ -157,7 +161,7 @@ impl SetupView { return; } self.done = true; - cx.emit(SetupEvent::Done(self.path_to_hand_back(cx))); + cx.emit(SetupEvent::Done { claude_path: self.path_to_hand_back(cx), recommended_trims: self.recommended_trims }); } /// Hand the path back and close the window. The window goes in a deferred step: the main window listens through a @@ -219,6 +223,31 @@ impl SetupView { button(id, label, true).on_click(cx.listener(move |_, _: &ClickEvent, _, cx| cx.open_url(url))) } + fn trims_row(&self, cx: &mut Context) -> impl IntoElement { + let on = self.recommended_trims; + card() + .child(tool_title("Recommended trims", "OPTIONAL")) + .child( + div() + .id("setup-recommended-trims") + .flex() + .items_center() + .justify_between() + .gap(px(12.0)) + .cursor_pointer() + .text_size(crate::panels::scale::px(13.0)) + .child(div().min_w_0().child( + "Turn off Claude Code features that add tokens to every request and that coding rarely uses: Artifacts, bundled skills, claude.ai connectors, ScheduleWakeup, ReportFindings and the Claude API skill.", + )) + .child(div().flex_none().text_color(hsla(if on { theme::ACCENT } else { theme::TEXT_FAINT })).child(if on { "On" } else { "Off" })) + .on_click(cx.listener(|view, _: &ClickEvent, _, cx| { + view.recommended_trims = !view.recommended_trims; + cx.notify(); + })), + ) + .child(faint("Settings → Claude Code tools changes them later. This edits Claude Code's own settings.json.")) + } + fn claude_row(&self, cx: &mut Context) -> impl IntoElement { let found = self.checked.as_ref().map(|found| &found.claude); let state = match found { @@ -305,6 +334,7 @@ impl Render for SetupView { .child(self.claude_row(cx)) .child(self.gh_row(cx)) .children(self.needs_restart_hint().then(|| faint(STILL_MISSING))) + .child(self.trims_row(cx)) .child(div().flex_1()) .child( div() @@ -336,9 +366,9 @@ impl Workspace { }; self.setup_window = Some(handle); cx.subscribe_in(&view, window, |ws: &mut Workspace, _, ev: &SetupEvent, window, cx| match ev { - SetupEvent::Done(path) => { + SetupEvent::Done { claude_path, recommended_trims } => { ws.setup_window = None; - ws.apply_setup(path.clone(), cx); + ws.apply_setup(claude_path.clone(), *recommended_trims, cx); } SetupEvent::SignIn => { window.activate_window(); @@ -348,15 +378,38 @@ impl Workspace { .detach(); } - /// Use what the setup window ended with: its `claude` path (`None` clears it), looked for again, and saved. On a - /// first launch the save also creates the state file. - pub fn apply_setup(&mut self, claude_path: Option, cx: &mut Context) { + /// Use what the setup window ended with: its `claude` path (`None` clears it), looked for again, and saved, and + /// the recommended trims when asked for. On a first launch the save also creates the state file. + pub fn apply_setup(&mut self, claude_path: Option, recommended_trims: bool, cx: &mut Context) { self.store.data.settings.claude_path = claude_path; self.claude_exe = claude::discover(self.store.data.settings.claude_path.as_deref()); + if recommended_trims { + self.add_recommended_trims(cx); + } self.store.mark_dirty(); self.store.save(); cx.notify(); } + + /// Write the recommended trims into Claude Code's settings.json, as saving them in Settings would. When the file + /// can't be changed the trims stay as they were, so Settings shows what Claude Code has. + fn add_recommended_trims(&mut self, cx: &mut Context) { + let s = &mut self.store.data.settings; + let trimmed = claude::trim::with_recommended(&s.trimmed_tools); + if trimmed == s.trimmed_tools { + return; + } + let written = claude::claude_home() + .ok_or_else(|| std::io::Error::other("Claude Code's folder was not found")) + .and_then(|home| claude::trim::write_global(&home.join("settings.json"), &trimmed, &s.limits, &s.applied_trims)); + match written { + Ok(owned) => { + s.applied_trims = owned; + s.trimmed_tools = trimmed; + } + Err(e) => self.toast(format!("Claude Code's settings.json could not be changed ({e}), so the recommended trims are not on."), true, cx), + } + } } #[cfg(test)] @@ -385,8 +438,8 @@ mod tests { let log = handed_back.clone(); let _watch = cx.update(|app| { app.subscribe(&view, move |_, ev: &SetupEvent, _| { - if let SetupEvent::Done(path) = ev { - log.borrow_mut().push(path.clone()); + if let SetupEvent::Done { claude_path, .. } = ev { + log.borrow_mut().push(claude_path.clone()); } }) }); @@ -417,8 +470,8 @@ mod tests { let log = handed_back.clone(); let _watch = cx.update(|app| { app.subscribe(&view, move |_, ev: &SetupEvent, _| { - if let SetupEvent::Done(path) = ev { - log.borrow_mut().push(path.clone()); + if let SetupEvent::Done { claude_path, .. } = ev { + log.borrow_mut().push(claude_path.clone()); } }) }); @@ -451,6 +504,33 @@ mod tests { } } + #[test] + fn the_recommended_trims_are_off_unless_the_user_turns_them_on() { + let mut cx = TestAppContext::single(); + cx.update(gpui_kit::init); + let choices: Rc>> = Rc::default(); + for turn_on in [false, true] { + let (_, view) = cx + .update(|app| gpui_kit::open_window(Default::default(), app, |window, app| app.new(|cx| SetupView::with_reload(Mode::Reopened, None, || {}, window, cx)))) + .unwrap(); + let log = choices.clone(); + let _watch = cx.update(|app| { + app.subscribe(&view, move |_, ev: &SetupEvent, _| { + if let SetupEvent::Done { recommended_trims, .. } = ev { + log.borrow_mut().push(*recommended_trims); + } + }) + }); + view.update(&mut cx, |view, cx| { + if turn_on { + view.recommended_trims = !view.recommended_trims; + } + view.finish(cx); + }); + } + assert_eq!(*choices.borrow(), [false, true]); + } + #[test] fn the_claude_path_field_is_empty_a_real_program_or_an_error() { let tmp = tempfile::tempdir().unwrap(); diff --git a/src/claude/trim.rs b/src/claude/trim.rs index 64bbe73..2cfdb2a 100644 --- a/src/claude/trim.rs +++ b/src/claude/trim.rs @@ -46,6 +46,34 @@ enum Effect { Deny(&'static [&'static str]), } +/// How much a trim saves; shown beside each switch (see `Trim::saving`). +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Saving { + High, + Medium, + Low, +} + +impl Saving { + pub fn label(self) -> &'static str { + match self { + Saving::High => "high savings", + Saving::Medium => "medium savings", + Saving::Low => "low savings", + } + } +} + +/// What the setup window's "recommended trims" switch turns off: the high and medium savers that take nothing away +/// from how Claude works. The Advisor tool, Git instructions, background tasks and the Explore and Plan agents save +/// tokens too, but a new user has not chosen to lose them. +pub const RECOMMENDED: [Trim; 6] = [Trim::Artifacts, Trim::BundledSkills, Trim::ClaudeApiSkill, Trim::ClaudeAiConnectors, Trim::ScheduleWakeup, Trim::ReportFindings]; + +/// `trimmed` with the recommended trims added; what the user had turned off stays off. +pub fn with_recommended(trimmed: &[Trim]) -> Vec { + normalized(&[trimmed, &RECOMMENDED[..]].concat()) +} + impl Trim { /// In the order the page lists them, grouped (see `GROUPS`). pub const ALL: [Trim; 20] = [ @@ -106,22 +134,24 @@ impl Trim { } } - /// Turning it off saved under 100 tokens per request in a measured run (Claude Code 2.1.319): these tools load only - /// when Claude searches for them, so the switch removes the tool but hardly any tokens. The page tags them. - pub fn saves_little(self) -> bool { - matches!( - self, + /// How many tokens turning it off saved per request in a measured run on Claude Code 2.1.319 (first request, + /// alone against no trims): high is 1,300 to 13,400, medium 330 to 830, low under 100. Low ones are tools that load + /// only when Claude searches for them. The Advisor tool is high only when an advisor model is set, and 0 otherwise. + pub fn saving(self) -> Saving { + match self { + Self::Artifacts | Self::BundledSkills | Self::ClaudeAiConnectors | Self::ScheduleWakeup | Self::AdvisorTool => Saving::High, + Self::GitInstructions | Self::ReportFindings | Self::ClaudeApiSkill | Self::BackgroundTasks | Self::ExplorePlanAgents => Saving::Medium, Self::Workflows - | Self::RemoteControl - | Self::PlanMode - | Self::AskUserQuestion - | Self::ScheduledTasks - | Self::RemoteTrigger - | Self::SendMessage - | Self::PushNotification - | Self::DesignSync - | Self::NotebookEdit - ) + | Self::RemoteControl + | Self::PlanMode + | Self::AskUserQuestion + | Self::ScheduledTasks + | Self::RemoteTrigger + | Self::SendMessage + | Self::PushNotification + | Self::DesignSync + | Self::NotebookEdit => Saving::Low, + } } fn effect(self) -> Effect { @@ -541,12 +571,25 @@ mod tests { } #[test] - fn only_the_switches_measured_under_100_tokens_are_tagged_as_saving_little() { - let tagged: Vec = Trim::ALL.into_iter().filter(|t| t.saves_little()).collect(); + fn each_switch_shows_the_saving_band_it_was_measured_in() { + let band = |saving: Saving| -> Vec { Trim::ALL.into_iter().filter(|t| t.saving() == saving).collect() }; + assert_eq!(band(Saving::High), [Artifacts, BundledSkills, ClaudeAiConnectors, AdvisorTool, ScheduleWakeup]); + assert_eq!(band(Saving::Medium), [ClaudeApiSkill, ExplorePlanAgents, BackgroundTasks, ReportFindings, GitInstructions]); assert_eq!( - tagged, + band(Saving::Low), [Workflows, RemoteControl, PlanMode, AskUserQuestion, ScheduledTasks, RemoteTrigger, SendMessage, PushNotification, DesignSync, NotebookEdit] ); + assert_eq!(Saving::Medium.label(), "medium savings"); + } + + #[test] + fn the_recommended_trims_are_added_to_what_the_user_already_turned_off() { + assert_eq!(with_recommended(&[]), [Artifacts, BundledSkills, ClaudeApiSkill, ClaudeAiConnectors, ScheduleWakeup, ReportFindings]); + assert_eq!( + with_recommended(&[PlanMode, Artifacts]), + [Artifacts, BundledSkills, ClaudeApiSkill, ClaudeAiConnectors, PlanMode, ScheduleWakeup, ReportFindings], + "the user's own trim stays, and nothing is listed twice" + ); } #[test] diff --git a/src/main.rs b/src/main.rs index c7eb116..19bfd8b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -252,10 +252,10 @@ fn main() { }) .expect("open setup window"); cx.subscribe(&setup, move |_, ev: &app::SetupEvent, cx| { - let app::SetupEvent::Done(claude_path) = ev else { return }; + let app::SetupEvent::Done { claude_path, recommended_trims } = ev else { return }; // The main window opens before the setup window closes: closing the last window quits the app. let (window, workspace) = open_main_window(initial.clone(), cx); - workspace.update(cx, |ws, cx| ws.apply_setup(claude_path.clone(), cx)); + workspace.update(cx, |ws, cx| ws.apply_setup(claude_path.clone(), *recommended_trims, cx)); *main.borrow_mut() = Some((window, workspace)); setup_window.update(cx, |_, window, _| window.remove_window()).ok(); }) diff --git a/src/panels/workspace_view.rs b/src/panels/workspace_view.rs index e2e030a..2067782 100644 --- a/src/panels/workspace_view.rs +++ b/src/panels/workspace_view.rs @@ -899,7 +899,7 @@ fn settings_body(page: SettingsPage, modal: &Modal, worktrees: &crate::app::Work for (heading, items) in Trim::GROUPS { list = list.child(div().mt(px(4.0)).child(section_label(heading.to_string()))); for &item in items { - let tag = item.saves_little().then_some("saves little"); + let tag = Some(item.saving().label()); list = list.child(switch_row(("settings-trim", item as usize), item.label(), tag, !trimmed.contains(&item), move |ws| { if let Some(Modal::Settings { trimmed, .. }) = ws.modal.as_mut() { flip(trimmed, item); From d3ace496dc43a3f08b8924c0e1a575d9ec321f83 Mon Sep 17 00:00:00 2001 From: Savin Angel-Mario Date: Sat, 7 Nov 2026 16:55:44 +0200 Subject: [PATCH 06/13] Add a token optimization section to the website The new Fig. 5 shows the tokens each Claude Code tools switch saved per request on Claude Code 2.1.319, and the real-task results: the first request went from 34.3k to 13.0k tokens, and every run passed all 30 hidden tests. The settings card now says 20 switches, each shown with its saving. --- web/src/pages/index.astro | 55 ++++++++++++++++++++++++++++++++++++++- web/src/styles/global.css | 10 +++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/web/src/pages/index.astro b/web/src/pages/index.astro index 20f36ef..08314e6 100644 --- a/web/src/pages/index.astro +++ b/web/src/pages/index.astro @@ -52,6 +52,7 @@ const calls = [ @@ -167,13 +168,65 @@ const calls = [

Settings, by category.

-

Defaults for new sessions, 15 switches for Claude Code's bundled tools, one for each Claudiu feature.

+

Defaults for new sessions, 20 switches for Claude Code's bundled tools with what each saves, one for each Claudiu feature.

Claudiu's settings dialog on the Claude Code tools page, listing switches for bundled skills, workflows, remote control, claude.ai connectors, artifacts and plan mode
+
+
Claudiu · token optimizationFig. 5 · measured on Claude Code 2.1.319
+ +
+

Fewer tokens in every request.

+

Each switch on the Claude Code tools page shows what turning it off saves: high, medium or low. Setup offers to turn off six that coding rarely uses.

+
+
+
Tokens saved per requestalone
+ {[ + ["Artifacts", "13,390", "100%"], + ["Bundled skills", "2,614", "19.5%"], + ["claude.ai connectors", "1,694", "12.7%"], + ["ScheduleWakeup", "1,692", "12.6%"], + ["Advisor tool, if set", "1,358", "10.1%"], + ["Git instructions", "830", "6.2%"], + ["ReportFindings", "822", "6.1%"], + ["Claude API skill", "464", "3.5%"], + ["Background tasks", "408", "3%"], + ["Explore and Plan agents", "334", "2.5%"], + ].map(([name, saved, v]) => ( +
+ {name} +
+ {saved} +
+ ))} +
+ Ten others + tools that load only on search + 0–68 +
+
+
+
+ +
+

Measured on a real task.

+

One change across 7 files, done by Sonnet 5.5 and graded by 30 tests the agent never saw.

+
+ + + + + + + +
First request34.3k tokens with no trims, 13.0k with the measured savers off
Hidden tests30 of 30 passed in every run, with or without trims
Whole run1.7% fewer input tokens, because the conversation is most of a long run
Output capsleft empty, since capped runs took 32 and 40 tool calls instead of 13 and 14
+
+
+
+
ClaudiuSpecifications

Specifications.

Claudiu owns the workspace. Claude Code owns the agent.

Built withRust and GPUI, not a web wrapper
Terminalone real PTY per session; typed into only for the editor's @path#L reference
Anthropic APInever called by Claudiu
Claude Code datatranscripts never deleted; settings change only when you flip a switch
NetworkGitHub only
Uploadsnone
After a restartrunning sessions come back
Download Windows, macOS and Linux
diff --git a/web/src/styles/global.css b/web/src/styles/global.css index 79bc783..8ab3ec3 100644 --- a/web/src/styles/global.css +++ b/web/src/styles/global.css @@ -451,6 +451,12 @@ grid-template-columns: minmax(0, 1fr); grid-template-areas: "tb" "sp"; } + .win.tok { + grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); + grid-template-areas: "tb tb" "t1 t2"; + } + .win .t1 { grid-area: t1; } + .win .t2 { grid-area: t2; } .win .e1 { grid-area: e1; } .win .l1 { grid-area: l1; } .win .a1 { grid-area: a1; } @@ -487,6 +493,10 @@ grid-template-columns: minmax(0, 1fr); grid-template-areas: "tb" "r1" "r2" "r3"; } + .win.tok { + grid-template-columns: minmax(0, 1fr); + grid-template-areas: "tb" "t1" "t2"; + } .win .sp { grid-template-columns: minmax(0, 1fr); } From eca5a3b4ecb45f6605422542f26e612edf23e4fa Mon Sep 17 00:00:00 2001 From: Savin Angel-Mario Date: Sat, 7 Nov 2026 16:58:48 +0200 Subject: [PATCH 07/13] Show the token optimization results as bars instead of each trim Fig. 5 now compares a run with no trims against one with the nine measured savers off: first request tokens, hidden tests passed and tool calls. --- web/src/pages/index.astro | 42 +++++++++++++++------------------------ web/src/styles/global.css | 11 ++++++++++ 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/web/src/pages/index.astro b/web/src/pages/index.astro index 08314e6..f421b56 100644 --- a/web/src/pages/index.astro +++ b/web/src/pages/index.astro @@ -180,46 +180,36 @@ const calls = [

Fewer tokens in every request.

-

Each switch on the Claude Code tools page shows what turning it off saves: high, medium or low. Setup offers to turn off six that coding rarely uses.

+

Each switch on the Claude Code tools page shows what turning it off saves: high, medium or low. Setup offers to turn off six that coding rarely uses. Measured on Claude Code 2.1.319 with Sonnet 5.5, on one change across 7 files graded by 30 hidden tests.

-
Tokens saved per requestalone
+
No trims9 measured savers off
{[ - ["Artifacts", "13,390", "100%"], - ["Bundled skills", "2,614", "19.5%"], - ["claude.ai connectors", "1,694", "12.7%"], - ["ScheduleWakeup", "1,692", "12.6%"], - ["Advisor tool, if set", "1,358", "10.1%"], - ["Git instructions", "830", "6.2%"], - ["ReportFindings", "822", "6.1%"], - ["Claude API skill", "464", "3.5%"], - ["Background tasks", "408", "3%"], - ["Explore and Plan agents", "334", "2.5%"], - ].map(([name, saved, v]) => ( -
- {name} -
- {saved} + ["First request, tokens", [["34.3k", "100%", true], ["13.0k", "37.9%", false]]], + ["Hidden tests passed", [["30 / 30", "100%", true], ["30 / 30", "100%", false]]], + ["Tool calls", [["13–14", "100%", true], ["14", "100%", false]]], + ].map(([label, bars]) => ( +
+
{label}
+ {bars.map(([value, v, off]) => ( +
+
+ {value} +
+ ))}
))} -
- Ten others - tools that load only on search - 0–68 -

Measured on a real task.

-

One change across 7 files, done by Sonnet 5.5 and graded by 30 tests the agent never saw.

+

Two things the bars don't show.

- - - +
First request34.3k tokens with no trims, 13.0k with the measured savers off
Hidden tests30 of 30 passed in every run, with or without trims
Whole run1.7% fewer input tokens, because the conversation is most of a long run
Whole run1.7% fewer input tokens than with a few trims, because the conversation is most of a long run
Output capsleft empty, since capped runs took 32 and 40 tool calls instead of 13 and 14
diff --git a/web/src/styles/global.css b/web/src/styles/global.css index 8ab3ec3..1b98f6b 100644 --- a/web/src/styles/global.css +++ b/web/src/styles/global.css @@ -338,6 +338,17 @@ width: var(--v); background: var(--color-ink); } + .meter.off i { + background: var(--color-faint); + } + .swatch { + width: 10px; + height: 10px; + background: var(--color-ink); + } + .swatch.off { + background: var(--color-faint); + } .scale { display: flex; justify-content: space-between; From 7ff298317a4535b8ad549f4a8b3155c06c1fe73c Mon Sep 17 00:00:00 2001 From: Savin Angel-Mario Date: Sat, 7 Nov 2026 16:59:23 +0200 Subject: [PATCH 08/13] Draw the trimmed run's bars in the accent color --- web/src/pages/index.astro | 2 +- web/src/styles/global.css | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/web/src/pages/index.astro b/web/src/pages/index.astro index f421b56..0a5ee7f 100644 --- a/web/src/pages/index.astro +++ b/web/src/pages/index.astro @@ -193,7 +193,7 @@ const calls = [
{label}
{bars.map(([value, v, off]) => (
-
+
{value}
))} diff --git a/web/src/styles/global.css b/web/src/styles/global.css index 1b98f6b..c6e973d 100644 --- a/web/src/styles/global.css +++ b/web/src/styles/global.css @@ -341,10 +341,13 @@ .meter.off i { background: var(--color-faint); } + .meter.accent i { + background: var(--color-orange); + } .swatch { width: 10px; height: 10px; - background: var(--color-ink); + background: var(--color-orange); } .swatch.off { background: var(--color-faint); From 092f626de46c953a92383832fcf4d7d0bdb9b13a Mon Sep 17 00:00:00 2001 From: Savin Angel-Mario Date: Sat, 7 Nov 2026 17:03:15 +0200 Subject: [PATCH 09/13] Lead the token results with the per-request saving and drop the running window The real-task panel now says each request carries 21,300 fewer tokens, which works out to about 300,000 over a 14-call task with the same tests passing. The Scrolling, Quiet and Settings cards are gone, so token optimization is Fig. 4. --- web/src/pages/index.astro | 31 ++++--------------------------- web/src/styles/global.css | 11 ----------- 2 files changed, 4 insertions(+), 38 deletions(-) diff --git a/web/src/pages/index.astro b/web/src/pages/index.astro index 0a5ee7f..7e51479 100644 --- a/web/src/pages/index.astro +++ b/web/src/pages/index.astro @@ -151,32 +151,8 @@ const calls = [
-
-
Claudiu · runningFig. 4 · under load
- -
-

Scrolling that keeps up.

-

Wheel and trackpad glide in the terminal, sidebars and editor, and the editor no longer overshoots its ends.

- -
- -
-

Quiet when nothing happens.

-

The list draws only the rows in view, an idle window doesn't redraw, and saves happen in the background. On Windows, claude runs at above-normal priority.

- -
- -
-

Settings, by category.

-

Defaults for new sessions, 20 switches for Claude Code's bundled tools with what each saves, one for each Claudiu feature.

-
- Claudiu's settings dialog on the Claude Code tools page, listing switches for bundled skills, workflows, remote control, claude.ai connectors, artifacts and plan mode -
-
-
-
-
Claudiu · token optimizationFig. 5 · measured on Claude Code 2.1.319
+
Claudiu · token optimizationFig. 4 · measured on Claude Code 2.1.319

Fewer tokens in every request.

@@ -205,11 +181,12 @@ const calls = [

Measured on a real task.

-

Two things the bars don't show.

+

What the smaller request adds up to.

- + +
Whole run1.7% fewer input tokens than with a few trims, because the conversation is most of a long run
Every request21,300 fewer tokens, because Claude Code sends its tools and instructions again with every call
A 14-call taskworks out to about 300,000 fewer tokens, with the same 30 tests passing
Output capsleft empty, since capped runs took 32 and 40 tool calls instead of 13 and 14
diff --git a/web/src/styles/global.css b/web/src/styles/global.css index c6e973d..4893a7c 100644 --- a/web/src/styles/global.css +++ b/web/src/styles/global.css @@ -454,10 +454,6 @@ grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "tb tb" "e1 e1" "l1 a1"; } - .win.run { - grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); - grid-template-areas: "tb tb" "r1 r3" "r2 r3"; - } .win.ed .l1 figure { margin-top: 0; } @@ -474,9 +470,6 @@ .win .e1 { grid-area: e1; } .win .l1 { grid-area: l1; } .win .a1 { grid-area: a1; } - .win .r1 { grid-area: r1; } - .win .r2 { grid-area: r2; } - .win .r3 { grid-area: r3; } .win .sp { grid-area: sp; display: grid; @@ -503,10 +496,6 @@ grid-template-columns: minmax(0, 1fr); grid-template-areas: "tb" "e1" "l1" "a1"; } - .win.run { - grid-template-columns: minmax(0, 1fr); - grid-template-areas: "tb" "r1" "r2" "r3"; - } .win.tok { grid-template-columns: minmax(0, 1fr); grid-template-areas: "tb" "t1" "t2"; From 94a772e9e76788466b01fbc7e1ceb912d69f68b3 Mon Sep 17 00:00:00 2001 From: Savin Angel-Mario Date: Sat, 7 Nov 2026 17:07:09 +0200 Subject: [PATCH 10/13] Draw the token saving to scale on the website Fig. 4 is now one wide drawing in the manual's own style. A request with no trims (34.3k tokens) sits above one with the savers off (13.0k), the 21,300 cut is hatched and dimensioned in orange, and the same cut repeats down 14 calls to about 300,000 tokens never sent. The heading leads with the number, and a spec table keeps the hidden tests, tool calls, output caps and test setup. --- web/src/pages/index.astro | 87 +++++++++++++++++++++-------------- web/src/styles/global.css | 95 ++++++++++++++++++++++++++++++--------- 2 files changed, 128 insertions(+), 54 deletions(-) diff --git a/web/src/pages/index.astro b/web/src/pages/index.astro index 7e51479..a74afc2 100644 --- a/web/src/pages/index.astro +++ b/web/src/pages/index.astro @@ -152,44 +152,63 @@ const calls = [
-
Claudiu · token optimizationFig. 4 · measured on Claude Code 2.1.319
- -
-

Fewer tokens in every request.

-

Each switch on the Claude Code tools page shows what turning it off saves: high, medium or low. Setup offers to turn off six that coding rarely uses. Measured on Claude Code 2.1.319 with Sonnet 5.5, on one change across 7 files graded by 30 hidden tests.

-
-
-
No trims9 measured savers off
- {[ - ["First request, tokens", [["34.3k", "100%", true], ["13.0k", "37.9%", false]]], - ["Hidden tests passed", [["30 / 30", "100%", true], ["30 / 30", "100%", false]]], - ["Tool calls", [["13–14", "100%", true], ["14", "100%", false]]], - ].map(([label, bars]) => ( -
-
{label}
- {bars.map(([value, v, off]) => ( -
-
- {value} -
- ))} -
- ))} -
-
-
- -
-

Measured on a real task.

-

What the smaller request adds up to.

-
+
Claudiu · token optimizationFig. 4 · one request, drawn to scale
+ +
+
+

−21,300 tokens. Every request.

+

+ Claude Code sends its tools and instructions again with every call. The nine switches that measured + highest cut a first request from 34.3k tokens to 13.0k. Over a 14-call task that works out to about + 300,000 tokens never sent, and the work came out just as correct. +

- - - + + + +
Every request21,300 fewer tokens, because Claude Code sends its tools and instructions again with every call
A 14-call taskworks out to about 300,000 fewer tokens, with the same 30 tests passing
Output capsleft empty, since capped runs took 32 and 40 tool calls instead of 13 and 14
Hidden tests30 of 30 passed, before and after
Tool calls13–14 before, 14 after
Output capsleft empty, since capped runs took 32 and 40 calls
Measured onClaude Code 2.1.319, Sonnet 5.5, one change across 7 files
+
+ +
+ + A first request drawn to scale: 34.3k tokens with no trims, 13.0k with them; the 21,300 tokens cut are hatched, and the same cut repeats on each of 14 calls + + + + + + + + + + No trims + + + 34.3k tokens + + Savers off + + + 13.0k + + + + + + + + + −21,300 per request + + Each of 14 calls + + + ≈ 300,000 never sent + +

Fig. 4Hatched: what the trims remove from every request.

diff --git a/web/src/styles/global.css b/web/src/styles/global.css index 4893a7c..e6b7a61 100644 --- a/web/src/styles/global.css +++ b/web/src/styles/global.css @@ -338,20 +338,6 @@ width: var(--v); background: var(--color-ink); } - .meter.off i { - background: var(--color-faint); - } - .meter.accent i { - background: var(--color-orange); - } - .swatch { - width: 10px; - height: 10px; - background: var(--color-orange); - } - .swatch.off { - background: var(--color-faint); - } .scale { display: flex; justify-content: space-between; @@ -462,11 +448,79 @@ grid-template-areas: "tb" "sp"; } .win.tok { - grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); - grid-template-areas: "tb tb" "t1 t2"; + grid-template-columns: minmax(0, 1fr); + grid-template-areas: "tb" "tk"; + } + .win .tk { + grid-area: tk; + display: grid; + grid-template-columns: minmax(0, 4fr) minmax(0, 7fr); + column-gap: 56px; + align-items: center; + padding-block: 40px; + } + .tk-copy { + display: flex; + flex-direction: column; + gap: 22px; + } + .win .tk h2 { + font-size: clamp(40px, 5.2vw, 76px); + line-height: 0.95; + letter-spacing: -0.04em; + } + .tk-num { + display: block; + color: var(--color-orange); + } + .tk-fig svg { + display: block; + width: 100%; + height: auto; + } + .tk-fig .t-lbl { + font: 600 20px var(--font-sans); + letter-spacing: 0.08em; + text-transform: uppercase; + fill: var(--color-dim); + } + .tk-fig .t-in { + font: 700 26px var(--font-sans); + fill: var(--color-ink); + } + .tk-fig .t-in.dark { + fill: var(--color-paper); + } + @media (max-width: 640px) { + .tk-fig .t-lbl { + font-size: 36px; + } + .tk-fig .t-in { + font-size: 38px; + } + .tk-fig .t-cut { + font-size: 46px; + } + } + .tk-fig .t-cut { + font: 800 34px var(--font-sans); + letter-spacing: -0.02em; + fill: var(--color-orange); + } + @media (prefers-reduced-motion: no-preference) { + @supports (animation-timeline: view()) { + .tk-fig .cut { + animation: tk-cut linear both; + animation-timeline: view(); + animation-range: entry 20% cover 45%; + } + @keyframes tk-cut { + from { + clip-path: inset(0 100% 0 0); + } + } + } } - .win .t1 { grid-area: t1; } - .win .t2 { grid-area: t2; } .win .e1 { grid-area: e1; } .win .l1 { grid-area: l1; } .win .a1 { grid-area: a1; } @@ -496,9 +550,10 @@ grid-template-columns: minmax(0, 1fr); grid-template-areas: "tb" "e1" "l1" "a1"; } - .win.tok { + .win .tk { grid-template-columns: minmax(0, 1fr); - grid-template-areas: "tb" "t1" "t2"; + row-gap: 36px; + padding-block: 28px; } .win .sp { grid-template-columns: minmax(0, 1fr); From 6138143e1cb4ac07f12c2500138edcaf18634927 Mon Sep 17 00:00:00 2001 From: Savin Angel-Mario Date: Sat, 7 Nov 2026 17:20:41 +0200 Subject: [PATCH 11/13] Keep the setup window's buttons in view and shorten the trims card The setup window has a fixed 560 by 620 size, and the Recommended trims card added in 96f1cd0 made the cards taller than that, so Check again and Continue were cut off. The cards now scroll between the fixed header and the buttons, which also covers a large UI scale or a long error. The trims card is one line: its title with the On/Off state, and a short note that Settings changes it later. The whole card toggles. --- src/app/setup.rs | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/src/app/setup.rs b/src/app/setup.rs index 69ca39d..6e2cf48 100644 --- a/src/app/setup.rs +++ b/src/app/setup.rs @@ -82,6 +82,9 @@ pub struct SetupView { reload_path: fn(), /// The "recommended trims" switch; off until the user turns it on. recommended_trims: bool, + /// The cards scroll under a fixed header and buttons: the window has one size, and UI scale or a long error can + /// make them taller than it. + body_scroll: crate::panels::glide::Smooth, done: bool, } @@ -110,7 +113,7 @@ impl SetupView { view.update(cx, |view, cx| view.close(window, cx)).is_err() }); } - let mut view = Self { mode, path_input, configured: current, path_error: None, checked: None, asked_again: false, checks: 0, reload_path, recommended_trims: false, done: false }; + let mut view = Self { mode, path_input, configured: current, path_error: None, checked: None, asked_again: false, checks: 0, reload_path, recommended_trims: false, body_scroll: Default::default(), done: false }; view.run_checks(cx); view } @@ -226,26 +229,21 @@ impl SetupView { fn trims_row(&self, cx: &mut Context) -> impl IntoElement { let on = self.recommended_trims; card() - .child(tool_title("Recommended trims", "OPTIONAL")) + .id("setup-recommended-trims") + .cursor_pointer() .child( div() - .id("setup-recommended-trims") .flex() .items_center() .justify_between() - .gap(px(12.0)) - .cursor_pointer() - .text_size(crate::panels::scale::px(13.0)) - .child(div().min_w_0().child( - "Turn off Claude Code features that add tokens to every request and that coding rarely uses: Artifacts, bundled skills, claude.ai connectors, ScheduleWakeup, ReportFindings and the Claude API skill.", - )) - .child(div().flex_none().text_color(hsla(if on { theme::ACCENT } else { theme::TEXT_FAINT })).child(if on { "On" } else { "Off" })) - .on_click(cx.listener(|view, _: &ClickEvent, _, cx| { - view.recommended_trims = !view.recommended_trims; - cx.notify(); - })), + .child(tool_title("Recommended trims", "OPTIONAL")) + .child(div().text_size(crate::panels::scale::px(13.0)).text_color(hsla(if on { theme::ACCENT } else { theme::TEXT_FAINT })).child(if on { "On" } else { "Off" })), ) - .child(faint("Settings → Claude Code tools changes them later. This edits Claude Code's own settings.json.")) + .child(faint("Fewer tokens in every request. Change it later in Settings → Claude Code tools.")) + .on_click(cx.listener(|view, _: &ClickEvent, _, cx| { + view.recommended_trims = !view.recommended_trims; + cx.notify(); + })) } fn claude_row(&self, cx: &mut Context) -> impl IntoElement { @@ -301,7 +299,7 @@ impl SetupView { } impl Render for SetupView { - fn render(&mut self, _: &mut Window, cx: &mut Context) -> impl IntoElement { + fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { let primary = if self.mode == Mode::Reopened { button("setup-done", "Close", true).on_click(cx.listener(|view, _: &ClickEvent, window, cx| view.close(window, cx))) } else if self.can_continue() { @@ -331,11 +329,18 @@ impl Render for SetupView { .child("Claudiu runs your own claude and reaches GitHub through your own gh. It installs nothing; this page only checks that they are there."), ), ) - .child(self.claude_row(cx)) - .child(self.gh_row(cx)) - .children(self.needs_restart_hint().then(|| faint(STILL_MISSING))) - .child(self.trims_row(cx)) - .child(div().flex_1()) + .child( + self.body_scroll.wire(div().id("setup-body").flex_1().min_h_0(), window).child( + div() + .flex() + .flex_col() + .gap(px(14.0)) + .child(self.claude_row(cx)) + .child(self.gh_row(cx)) + .children(self.needs_restart_hint().then(|| faint(STILL_MISSING))) + .child(self.trims_row(cx)), + ), + ) .child( div() .flex() From 1ebdbfc20dd7bc79f16614ccff0ac420fd17d447 Mon Sep 17 00:00:00 2001 From: Savin Angel-Mario Date: Sat, 7 Nov 2026 17:31:44 +0200 Subject: [PATCH 12/13] Remove the Bash output and file read caps In measured runs on Claude Code 2.1.319, every cap made Claude use more tokens, not fewer. With a 10,000-character Bash cap, Claude's usual batched reads were cut short, so it re-read them in smaller calls: 30 tool calls instead of 14 and twice the input tokens. The Claude Code tools page now keeps only the skills field, under a SKILLS heading, and the website drops its caps row. A cap an earlier build wrote to settings.json still comes out on the next save that changes the trims. --- src/app/mod.rs | 11 ++--- src/app/modal.rs | 13 ++--- src/app/settings.rs | 4 +- src/claude/trim.rs | 96 ++++++++++++++---------------------- src/panels/workspace_view.rs | 9 ++-- web/src/pages/index.astro | 1 - 6 files changed, 50 insertions(+), 84 deletions(-) diff --git a/src/app/mod.rs b/src/app/mod.rs index cf45308..160cbe6 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -306,7 +306,7 @@ pub enum Modal { /// Claudiu tools turned off (Claudiu tools page). claudiu_off: Vec, /// Bash output cap, file read cap and skills to turn off, in that order (Claude Code tools page). - limit_fields: [Entity; 3], + skills_field: Entity, /// Settings found at open time that make Claude Code cost more (Claude Code tools page). costly: Vec, /// Focus of the category list, which has the keyboard when the dialog opens. @@ -797,16 +797,11 @@ impl Workspace { let claude = self.modal_input(&claude_t, &claude_hint, window, cx); let model = self.modal_input(defaults.model.as_deref().unwrap_or_default(), "Claude Code default", window, cx); let shell = self.modal_input(&shell_t, &platform::default_shell(None).0, window, cx); - let (bash_t, file_t, skills_t) = self.store.data.settings.limits.texts(); - let limit_fields = [ - self.modal_input(&bash_t, "Claude Code default (30000)", window, cx), - self.modal_input(&file_t, "Claude Code default", window, cx), - self.modal_input(&skills_t, "none, e.g. dataviz, claude-api", window, cx), - ]; + let skills_field = self.modal_input(&self.store.data.settings.limits.text(), "none, e.g. dataviz, claude-api", window, cx); let list_focus = cx.focus_handle(); window.focus(&list_focus, cx); self.set_settings_page(self.settings_page, cx); - self.modal = Some(Modal::Settings { shell, claude, model, effort: defaults.effort, permission: defaults.permission_mode, updates, chrome, scale: crate::panels::scale::percent(), trimmed: self.store.data.settings.trimmed_tools.clone(), claudiu_off: self.store.data.settings.claudiu_tools_off.clone(), limit_fields, costly: claude::costly::scan(), list_focus }); + self.modal = Some(Modal::Settings { shell, claude, model, effort: defaults.effort, permission: defaults.permission_mode, updates, chrome, scale: crate::panels::scale::percent(), trimmed: self.store.data.settings.trimmed_tools.clone(), claudiu_off: self.store.data.settings.claudiu_tools_off.clone(), skills_field, costly: claude::costly::scan(), list_focus }); } Act::PickEffort(choice) => { if let Some(Modal::Settings { effort, .. }) = self.modal.as_mut() { diff --git a/src/app/modal.rs b/src/app/modal.rs index a902ea1..68b1ce6 100644 --- a/src/app/modal.rs +++ b/src/app/modal.rs @@ -108,7 +108,7 @@ impl Workspace { } } } - Some(Modal::Settings { shell, claude, model, effort, permission, updates, chrome, scale, trimmed, claudiu_off, limit_fields, costly, list_focus }) => { + Some(Modal::Settings { shell, claude, model, effort, permission, updates, chrome, scale, trimmed, claudiu_off, skills_field, costly, list_focus }) => { let clean = |s: &str| s.trim().trim_matches('"').to_string(); let (shell_t, claude_t) = (clean(shell.read(cx).value().as_ref()), clean(claude.read(cx).value().as_ref())); let model_name = claude::defaults::parse_model(model.read(cx).value().as_ref()); @@ -118,17 +118,12 @@ impl Workspace { .find(|(_, _, t)| !t.is_empty() && platform::resolve_program(t).is_none()) .map(|(what, field, t)| (SettingsPage::General, field.clone(), format!("{what}: “{t}” is not a file or a program on PATH"))); let bad_model = model_name.is_err().then(|| (SettingsPage::Sessions, model.clone(), "Use a model alias or id (letters, digits, . _ -).".to_string())); - let [bash_field, file_field, skills_field] = &limit_fields; - let limits = claude::trim::Limits::parse(bash_field.read(cx).value().as_ref(), file_field.read(cx).value().as_ref(), skills_field.read(cx).value().as_ref()); - // The parser's message starts with the field it blames, which says which of the three to focus. - let bad_limits = limits.as_ref().err().map(|why| { - let field = if why.starts_with("Bash") { bash_field } else if why.starts_with("File") { file_field } else { skills_field }; - (SettingsPage::ClaudeTools, field.clone(), why.clone()) - }); + let limits = claude::trim::Limits::parse(skills_field.read(cx).value().as_ref()); + let bad_limits = limits.as_ref().err().map(|why| (SettingsPage::ClaudeTools, skills_field.clone(), why.clone())); if let Some((page, field, msg)) = paths.or(bad_model).or(bad_limits) { self.settings_page = page; field.update(cx, |s, cx| s.focus(window, cx)); - self.modal = Some(Modal::Settings { shell, claude, model, effort, permission, updates, chrome, scale, trimmed, claudiu_off, limit_fields, costly, list_focus }); + self.modal = Some(Modal::Settings { shell, claude, model, effort, permission, updates, chrome, scale, trimmed, claudiu_off, skills_field, costly, list_focus }); self.toast(msg, true, cx); return; } diff --git a/src/app/settings.rs b/src/app/settings.rs index 60f31f8..568a0dd 100644 --- a/src/app/settings.rs +++ b/src/app/settings.rs @@ -46,12 +46,12 @@ impl Workspace { /// Keys for the open Settings dialog, seen before the focused control. Up and Down change the page and Enter saves /// only while the category list has focus; Tab and Shift+Tab cycle the list and the current page's text fields. pub(crate) fn settings_key(&mut self, ev: &KeyDownEvent, window: &mut Window, cx: &mut Context) { - let Some(Modal::Settings { shell, claude, model, limit_fields, list_focus, .. }) = &self.modal else { return }; + let Some(Modal::Settings { shell, claude, model, skills_field, list_focus, .. }) = &self.modal else { return }; let list_focus = list_focus.clone(); let fields = match self.settings_page { SettingsPage::General => vec![shell.clone(), claude.clone()], SettingsPage::Sessions => vec![model.clone()], - SettingsPage::ClaudeTools => limit_fields.to_vec(), + SettingsPage::ClaudeTools => vec![skills_field.clone()], _ => Vec::new(), }; let on_list = list_focus.is_focused(window); diff --git a/src/claude/trim.rs b/src/claude/trim.rs index 2cfdb2a..ff486bb 100644 --- a/src/claude/trim.rs +++ b/src/claude/trim.rs @@ -206,8 +206,7 @@ impl Entry { } } - /// The entry an earlier `id` stood for, so it can be taken out again. The value is part of an env id because the - /// caps change between saves. + /// The entry an earlier `id` stood for, so it can be taken out again. fn from_id(id: &str) -> Option { if let Some(rest) = id.strip_prefix("env:") { let (name, value) = rest.split_once('=')?; @@ -310,27 +309,21 @@ fn remove(settings: &mut Map, entry: &Entry) { } } -/// The caps and skills the user set on the Claude Code tools page. Empty means Claude Code's own behavior. +/// The skills the user turned off on the Claude Code tools page. Empty leaves Claude Code's own behavior. +/// +/// There are no output caps (`BASH_MAX_OUTPUT_LENGTH`, `CLAUDE_CODE_FILE_READ_MAX_OUTPUT_TOKENS`): in measured runs on +/// Claude Code 2.1.319, even a 10,000-character Bash cap cut Claude's normal batched reads, so it re-read them in +/// smaller calls and used twice the tokens. #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] pub struct Limits { - /// Most characters of a Bash command's output that reach the model (`BASH_MAX_OUTPUT_LENGTH`). - #[serde(default)] - pub bash_output: Option, - /// Most tokens a single file read returns (`CLAUDE_CODE_FILE_READ_MAX_OUTPUT_TOKENS`). - #[serde(default)] - pub file_read_tokens: Option, /// Skills Claude no longer sees (`skillOverrides` set to `off`); the user can still type them. #[serde(default)] pub skills_off: Vec, } impl Limits { - /// The page's three text fields. Empty text leaves a cap unset. Skills are separated by commas or spaces. - pub fn parse(bash_output: &str, file_read_tokens: &str, skills: &str) -> Result { - let number = |what: &str, text: &str| match text.trim() { - "" => Ok(None), - t => t.parse::().ok().filter(|n| *n > 0).map(Some).ok_or(format!("{what}: use a whole number above 0, or leave it empty.")), - }; + /// The page's skills field: names separated by commas or spaces. + pub fn parse(skills: &str) -> Result { let mut skills_off: Vec = vec![]; for name in skills.split([',', ' ', '\n']).map(str::trim).filter(|n| !n.is_empty()) { let valid = name.chars().all(|c| c.is_ascii_alphanumeric() || matches!(c, '-' | '_' | ':' | '.')); @@ -341,19 +334,16 @@ impl Limits { skills_off.push(name.to_string()); } } - Ok(Limits { bash_output: number("Bash output", bash_output)?, file_read_tokens: number("File reads", file_read_tokens)?, skills_off }) + Ok(Limits { skills_off }) } - /// The fields as text, for the page. - pub fn texts(&self) -> (String, String, String) { - let number = |n: Option| n.map(|n| n.to_string()).unwrap_or_default(); - (number(self.bash_output), number(self.file_read_tokens), self.skills_off.join(", ")) + /// The skills field as text, for the page. + pub fn text(&self) -> String { + self.skills_off.join(", ") } fn entries(&self) -> Vec { - let env = |name: &str, n: Option| n.map(|n| Entry::Env(name.into(), n.to_string())); - let caps = [env("BASH_MAX_OUTPUT_LENGTH", self.bash_output), env("CLAUDE_CODE_FILE_READ_MAX_OUTPUT_TOKENS", self.file_read_tokens)]; - caps.into_iter().flatten().chain(self.skills_off.iter().map(|name| Entry::Skill(name.clone()))).collect() + self.skills_off.iter().map(|name| Entry::Skill(name.clone())).collect() } } @@ -512,62 +502,52 @@ mod tests { assert_eq!(Value::Object(s), json!({ "model": "sonnet" })); } - fn limits(bash: Option, file: Option, skills: &[&str]) -> Limits { - Limits { bash_output: bash, file_read_tokens: file, skills_off: skills.iter().map(|s| s.to_string()).collect() } + fn skills(names: &[&str]) -> Limits { + Limits { skills_off: names.iter().map(|s| s.to_string()).collect() } } #[test] - fn caps_and_skills_go_where_claude_code_reads_them() { + fn skills_turned_off_go_where_claude_code_reads_them() { let mut s = object(json!({ "skillOverrides": { "loop": "user-invocable-only" } })); - apply(&mut s, &[], &limits(Some(2000), Some(5000), &["dataviz", "m4:do"]), &[]); - assert_eq!( - Value::Object(s), - json!({ - "env": { "BASH_MAX_OUTPUT_LENGTH": "2000", "CLAUDE_CODE_FILE_READ_MAX_OUTPUT_TOKENS": "5000" }, - "skillOverrides": { "loop": "user-invocable-only", "dataviz": "off", "m4:do": "off" } - }) - ); + apply(&mut s, &[], &skills(&["dataviz", "m4:do"]), &[]); + assert_eq!(Value::Object(s), json!({ "skillOverrides": { "loop": "user-invocable-only", "dataviz": "off", "m4:do": "off" } })); } #[test] - fn changing_a_cap_replaces_the_old_value_and_clearing_it_removes_it() { - let mut s = Map::new(); - let owned = apply(&mut s, &[], &limits(Some(2000), None, &[]), &[]); - let owned = apply(&mut s, &[], &limits(Some(3000), None, &[]), &owned); - assert_eq!(Value::Object(s.clone()), json!({ "env": { "BASH_MAX_OUTPUT_LENGTH": "3000" } })); - apply(&mut s, &[], &Limits::default(), &owned); - assert!(s.is_empty()); - } - - #[test] - fn a_cap_or_skill_the_user_set_differently_is_kept_and_never_removed() { - let mut s = object(json!({ "env": { "BASH_MAX_OUTPUT_LENGTH": "9000" }, "skillOverrides": { "dataviz": "user-invocable-only" } })); - let owned = apply(&mut s, &[], &limits(Some(2000), None, &["dataviz"]), &[]); + fn a_skill_the_user_set_differently_is_kept_and_never_removed() { + let mut s = object(json!({ "skillOverrides": { "dataviz": "user-invocable-only" } })); + let owned = apply(&mut s, &[], &skills(&["dataviz"]), &[]); assert!(owned.is_empty(), "nothing was added, so nothing is claimed"); apply(&mut s, &[], &Limits::default(), &owned); - assert_eq!(Value::Object(s), json!({ "env": { "BASH_MAX_OUTPUT_LENGTH": "9000" }, "skillOverrides": { "dataviz": "user-invocable-only" } })); + assert_eq!(Value::Object(s), json!({ "skillOverrides": { "dataviz": "user-invocable-only" } })); } #[test] fn turning_a_skill_back_on_removes_the_override_and_an_empty_block() { let mut s = Map::new(); - let owned = apply(&mut s, &[], &limits(None, None, &["dataviz"]), &[]); - apply(&mut s, &[], &limits(None, None, &[]), &owned); + let owned = apply(&mut s, &[], &skills(&["dataviz"]), &[]); + apply(&mut s, &[], &skills(&[]), &owned); assert!(s.is_empty()); } #[test] - fn the_limit_fields_are_parsed_with_empty_meaning_unset() { - assert_eq!(Limits::parse("", " ", "").unwrap(), Limits::default()); - assert_eq!(Limits::parse("2000", "5000", "dataviz, m4:do dataviz").unwrap(), limits(Some(2000), Some(5000), &["dataviz", "m4:do"])); - assert!(Limits::parse("0", "", "").unwrap_err().starts_with("Bash output")); - assert!(Limits::parse("", "ten", "").unwrap_err().starts_with("File reads")); - assert!(Limits::parse("", "", "a/b").unwrap_err().starts_with("Skills")); + fn the_skills_field_is_parsed_with_empty_meaning_none() { + assert_eq!(Limits::parse(" ").unwrap(), Limits::default()); + assert_eq!(Limits::parse("dataviz, m4:do dataviz").unwrap(), skills(&["dataviz", "m4:do"])); + assert!(Limits::parse("a/b").unwrap_err().starts_with("Skills")); + } + + #[test] + fn a_cap_written_by_an_earlier_build_is_taken_out_on_the_next_save() { + let mut s = object(json!({ "env": { "BASH_MAX_OUTPUT_LENGTH": "2000", "FOO": "1" } })); + let owned = apply(&mut s, &[], &Limits::default(), &["env:BASH_MAX_OUTPUT_LENGTH=2000".to_string()]); + assert!(owned.is_empty()); + assert_eq!(Value::Object(s), json!({ "env": { "FOO": "1" } })); } #[test] - fn the_fields_show_the_saved_limits_as_text() { - assert_eq!(limits(Some(2000), None, &["a", "b"]).texts(), ("2000".to_string(), String::new(), "a, b".to_string())); + fn the_field_shows_the_saved_skills_as_text() { + assert_eq!(skills(&["a", "b"]).text(), "a, b"); } #[test] diff --git a/src/panels/workspace_view.rs b/src/panels/workspace_view.rs index 2067782..e3d6c2a 100644 --- a/src/panels/workspace_view.rs +++ b/src/panels/workspace_view.rs @@ -822,7 +822,7 @@ impl Render for Workspace { /// The Settings dialog's body: the category list on the left and the chosen page on the right. fn settings_body(page: SettingsPage, modal: &Modal, worktrees: &crate::app::WorktreesPage, scroll: &crate::panels::glide::Smooth, window: &mut Window, cx: &mut Context) -> AnyElement { - let Modal::Settings { shell, claude, model, effort, permission, updates, chrome, scale, trimmed, claudiu_off, limit_fields, costly, list_focus } = modal else { + let Modal::Settings { shell, claude, model, effort, permission, updates, chrome, scale, trimmed, claudiu_off, skills_field, costly, list_focus } = modal else { return div().into_any_element(); }; let (updates, chrome, scale) = (*updates, *chrome, *scale); @@ -910,11 +910,8 @@ fn settings_body(page: SettingsPage, modal: &Modal, worktrees: &crate::app::Work if plan_trimmed { list = list.child(faint("With Plan mode off, Claude can't leave plan mode itself; press Shift+Tab.".to_string())); } - let [bash_field, file_field, skills_field] = limit_fields; - list.child(div().mt(px(4.0)).child(section_label("LIMITS".to_string()))) - .child(faint("Leave a field empty to keep Claude Code's own behavior. A value you already set in Claude Code's settings.json wins.".to_string())) - .child(field("BASH OUTPUT, MOST CHARACTERS", bash_field)) - .child(field("FILE READ, MOST TOKENS", file_field)) + list.child(div().mt(px(4.0)).child(section_label("SKILLS".to_string()))) + .child(faint("Claude no longer sees these skills, but you can still type them. A setting you already have for a skill in Claude Code's settings.json wins.".to_string())) .child(field("SKILLS TO TURN OFF, SEPARATED BY COMMAS", skills_field)) } SettingsPage::ClaudiuTools => { diff --git a/web/src/pages/index.astro b/web/src/pages/index.astro index a74afc2..be6a9c8 100644 --- a/web/src/pages/index.astro +++ b/web/src/pages/index.astro @@ -166,7 +166,6 @@ const calls = [ Hidden tests30 of 30 passed, before and after Tool calls13–14 before, 14 after - Output capsleft empty, since capped runs took 32 and 40 calls Measured onClaude Code 2.1.319, Sonnet 5.5, one change across 7 files From ddc4d841267179b0a922de61a0fcf1abceef04eb Mon Sep 17 00:00:00 2001 From: Savin Angel-Mario Date: Sat, 7 Nov 2026 17:38:53 +0200 Subject: [PATCH 13/13] Drop leftovers from the removed caps The skills field's comment and apply's doc still described caps, and Entry kept owned env strings and an env id parser that only caps needed. Env entries now borrow the trims' static names, and earlier ids are found through the trims as before. --- src/app/mod.rs | 2 +- src/claude/trim.rs | 26 +++++++------------------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/app/mod.rs b/src/app/mod.rs index 160cbe6..fe8b530 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -305,7 +305,7 @@ pub enum Modal { trimmed: Vec, /// Claudiu tools turned off (Claudiu tools page). claudiu_off: Vec, - /// Bash output cap, file read cap and skills to turn off, in that order (Claude Code tools page). + /// Skills to turn off, separated by commas (Claude Code tools page). skills_field: Entity, /// Settings found at open time that make Claude Code cost more (Claude Code tools page). costly: Vec, diff --git a/src/claude/trim.rs b/src/claude/trim.rs index ff486bb..22c4a8c 100644 --- a/src/claude/trim.rs +++ b/src/claude/trim.rs @@ -190,7 +190,7 @@ pub fn normalized(trimmed: &[Trim]) -> Vec { enum Entry { Key(&'static str, bool), Deny(&'static str), - Env(String, String), + Env(&'static str, &'static str), /// A skill turned off in `skillOverrides`. Skill(String), } @@ -208,10 +208,6 @@ impl Entry { /// The entry an earlier `id` stood for, so it can be taken out again. fn from_id(id: &str) -> Option { - if let Some(rest) = id.strip_prefix("env:") { - let (name, value) = rest.split_once('=')?; - return Some(Entry::Env(name.into(), value.into())); - } if let Some(name) = id.strip_prefix("skill:") { return Some(Entry::Skill(name.into())); } @@ -223,7 +219,7 @@ fn entries(trim: Trim) -> Vec { match trim.effect() { Effect::Keys(keys) => keys.iter().map(|(key, value)| Entry::Key(key, *value)).collect(), Effect::Deny(names) => names.iter().map(|name| Entry::Deny(name)).collect(), - Effect::Env(vars) => vars.iter().map(|(name, value)| Entry::Env(name.to_string(), value.to_string())).collect(), + Effect::Env(vars) => vars.iter().map(|(name, value)| Entry::Env(name, value)).collect(), } } @@ -234,7 +230,7 @@ fn present(settings: &Map, entry: &Entry) -> bool { let list = settings.get("permissions").and_then(|p| p.get("deny")).and_then(Value::as_array); list.is_some_and(|list| list.iter().any(|v| v.as_str() == Some(name))) } - Entry::Env(name, value) => settings.get("env").and_then(|e| e.get(name)).and_then(Value::as_str) == Some(value), + Entry::Env(name, value) => settings.get("env").and_then(|e| e.get(*name)).and_then(Value::as_str) == Some(*value), Entry::Skill(name) => settings.get("skillOverrides").and_then(|o| o.get(name)).and_then(Value::as_str) == Some("off"), } } @@ -257,7 +253,7 @@ fn add(settings: &mut Map, entry: &Entry) { Entry::Env(name, value) => { let env = settings.entry("env").or_insert_with(|| json!({})); if let Some(env) = env.as_object_mut() { - env.entry(name.clone()).or_insert_with(|| Value::String(value.clone())); + env.entry(*name).or_insert_with(|| Value::String((*value).into())); } } Entry::Skill(name) => { @@ -290,8 +286,8 @@ fn remove(settings: &mut Map, entry: &Entry) { } Entry::Env(name, value) => { let Some(env) = settings.get_mut("env").and_then(Value::as_object_mut) else { return }; - if env.get(name).and_then(Value::as_str) == Some(value) { - env.remove(name); + if env.get(*name).and_then(Value::as_str) == Some(*value) { + env.remove(*name); } if env.is_empty() { settings.remove("env"); @@ -348,7 +344,7 @@ impl Limits { } /// Put the trimmed items and limits into `settings` and take out the ones Claudiu added earlier (`applied`) that are -/// no longer wanted. A line the user had before Claudiu (a tool they denied themselves, a cap they set) is never +/// no longer wanted. A line the user had before Claudiu (a tool they denied themselves, a skill they set) is never /// recorded, so turning the trim off leaves it. Returns what Claudiu now owns, to pass back next time. pub fn apply(settings: &mut Map, trimmed: &[Trim], limits: &Limits, applied: &[String]) -> Vec { let wanted: Vec = normalized(trimmed).into_iter().flat_map(entries).chain(limits.entries()).collect(); @@ -537,14 +533,6 @@ mod tests { assert!(Limits::parse("a/b").unwrap_err().starts_with("Skills")); } - #[test] - fn a_cap_written_by_an_earlier_build_is_taken_out_on_the_next_save() { - let mut s = object(json!({ "env": { "BASH_MAX_OUTPUT_LENGTH": "2000", "FOO": "1" } })); - let owned = apply(&mut s, &[], &Limits::default(), &["env:BASH_MAX_OUTPUT_LENGTH=2000".to_string()]); - assert!(owned.is_empty()); - assert_eq!(Value::Object(s), json!({ "env": { "FOO": "1" } })); - } - #[test] fn the_field_shows_the_saved_skills_as_text() { assert_eq!(skills(&["a", "b"]).text(), "a, b");