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

Open-source SwiftUI testing skill for Claude Code uses Computer Use to visually test apps
An open-source Claude Code skill called /ios-test visually tests SwiftUI apps using Computer Use capability. The agent finds .xcodeproj files, builds the app in a Simulator, then navigates through every screen, tapping buttons and following links like a real user.

Claude Code protocol file reduces repetitive questioning
A developer created a single .md file for ~/.claude/rules/ that infers task type and risk from the first message, eliminating Claude Code's typical three-question sequence before starting work.

Local AI VS Code extension blocks insecure code generation during saves
A developer built a VS Code extension that runs llama3.1:8b-instruct-q4 locally to intercept saves, map source-to-sink execution flows, and block AI-generated insecure code like CWE-117 Log Injection vulnerabilities.

Six GitHub Repositories for Claude Code Development
A Reddit user tested and shared six GitHub repositories designed to improve Claude Code projects, including tools for structured development, UI generation, task management, memory, ecosystem exploration, and workflow automation.