From 11ca660dec2c450ac7fb594d14a85ca271acce0e Mon Sep 17 00:00:00 2001 From: Steffen Deusch Date: Thu, 29 Jan 2026 16:34:39 +0100 Subject: [PATCH] allow using /context command (#268) I experimented with https://agentclientprotocol.com/rfds/session-usage (see https://github.com/agentclientprotocol/agent-client-protocol/pull/415), but the Claude Agent SDK does not seem to return the information we need for an accurate context indicator. For example, one request to explore a project returned 500k+ cached read tokens in Claude's `result` message, while the agent reported 64k tokens used. I can open a PR with those changes for reference once the Typescript SDK is updated. To allow users to still see the current context usage, allowing to run `/context` seems to be the second best option. This PR changes the code to handle the `` message that the SDK generates when sending `/context` and includes `/context` as allowed command. Screenshot from Tidewave with this change: image --- src/acp-agent.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/acp-agent.ts b/src/acp-agent.ts index 7ef73f8d..b63e63f6 100644 --- a/src/acp-agent.ts +++ b/src/acp-agent.ts @@ -350,6 +350,21 @@ export class ClaudeAcpAgent implements Agent { typeof message.message.content === "string" && message.message.content.includes("") ) { + // Handle /context by sending its reply as regular agent message. + if (message.message.content.includes("Context Usage")) { + for (const notification of toAcpNotifications( + message.message.content + .replace("", "") + .replace("", ""), + "assistant", + params.sessionId, + this.toolUseCache, + this.client, + this.logger, + )) { + await this.client.sessionUpdate(notification); + } + } this.logger.log(message.message.content); break; } @@ -872,7 +887,6 @@ async function getAvailableModels(query: Query): Promise { async function getAvailableSlashCommands(query: Query): Promise { const UNSUPPORTED_COMMANDS = [ - "context", "cost", "login", "logout",