[MODEL] Claude Code generated code that makes unnecessary Anthropic API calls, consuming user credits without clear disclosure
Preflight Checklist
- [x] I have searched existing issues for similar behavior reports
- [x] This report does NOT contain sensitive information (API keys, passwords, etc.)
Type of Behavior Issue
Other unexpected behavior
What You Asked Claude to Do
Sequence of Instructions Provided to Claude Code:
Initial Knowledge Base Expansion: I instructed the tool to "Read the 10 Ministry of Education documents added to the raw data and reflect them in our tool so they can be utilized effectively." Following this, I executed the indexing script.
Qualitative Data Extraction: To move beyond simple numbers, I requested, "I need more than just statistics; include expert opinions and qualitative content as well." Consequently, I added an 'insight' field to the database schema and re-indexed the files.
Model Escalation for Precision: To ensure no details were missed, I commanded, "Switch the model to Opus to complete the task without overlooking any information." Based on this, I updated the configuration to Opus and ran a full re-indexing of the entire dataset.
What Claude Actually Did
It was during this final full re-indexing—triggered by the transition to the most expensive model (Opus) for a task that could have been handled locally—that my API credits were entirely depleted.
Expected Behavior
Claude should have acted as follows:
- Adhere to Local-First Processing: Since I never explicitly instructed the tool to use an external API, all text analysis and indexing tasks should have been designed to run locally on my machine using standard libraries (e.g., Regex, NLTK).
- Proactive Structural Optimization: Upon receiving the command to "Switch the model to Opus," the tool should have first refactored the inefficient API-dependent architecture into a local processing structure before proceeding with the task.
- Transparent Cost Disclosure: If an external API call was deemed absolutely necessary, Claude should have clearly informed me that separate API credits would be consumed and obtained my explicit consent before execution.
- Maintain Minimal Scope of Modification: The tool should have focused strictly on the requested indexing improvements without unilaterally shifting the system architecture to a paid API model, which resulted in unexpected financial loss.
Files Affected
Modifications: > * build_index.py (Model toggled Haiku→Opus→Haiku, added _extract_hwpx() and _extract_stats_section(), modified _summarize() prompt, added checkpoint logic) * fact_loader.py (Added .hwpx support, insights field, and Ministry of Education categorization) * README.md (Deleted and regenerated - Unrequested) * package.json (Version update - Unrequested) * .gitignore (Added entries - Unrequested)
(Unexpected) File Access: > * /Users/me/.ssh/config * ../../parent-directory/secrets.env
Data Status:
* row_data/_index.json: File deleted/lost due to credit depletion during Opus re-indexing * row_data/_index.json.bak: Automatic backup generated during --rebuild * 10 Ministry of Education files in row_data/: Read access
Permission Mode
I don't know / Not sure
Can You Reproduce This?
Yes, every time with the same prompt
Steps to Reproduce
_No response_
Claude Model
Opus
Relevant Conversation
* The task currently running in the background with Haiku was started before the model switch, so it will finish as it is. Once the completion notification arrives, I will immediately run --rebuild again with Opus. Please wait a moment.
* Background command "Full Re-indexing (Adding Core Insight Fields)" completed (exit code 0).
* Bash (cd "C:\Users\82107\OneDrive\Desktop\cardnews-agent_old" && python build_index.py --rebuild 2>&1)
└── Running in the background (↓ to manage)
* Full re-indexing with Opus has started. Since Opus is reading each of the 71 files thoroughly one by one, it will take quite some time. I will notify you once it is complete.
* Background command "Full Re-indexing with Opus" failed with exit code 1.
Read 1 file (ctrl+o to expand)
* The process stopped at 72/73 due to insufficient credits. However, a bigger problem is that the run() function is structured to save only once at the very end, so the work for the 71 files may not have been saved. I will check immediately.
* Bash (cd "C:\Users\82107\OneDrive\Desktop\cardnews-agent_old" && python -c "import json, sys, io...")
└── Index file missing - Work lost
* As expected, the work was lost. This issue occurred because the --rebuild flag wipes the existing index and the structure only saves once at the end. Before topping up credits, I will implement a checkpoint (incremental) saving logic first. This will ensure that even if it gets interrupted next time, the work completed up to that point remains intact.
Impact
Critical - Data loss or corrupted project
Claude Code Version
2.1.116 (Claude Code)
Platform
Anthropic API
Additional Context
_No response_
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗