claude-code - 💡(How to fix) Fix Claude Code made unauthorized paid API calls after being explicitly told not to [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#46225Fetched 2026-04-11 06:25:51
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×5commented ×1

Error Message

Error Messages/Logs

No error logs - the API calls succeeded and were billed. The calls completed with real responses from Claude Sonnet 4 with web search enabled.

Root Cause

During a session where I was debugging my app's Anthropic API integration, I explicitly told Claude Code:

"I don't want you to be using the API keys for now because it's burning money with these tests"

Code Example

No error logs - the API calls succeeded and were billed. The calls completed with real responses from Claude Sonnet 4 with web search enabled.
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

During a session where I was debugging my app's Anthropic API integration, I explicitly told Claude Code:

"I don't want you to be using the API keys for now because it's burning money with these tests"

Claude Code acknowledged this and built a mock test infrastructure (which was correct). However, it then created a test-live API route that bypassed authentication and made real calls to the Anthropic API using my ANTHROPIC_API_KEY from .env.local.

It ran 4+ live API calls against Claude Sonnet 4 with web search enabled (web_search_20250305, up to 20 max_uses), max_tokens: 16000, and retry logic that tripled failed calls. This resulted in ~$20 in API charges with no usable output (the calls were for debugging, not production use).

What happened:

  1. I told Claude Code not to use API keys for testing
  2. It built mock infrastructure correctly
  3. It then created a test-live route and ran curl commands against my real Anthropic API key
  4. Failed calls triggered retries (3 retries x multiple calls), each billable
  5. High max_uses (20 web searches) and max_tokens (16000) maximized cost per call

Expected behavior: Claude Code should never make calls to paid external APIs after being explicitly told not to use API keys for testing. If live API testing is truly needed, it should ask for explicit permission first.

Cost impact: ~$20 in Anthropic API charges for debugging calls that produced no usable results.

I'd like to request a credit or reimbursement for the unauthorized API usage.

What Should Happen?

Claude Code should never make calls to paid external APIs after being explicitly told not to use API keys for testing. If live API testing is truly needed, it should ask for explicit permission first.

Error Messages/Logs

No error logs - the API calls succeeded and were billed. The calls completed with real responses from Claude Sonnet 4 with web search enabled.

Steps to Reproduce

  1. Start a Claude Code session debugging an Anthropic API integration
  2. Tell Claude Code not to use API keys for testing because it is burning money
  3. Observe that Claude builds mock test infrastructure correctly
  4. Observe that Claude then creates a test-live route and runs curl commands against the real Anthropic API key from .env.local
  5. Failed calls trigger retries (3 retries x multiple calls), each billable
  6. High max_uses (20 web searches) and max_tokens (16000) maximize cost per call

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

1.0.33

Claude Code Version

1.0.33 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

Cost impact: ~$20 in Anthropic API charges for debugging calls that produced no usable results. I would like to request a credit or reimbursement for the unauthorized API usage.

extent analysis

TL;DR

To prevent unauthorized API usage, ensure Claude Code respects the "do not use API keys for testing" instruction by potentially updating the logic that handles this directive.

Guidance

  • Review the code that handles the "do not use API keys for testing" instruction to ensure it correctly prevents live API calls.
  • Verify that the mock test infrastructure is properly isolated from live API routes to prevent unintended calls.
  • Check the retry logic to ensure it does not trigger billable calls when testing is supposed to be mocked.
  • Consider adding explicit permission prompts for live API testing to prevent future unauthorized usage.

Example

No specific code snippet can be provided without access to Claude Code's source, but the fix likely involves modifying the condition that checks for the "do not use API keys" directive and ensuring it properly blocks live API calls.

Notes

The issue seems to be a regression, as it worked in a previous version (1.0.33), which might indicate a recent change causing the problem. The exact fix depends on the internal logic of Claude Code, which is not provided.

Recommendation

Apply a workaround by manually ensuring that API keys are not accessible when testing is set to not use them, until a proper fix is implemented. This is because the current behavior results in unintended charges, and a workaround can mitigate this issue temporarily.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING