Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:777genius Agent teams ai ContextBadge TokenUsageDisplay

From Leeroopedia
Knowledge Sources
Domains Session_Analysis, UI_Overlay
Last Updated 2026-10-22 00:00 GMT

Overview

Concrete tool for rendering per-turn context token breakdowns as React UI components (badge, hover popover, full panel), provided by the Agent Teams application.

Description

The ContextBadge and TokenUsageDisplay React components render context tracking data to the user. They consume `ContextStats` and `ContextPhaseInfo` from `processSessionContextWithPhases()` and use type guards to discriminate the `ContextInjection` union type for category-specific rendering.

ContextBadge:

  • Compact badge shown per timeline turn.
  • Hover triggers a popover showing the 6-category token breakdown (claude-md, mentioned-file, tool-output, thinking-text, team-coordination, user-message).
  • Uses component-scoped type guards (`isClaudeMdInjection`, `isToolOutputInjection`, etc.) to render category-specific icons and labels.

TokenUsageDisplay:

  • Hover-triggered breakdown showing token usage by category.
  • Uses `formatTokens()` from `@shared/utils/tokenFormatting` for human-readable token counts.
  • Shows per-category bars or progress indicators.

SessionContextPanel:

  • Full panel showing the complete session context overview.
  • Displays all phases (compaction boundaries) and per-turn stats.
  • Provides the most detailed view of context consumption across the entire session.

Usage

  • Per-turn badge: Place `ContextBadge` next to each AI turn in the timeline.
  • Hover detail: `TokenUsageDisplay` provides quick hover access to category breakdowns.
  • Full analysis: `SessionContextPanel` opens as a side panel for the complete picture.

Code Reference

Source Location

  • Repository: agent-teams
  • Files:
    • src/renderer/components/common/ContextBadge.tsx
    • src/renderer/components/common/TokenUsageDisplay.tsx
    • src/renderer/types/contextInjection.ts

Signature

// ContextBadge component
export function ContextBadge(props: {
  stats: ContextStats;
  phaseInfo?: ContextPhaseInfo;
}): JSX.Element;

// TokenUsageDisplay component
export function TokenUsageDisplay(props: {
  stats: ContextStats;
}): JSX.Element;

// Type guards (component-scoped in ContextBadge.tsx)
function isClaudeMdInjection(inj: ContextInjection): inj is ClaudeMdContextInjection;
function isMentionedFileInjection(inj: ContextInjection): inj is MentionedFileInjection;
function isToolOutputInjection(inj: ContextInjection): inj is ToolOutputInjection;
function isThinkingTextInjection(inj: ContextInjection): inj is ThinkingTextInjection;
function isTeamCoordinationInjection(inj: ContextInjection): inj is TeamCoordinationInjection;
function isUserMessageInjection(inj: ContextInjection): inj is UserMessageInjection;

Import

import { ContextBadge } from '@renderer/components/common/ContextBadge';
import { TokenUsageDisplay } from '@renderer/components/common/TokenUsageDisplay';

I/O Contract

Inputs

Name Type Required Description
stats ContextStats Yes Per-turn context statistics from processSessionContextWithPhases
phaseInfo ContextPhaseInfo No Phase boundaries for phase-aware rendering

Outputs

Name Type Description
return JSX.Element Rendered badge or display component

Usage Examples

Per-Turn Context Badge

import { ContextBadge } from '@renderer/components/common/ContextBadge';

function TimelineTurn({ item, groupId, statsMap, phaseInfo }) {
  const stats = statsMap.get(groupId);
  return (
    <div className="timeline-turn">
      <div className="turn-content">{item.content}</div>
      {stats && <ContextBadge stats={stats} phaseInfo={phaseInfo} />}
    </div>
  );
}

Token Usage Hover Display

import { TokenUsageDisplay } from '@renderer/components/common/TokenUsageDisplay';

function ModelStats({ stats }) {
  return (
    <div className="group relative">
      <span>{stats.totalTokens} tokens</span>
      <div className="hidden group-hover:block absolute z-50">
        <TokenUsageDisplay stats={stats} />
      </div>
    </div>
  );
}

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment