Skip to content

Add /context command — token usage breakdown #27

Description

@aakashrajput

Why

Long agentic sessions eat context. Users should be able to see where tokens go — like /cost shows spend, /context should show context-window usage.

What

New slash command /context that prints a breakdown of the current session's context usage:

  • System prompt (core + project rules) tokens
  • Conversation messages (user / assistant / tool results)
  • Tool schemas
  • Total vs the active tier's context window, with a simple bar/percentage
  • Current compaction state (has the session been compacted? ledger size?)

A bytes/4 token estimate is fine — consistency matters more than exactness. Keep one estimation helper as the single source of truth so /context, compaction, and the sidebar all agree.

Where to start

  • src/screens/repl.tsSLASH_COMMANDS catalog + handleSlashCommand()
  • src/agent/compaction.ts — existing char/token budget helpers (charBudgetForWindow)
  • Sidebar stats already track token counts — reuse, don't duplicate

Acceptance criteria

  • /context renders the breakdown in the transcript
  • Appears in slash autocomplete with a description
  • bun run typecheck and bun test green

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions