From c8d4057dd1ef57f6d1216e17ba7ddab26ba5bf46 Mon Sep 17 00:00:00 2001 From: tlongwell-block <109685178+tlongwell-block@users.noreply.github.com> Date: Sun, 22 Feb 2026 13:13:18 -0500 Subject: [PATCH] feat: expose context window utilization to agent via MOIM (#7418) --- crates/goose/src/agents/extension_manager.rs | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/goose/src/agents/extension_manager.rs b/crates/goose/src/agents/extension_manager.rs index 51981780f8..61bfa88318 100644 --- a/crates/goose/src/agents/extension_manager.rs +++ b/crates/goose/src/agents/extension_manager.rs @@ -1608,6 +1608,28 @@ impl ExtensionManager { working_dir.display() ); + if let Ok(session) = self + .context + .session_manager + .get_session(session_id, false) + .await + { + if let (Some(total), Some(config)) = + (session.total_tokens, session.model_config.as_ref()) + { + let limit = config.context_limit(); + if total > 0 && limit > 0 { + let pct = (total as f64 / limit as f64 * 100.0).round() as u32; + content.push_str(&format!( + "Context: ~{}k/{}k tokens used ({}%)\n", + total / 1000, + limit / 1000, + pct + )); + } + } + } + let platform_clients: Vec<(String, McpClientBox)> = { let extensions = self.extensions.lock().await; extensions