Measuring Off-Task Token Spend in Claude Code: The 'Undeclared-Intent' Metric

A developer building custom hooks for Claude Code created a metric called undeclared-intent spend to measure token usage outside the declared objective.
Key Findings
- In one session, total compute was 5,137 tokens, with 1,173 (22.8%) classified as undeclared and 3,964 (77.2%) on-declared.
- Undeclared spend captures cost of retries, loops, reasoning drift, and off-task execution — not just governance violations.
- The metric treats cost as a behavioral signal, not billing telemetry alone.
Implementation Challenge
The hook surface doesn't always expose enough context to distinguish true drift from indeterminable intent. The author notes two distinct failure modes: genuine drift (wandered into unrelated files/systems) vs. indeterminable from hook data. Different responses needed per mode.
Example output format:
Total compute 5,137 tokens
Undeclared 1,173 tokens (22.8%)
Declared 3,964 tokens (77.2%)
No tool or library is shared in the source; the post is a discussion prompt. The author is interested whether others are measuring off-task compute or still treating token spend purely as billing/optimization.
📖 Read the full source: r/ClaudeAI
👀 See Also

Auto-Fix System Uses Claude Code Headless to Detect and Fix Production Errors
A developer built an automated production error-fixing system using Claude Code CLI in headless mode. The system detects errors from logs, creates isolated git worktrees for each issue, prompts Claude to write fixes, and requires manual approval via Telegram before creating PRs.

Persistent Side Panel for Claude Code with Autonomous Content Management
A developer built a TUI panel that sits in an iTerm2 split pane next to the terminal, featuring three fixed panels that Claude autonomously manages to show relevant content like code, diagrams, and status updates.

Cursor's Approach to Fast Regex Search for AI Agents
Cursor is developing indexed regex search to address performance issues in large monorepos where ripgrep can take over 15 seconds, using inverted indexes with n-grams based on 1993 research by Zobel, Moffat and Sacks-Davis.

Custom WhatsApp Channel Plugin for Claude Code Using Baileys
A developer built a custom channel plugin that adds WhatsApp support to Claude Code 2.1.80+ using Baileys v7, implementing the WhatsApp Web Multi-Device protocol as an MCP server with the experimental claude/channel capability.