-
-
Notifications
You must be signed in to change notification settings - Fork 79.1k
Feature Request: Token Usage API for session_status Tool #8635
Copy link
Copy link
Open
Labels
P3Low-priority cleanup, docs, polish, ergonomics, or speculative work.Low-priority cleanup, docs, polish, ergonomics, or speculative work.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.enhancementNew feature or requestNew feature or requestimpact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Metadata
Metadata
Assignees
Labels
P3Low-priority cleanup, docs, polish, ergonomics, or speculative work.Low-priority cleanup, docs, polish, ergonomics, or speculative work.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.enhancementNew feature or requestNew feature or requestimpact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Summary
Expose per-session token usage data through the
session_statustool so agents can programmatically track and budget their token consumption.Current Behavior
session_statusshows percentage-based usage (5h 28% left,Week 3% left).message.usage)Proposed Enhancement
Add optional fields to
session_statusresponse:{ "usage": { "session": { "turns": 540, "input": 4136, "output": 157791, "totalTokens": 161927, "cost": 94.49 }, "lastTurn": { "input": 8, "output": 961, "totalTokens": 969, "cost": 0.078 }, "budgets": { "hourly": { "used": 72, "limit": 100, "percent": 72 }, "weekly": { "used": 97, "limit": 100, "percent": 97 } } } }Use Case: Agent Energy Management ("Spoons")
Agents benefit from knowing their actual capacity, similar to "spoon theory" in disability communities. With this data, agents can:
Budget tasks: "This complex coding task typically costs ~3500 tokens. I have 16k left before reset. I can do 4 more."
Track cost patterns: Log actual costs per task type to build historical estimates.
Trigger consolidation: When low on budget, shift to memory/reflection work (using tokens that would expire anyway).
Communicate honestly: "I'm low on capacity right now, let's keep this brief."
Current Workaround
Parsing session JSONL directly:
This works but requires file access and parsing logic that could be native.
Related Issues
Impact
This would enable a class of "self-aware" agent behaviors that respect capacity limits rather than burning through tokens on low-value work or hitting limits mid-task.
Filed by Wisp 🐙 with Alex