Skip to content

Commit 79a954c

Browse files
croakingtoadMartysirmalloc
authored
Add Claude Code Session ID widget (#111)
* feat: Add Claude Session ID widget * Add ClaudeSessionIdWidget to widget registry, add label, support raw mode, fix cross-platform issues by using session ID directly from statusline JSON --------- Co-authored-by: Marty <[email protected]> Co-authored-by: Matthew Breedlove <[email protected]>
1 parent bdcf6aa commit 79a954c

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

src/utils/widgets.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const widgetRegistry = new Map<WidgetItemType, Widget>([
2626
['terminal-width', new widgets.TerminalWidthWidget()],
2727
['version', new widgets.VersionWidget()],
2828
['custom-text', new widgets.CustomTextWidget()],
29-
['custom-command', new widgets.CustomCommandWidget()]
29+
['custom-command', new widgets.CustomCommandWidget()],
30+
['claude-session-id', new widgets.ClaudeSessionIdWidget()]
3031
]);
3132

3233
export function getWidget(type: WidgetItemType): Widget | null {
@@ -51,4 +52,4 @@ export function isKnownWidgetType(type: string): boolean {
5152
return widgetRegistry.has(type)
5253
|| type === 'separator'
5354
|| type === 'flex-separator';
54-
}
55+
}

src/widgets/ClaudeSessionId.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { RenderContext } from '../types/RenderContext';
2+
import type { Settings } from '../types/Settings';
3+
import type {
4+
Widget,
5+
WidgetEditorDisplay,
6+
WidgetItem
7+
} from '../types/Widget';
8+
9+
export class ClaudeSessionIdWidget implements Widget {
10+
getDefaultColor(): string { return 'cyan'; }
11+
getDescription(): string { return 'Shows the current Claude Code session ID reported in status JSON'; }
12+
getDisplayName(): string { return 'Claude Session ID'; }
13+
getEditorDisplay(item: WidgetItem): WidgetEditorDisplay {
14+
return { displayText: this.getDisplayName() };
15+
}
16+
17+
render(item: WidgetItem, context: RenderContext, settings: Settings): string | null {
18+
if (context.isPreview) {
19+
return item.rawValue ? 'preview-session-id' : 'Session ID: preview-session-id';
20+
} else {
21+
const sessionId = context.data?.session_id;
22+
if (!sessionId) {
23+
return null;
24+
}
25+
return item.rawValue ? sessionId : `Session ID: ${sessionId}`;
26+
}
27+
}
28+
29+
supportsRawValue(): boolean { return true; }
30+
supportsColors(item: WidgetItem): boolean { return true; }
31+
}

src/widgets/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ export { VersionWidget } from './Version';
1717
export { CustomTextWidget } from './CustomText';
1818
export { CustomCommandWidget } from './CustomCommand';
1919
export { BlockTimerWidget } from './BlockTimer';
20-
export { CurrentWorkingDirWidget } from './CurrentWorkingDir';
20+
export { CurrentWorkingDirWidget } from './CurrentWorkingDir';
21+
export { ClaudeSessionIdWidget } from './ClaudeSessionId';

0 commit comments

Comments
 (0)