[BUG] Agent Harness Token Usage Error
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Claude Code Bug Report: Agent Harness Token Usage Error
Summary
When invoking specialized agents (specifically e2e-delegation agent), the Claude Code harness crashes with a token usage tracking error, preventing agent execution.
Error Details
Error Message:
Cannot read properties of undefined (reading 'input_tokens')
Error Type: TypeError - Attempted property access on undefined object
Stack Context: The error occurs in the harness token tracking/metering layer, not in the agent code itself
Steps to Reproduce
- Setup: Milton project at
c:/Projects/Miltonwith configured agents in.claude/agents/directory - Execute: Call the Agent tool with a specialized agent type:
````
Agent(
description="Run E2E delegation test",
prompt="Run full delegation lifecycle test...",
subagent_type="e2e-delegation"
)
- Result: Immediate failure with token tracking error before agent even starts
Environment Details
- OS: Windows 11 Pro 10.0.26200
- Claude Code Version: Latest (as of April 7, 2026)
- Model: claude-sonnet-4-6 (as specified in agent definition)
- Project: Milton (FastAPI + PostgreSQL backend, Python 3.10.11)
- Agent Definition:
.claude/agents/e2e-delegation.md(exists, properly formatted with YAML frontmatter)
Agent Configuration
File: .claude/agents/e2e-delegation.md
---
name: e2e-delegation
description: "End-to-end delegation flow tester..."
tools: Bash, Read, Write
model: sonnet
---
Agent definition is valid and includes all required fields. Other agents in the same directory (deploy-agent, test-runner, schema-agent, milton-context) may have the same issue.
Expected Behavior
- Agent harness receives Agent tool call with
subagent_type="e2e-delegation" - Harness initializes token counter/meter for the agent execution
- Agent runs with access to specified tools (Bash, Read, Write)
- Harness tracks tokens used during execution
- Agent completes and returns results
- Token usage is recorded in response metadata
Actual Behavior
- Agent harness receives Agent tool call
- Harness attempts to initialize token tracking
- Crash:
input_tokensproperty accessed on undefined token counter object - Error bubbles up immediately, agent never executes
- User sees harness error instead of agent results
Impact
- Severity: High - Blocks all specialized agent usage
- Scope: All agent types (e2e-delegation, test-runner, etc.) are inaccessible
- Workaround: Implement required functionality directly in main conversation (less efficient)
- Frequency: Occurs on every agent invocation attempt
Attempted Workarounds
- Retry same call: Error repeats consistently
- Different agent types: Same error (suggests systemic harness issue)
- Simpler prompts: Error occurs immediately, independent of prompt complexity
- Different models: Agent definition specifies sonnet; issue appears independent of model choice
Related Context
- This appears to be a token metering/accounting issue in the harness
- The error suggests
input_tokensis expected to exist on a counter object that was never initialized or is undefined - Likely in harness code that runs after agent tool is invoked but before agent execution begins
- May be a regression if agents were recently working
Additional Notes
- Milton project has multiple other agents defined and working (in foreground conversation, we've used test-runner and schema-agent without issue previously)
- The issue is reproducible and consistent
- No environment-specific configuration appears to cause this — standard Claude Code setup
- Error occurs at harness level, not in agent code or Milton project code
Recommended Fix Areas
- Token tracking initialization in agent harness
- Agent invocation middleware (where
input_tokensshould be set up) - Null/undefined checks on token counter object before property access
Files Referenced in Report
- Agent definition:
.claude/agents/e2e-delegation.md - Test config:
.claude/e2e-test-config.json - Project: Milton (c:/Projects/Milton)
What Should Happen?
Expected Behavior
- Agent harness receives Agent tool call with
subagent_type="e2e-delegation" - Harness initializes token counter/meter for the agent execution
- Agent runs with access to specified tools (Bash, Read, Write)
- Harness tracks tokens used during execution
- Agent completes and returns results
- Token usage is recorded in response metadata
Error Messages/Logs
Steps to Reproduce
Steps to Reproduce
- Setup: Milton project at
c:/Projects/Miltonwith configured agents in.claude/agents/directory - Execute: Call the Agent tool with a specialized agent type:
````
Agent(
description="Run E2E delegation test",
prompt="Run full delegation lifecycle test...",
subagent_type="e2e-delegation"
)
Claude Model
Other
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
claude-haiku 4.5
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗