[BUG] Claude Desktop sandbox blocks local tokenizer, causing billable Haiku inference calls on Bedrock AIPs

Status Open
Reported on v2.1.217
Maintainer reply None cached
Activity 0 comments · opened Jul 23, 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?

`Environment: Claude Desktop 1.24012.1 (Windows 11), Claude Code 2.1.217, Bedrock Application Inference Profiles (eu-central-1)

---

Summary

Every prompt submitted in a Claude Code session running inside Claude Desktop triggers 19 parallel Haiku inference invocations consuming 43,016 input tokens — before the actual Sonnet response is generated. This does not occur when using the Claude Code CLI directly.

---

Observed Behaviour

CloudWatch Evidence (AWS/Bedrock, ModelId=bdrfshw6ow7e — personal Haiku AIP)

From CloudWatch metric export (InputTokenCount__Invocations-2026_07_23_06_15_00-2026_07_23_07_00_00-UTC.csv):

| Time (UTC) | Invocations | Input Tokens | Note |
|---|---|---|---|
| 06:15 | 19 | 43,016 | 2 early prompts in one 5-min bucket |
| 06:20 | 19 | 43,016 | 1 prompt |
| 06:25–06:50 | 0 | 0 | No prompts sent |
| 06:55 | 57 | 129,048 | 3 × 19 — 3 prompts in one bucket |
| 07:00 | 57 | 129,048 | 3 × 19 — 3 prompts in one bucket |

Key observation: always exactly 19 invocations × 2,264 tokens = 43,016 per prompt, regardless of conversation length. This fixed size points to the system prompt + tool definitions, not conversation history.

Debug Log Evidence (~/.claude/debug/ecb06456-0cbd-4301-8309-897fb22652ff.txt)

The debug log (enabled mid-session via /debug) captures the mechanism directly:

Step 1 — Primary token counter returns null:

2026-07-23T06:58:18.329Z [DEBUG] countTokensWithFallback: [REDACTED] returned null, trying haiku fallback (0 tools)
2026-07-23T06:58:18.329Z [DEBUG] countTokensWithFallback: [REDACTED] returned null, trying haiku fallback (0 tools)
... (repeated 17 more times)
2026-07-23T06:58:18.330Z [DEBUG] countTokensWithFallback: [REDACTED] returned null, trying haiku fallback (28 tools)
2026-07-23T06:58:18.330Z [DEBUG] countTokensWithFallback: [REDACTED] returned null, trying haiku fallback (1 tools)
2026-07-23T06:58:18.330Z [DEBUG] countTokensWithFallback: [REDACTED] returned null, trying haiku fallback (11 tools)

Step 2 — 19 parallel Haiku API calls fired:

2026-07-23T06:58:18.334Z [DEBUG] [API REQUEST] /model/.../bdrfshw6ow7e/invoke source=count_tokens
2026-07-23T06:58:18.335Z [DEBUG] [API REQUEST] /model/.../bdrfshw6ow7e/invoke source=count_tokens
... (19 total, all within ~15ms of each other)

Step 3 — Sonnet dispatch follows:

2026-07-23T06:58:57.876Z [DEBUG] [API:timing] dispatching to bedrock model=.../iyztv5rlknm8

This pattern repeats identically on every user prompt. Total Haiku count_tokens calls captured in this session's debug log: 114.

---

Root Cause

Claude Code uses a local bundled tokenizer to count tokens before each inference call (to track context window usage and decide when to compact). This is a local operation — no API call required.

In the CLI: the local tokenizer runs normally. No Haiku calls are made for token counting.

In Claude Desktop: the Desktop app launches Claude Code with a sandbox enforced via --managed-settings:

"sandbox": {
  "enabled": true,
  "allowUnsandboxedCommands": false,
  "network": {
    "allowManagedDomainsOnly": true,
    "allowedDomains": [
      "bedrock-runtime.eu-central-1.amazonaws.com",
      "sts.amazonaws.com",
      "sts.eu-central-1.amazonaws.com",
      "portal.sso.eu-central-1.amazonaws.com",
      "oidc.eu-central-1.amazonaws.com",
      "portal.sso.eu-west-1.amazonaws.com",
      "oidc.eu-west-1.amazonaws.com",
      "api.anthropic.com"
    ]
  }
}

The sandbox blocks the local tokenizer path (no localhost, file://, or node: protocols allowed). The primary countTokens call returns null. Claude Code's countTokensWithFallback function then falls back to calling Haiku.

On the direct Anthropic API, Haiku has a cheap /count_tokens metadata endpoint. On Bedrock Application Inference Profiles, this endpoint is not supported. Claude Code therefore falls back a second time to a full Haiku inference invocation — which counts as a billable Bedrock inference call.

Since the system prompt + tool definitions are split into 19 chunks, 19 parallel Haiku inference calls are fired.

Fallback Chain

Local tokenizer (bundled)
    → blocked by Desktop sandbox → returns null
        → Haiku /count_tokens endpoint
            → not supported on Bedrock AIPs → falls back to
                → Haiku full inference call (×19, one per chunk) ← BILLABLE

---

Impact

| Metric | Value |
|---|---|
| Haiku invocations per prompt | 19 |
| Haiku input tokens per prompt | 43,016 |
| Cost per prompt (Haiku input, Bedrock pricing) | ~$0.0043 |
| Affected configuration | Claude Desktop + Bedrock AIPs |
| Unaffected configuration | Claude Code CLI + Bedrock AIPs |

The 43,016 tokens is fixed (system prompt + tools), not proportional to conversation length. This means the overhead is constant per prompt rather than growing — but it is present on every single prompt, including trivial ones like "hello world".

---

Related GitHub Issues

No exact duplicate found. Related issues to reference when filing:

  • #63532countTokensWithFallback failing on Bedrock with MCP tools (closed/completed, Jun 26 2026) — same function, different trigger

`

What Should Happen?

Token counting should be performed locally using the bundled tokenizer — no API calls, no cost. This is how it works in the CLI. The Claude Desktop sandbox should not block the local tokenizer path.

Error Messages/Logs

Steps to Reproduce

  1. Configure Claude Code with Bedrock Application Inference Profiles (Sonnet + Haiku)
  2. Open Claude Desktop (not the CLI)
  3. Start any Claude Code session
  4. Send any prompt (e.g. "hello world")
  5. Observe in CloudWatch (AWS/Bedrock, InputTokenCount, dimension ModelId=<haiku-aip-short-id>): exactly 19 invocations × 43,016 tokens appear within the same minute

Does not reproduce when running claude directly from the CLI with the same Bedrock AIP configuration.

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.217

Platform

AWS Bedrock

Operating System

Windows

Terminal/Shell

Other

Additional Information

_No response_

View original on GitHub ↗