Skip to content

feat: add /tokens /context /cost commands to show token usage and context size #224

Description

@andrewsruge2501-max

Feature Request: Token Usage & Context Visibility

It would be very useful to have visibility into token consumption and context size directly from the CLI, similar to Claude Code's /context and /cost commands.

Motivation

Currently, Deep Code already stores token usage data internally in sessions-index.json. According to the docs, each session entry tracks:

"token 用量 and 活跃 token 数"

However, there is no way to view this information from the CLI interface. Users have no visibility into:

  • How many tokens they have consumed in the current session
  • How much of the context window is being used
  • What is consuming the most tokens (system prompt, conversation history, skills, MCP tools)

Proposed Commands

/tokens – Show current session token consumption

Displays the token usage breakdown for the current session:

  • Input tokens (this turn)
  • Output tokens (this turn)
  • Thinking tokens (if thinking mode is enabled)
  • Total tokens (entire session)
  • Estimated cost (based on model pricing)

/context – Show context window breakdown

Displays what is consuming the context window:

  • System prompt size (tokens)
  • Conversation history size (# of messages, tokens)
  • Skills loaded and their contribution
  • Active MCP tools and their descriptions size
  • Total context window usage (e.g., 15K / 128K / 1M)

/cost – Show cumulative session cost

Shows the estimated cost of the current session based on model pricing:

  • Per-turn cost breakdown
  • Total session cost
  • Thinking vs non-thinking token cost

Why This Matters

  1. Cost awareness – Helps users monitor spend when using paid API models (especially with reasoning/thinking tokens which add significant cost)
  2. Debug context limits – When approaching context window limits, users can identify the culprit (bloated history, too many skills, etc.)
  3. Optimization feedback – Allows users to measure the impact of prompt optimization, skill trimming, or MCP cleanup
  4. Parity with alternatives – Tools like Claude Code already offer /context and /cost; adding these would reduce friction for users migrating to or evaluating Deep Code

Implementation Notes

  • The data already exists in ~/.deepcode/projects/<project-code>/sessions-index.json which stores "token 用量" per session entry
  • For real-time context window tracking, the token counts could be computed from the messages being sent to the model API
  • A lightweight tokenizer or cached counts per message would suffice — no need for full tokenization on every request

This is an open-ended feature request. Happy to help with implementation or testing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions