[BUG] Agent Harness Token Usage Error

Resolved 💬 3 comments Opened Apr 7, 2026 by jaysonsgit Closed Apr 11, 2026

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

  1. Setup: Milton project at c:/Projects/Milton with configured agents in .claude/agents/ directory
  2. 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"
)
``

  1. 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

  1. Agent harness receives Agent tool call with subagent_type="e2e-delegation"
  2. Harness initializes token counter/meter for the agent execution
  3. Agent runs with access to specified tools (Bash, Read, Write)
  4. Harness tracks tokens used during execution
  5. Agent completes and returns results
  6. Token usage is recorded in response metadata

Actual Behavior

  1. Agent harness receives Agent tool call
  2. Harness attempts to initialize token tracking
  3. Crash: input_tokens property accessed on undefined token counter object
  4. Error bubbles up immediately, agent never executes
  5. 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

  1. Retry same call: Error repeats consistently
  2. Different agent types: Same error (suggests systemic harness issue)
  3. Simpler prompts: Error occurs immediately, independent of prompt complexity
  4. 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_tokens is 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_tokens should 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

  1. Agent harness receives Agent tool call with subagent_type="e2e-delegation"
  2. Harness initializes token counter/meter for the agent execution
  3. Agent runs with access to specified tools (Bash, Read, Write)
  4. Harness tracks tokens used during execution
  5. Agent completes and returns results
  6. Token usage is recorded in response metadata

Error Messages/Logs

Steps to Reproduce

Steps to Reproduce

  1. Setup: Milton project at c:/Projects/Milton with configured agents in .claude/agents/ directory
  2. 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_

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗