Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(context): shared types and IPC channel for context-window meter

enes5460671b32ae
diff --git a/src/shared/ipc.ts b/src/shared/ipc.ts
index cfca4cd08..dd1bec976 100644
--- a/src/shared/ipc.ts
+++ b/src/shared/ipc.ts
@@ -33,6 +33,7 @@ export const IPC = {
usageFetch: 'usage:fetch',
usageRefresh: 'usage:refresh',
usageUpdate: 'usage:update',
+ contextUpdate: 'context:update',
// Events broadcast from main to the renderer (sessionId is appended to the channel name).
ptyData: (sessionId: string) => `pty:data:${sessionId}`,
ptyExit: (sessionId: string) => `pty:exit:${sessionId}`,
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 82c939e74..b5a947214 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -434,6 +434,25 @@ export interface UsageApi {
onUpdate(listener: (usage: ClaudeUsage) => void): () => void
}
+/** A Claude session's context-window fill, pushed per sessionId from the transcript tailer. */
+export interface ContextWindowUsage {
+ sessionId: string
+ /** input + cache_read + cache_creation tokens of the latest assistant message. */
+ usedTokens: number
+ /** Model context window (200k default, 1M for 1m-context models). */
+ windowTokens: number
+ /** 0–100 fullness. */
+ usedPercent: number
+ /** Model id from the transcript, or null if not seen yet. */
+ model: string | null
+ updatedAt: number
+}
+
+export interface ContextApi {
+ /** Fires whenever a session's context fill changes. Returns unsubscribe. */
+ onUpdate(listener: (usage: ContextWindowUsage) => void): () => void
+}
+
export interface NodeTerminalApi {
pty: PtyApi
workspace: WorkspaceApi
@@ -447,6 +466,7 @@ export interface NodeTerminalApi {
announcements: AnnouncementsApi
bridge: BridgeApi
usage: UsageApi
+ context: ContextApi
/** Fires when the user presses Cmd/Ctrl+M (toggle markdown view). Returns unsubscribe. */
onMarkdownToggle(listener: () => void): () => void
/** Fires when the user presses Cmd/Ctrl+W (close selected node). Returns unsubscribe. */