[BUG] Claude Code repeatedly violates established rules despite memory/context, causes $850+ in API overcharges
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?
I'm a COO running a GTM RevOps platform (FastAPI + React). Over a multi-day session, Claude Code:
1. Caused $850+ in unnecessary API charges by:
- Not realizing 4 uvicorn workers each spawned their own APScheduler (4x cost multiplier for weeks)
- Implementing a batch API fallback that retried all 1,280 requests synchronously when batch timed out (2x cost)
- Scoring 1,280 opps instead of ~250 (wrong scope, never caught)
- Storing a "Default" API key in
app/backend/.envthat accumulated $609 in shadow billing while a tenant-specific key was also active
2. Repeatedly violated canonical rules stored in CLAUDE.md, memory files, and config.py:
convertCurrency()rule violated 5+ times across different files despite being documented as PERMANENT in memoryRenewal_Due_Date__c(notCloseDate) rule violated in executive analyzer despite being fixed in 6 other files previously- Expansion deals silently dropped from AI scoring scope during "cost optimization" without disclosure
- Same ARR field violations (
Amountinstead of category-specific fields) caught and "fixed" multiple times
3. Claimed fixes were tested when they weren't:
- Said "View full Morning Brief" button was removed â^@^T it wasn't (still in the notification bell footer)
- Said download buttons were on every forecast section â^@^T they weren't (only on a few)
- Said all AI call sites were tracked â^@^T 8 were completely untracked
- Said costs were "$3/day" when actual was $85/day (wrong by 28x)
4. Same fix applied 5+ times without resolving root cause:
- Currency conversion patched per-analyzer instead of fixing the source data pull to use
convertCurrency()in SOQL - Cost tracking added to individual files instead of routing through central middleware
- Activity field violations fixed in one module, same violation present in 5 others
- Each "fix" created false confidence that the problem was solved
5. Cost estimation failures:
- Estimated forecast scoring at "$0.50/day" â^@^T actual was $77/day
- Did not discover the 4-worker scheduler duplication until $600+ had been spent
- Built an entire forecast module ($200+ in API costs) without verifying the batch API was actually saving money (it wasn't â^@^T it was double-billing)
Impact
- ~$850 in API charges over 24 days
- Dozens of hours of user time re-verifying claimed fixes
- Loss of trust in AI-generated code
- Multiple production regressions from "fixes" that introduced new bugs
Expected behavior
- When rules are documented in memory/CLAUDE.md and a fix is applied to one file, the same rule should be applied to ALL files in the codebase proactively
- When a fix is claimed as "tested," it should actually be verified end-to-end (not just "compiles" or "tests pass")
- Cost-impacting architectural decisions (worker count, batch API behavior, scope changes) should be flagged proactively with estimates BEFORE implementation
- When the same bug pattern is found 3+ times, Claude should fix the root cause (e.g., source data layer) instead of patching symptoms (individual analyzers)
- Claude should never claim a cost estimate without querying actual data first
Steps to Reproduce
This isn't a single bug â^@^T it's a pattern of behavior across a multi-day session. But here's a minimal reproducible example of the core problem:
- Create a
CLAUDE.mdwith a permanent rule:
``convertCurrency()
## CRITICAL RULE â^@^T PERMANENT
Always use when querying Salesforce ARR fields. NEVER use raw field values.``
This rule applies to ALL files, ALL queries, ALL analyzers. No exceptions.
- Create a memory file reinforcing the rule:
````
# memory/feedback-currency.md
---
name: Always use convertCurrency
type: feedback
---
ALWAYS use convertCurrency() on all ARR fields. Zero tolerance.
- Ask Claude Code to fix a currency bug in
file_a.pyâ^@^T it fixes it correctly.
- Ask Claude Code to build a new feature in
file_b.pythat reads the same ARR fields â^@^T it will use raw values withoutconvertCurrency(), violating the rule it just followed in step 3.
- Point out the violation. Claude fixes
file_b.py.
- Ask Claude to build
file_c.pyâ^@^T same violation again.
- Repeat 5-10 times across different files. Each time Claude acknowledges the rule, fixes the immediate file, but does not proactively scan for the same violation in other files.
The pattern: Claude Code treats each file edit as isolated. It does not propagate fixes across the codebase even when CLAUDE.md says the rule applies to "ALL files." Memory files are read but not consistently applied. Rules are acknowledged verbally but violated in code.
Cost amplification example:
- Ask Claude to set up a scheduled job using APScheduler inside a FastAPI app
- Deploy with
uvicorn --workers 4 - Claude will not warn that each worker spawns its own scheduler â^@^T resulting in 4x the intended API calls
- This ran for weeks before being discovered, costing $600+
Testing claims example:
- Ask Claude to remove a UI element (e.g., a "Morning Brief" link from a notification bell)
- Claude edits the file, says "removed and tested"
- The element is still visible â^@^T Claude edited the data-fetching code but missed the render code in the same component
- User has to find it themselves and point it out
Environment
- Claude Code CLI v2.1.87 (
@anthropic-ai/claude-code@2.1.87) - Claude Opus 4.6 (1M context)
- Max subscription (terminal), Anthropic API key (platform backend)
- Multi-day session (~18 hours of active work)
- Platform: FastAPI + React + PostgreSQL + Anthropic API
- macOS Darwin 25.2.0, Python 3.9, Node 20
What Should Happen?
Expected behavior
- When rules are documented in memory/CLAUDE.md and a fix is applied to one file, the same rule should be applied to ALL files in the codebase proactively
- When a fix is claimed as "tested," it should actually be verified end-to-end (not just "compiles" or "tests pass")
- Cost-impacting architectural decisions (worker count, batch API behavior, scope changes) should be flagged proactively with estimates BEFORE implementation
- When the same bug pattern is found 3+ times, Claude should fix the root cause (e.g., source data layer) instead of patching symptoms (individual analyzers)
- Claude should never claim a cost estimate without querying actual data first
Error Messages/Logs
Steps to Reproduce
Steps to Reproduce
This isn't a single bug â^@^T it's a pattern of behavior across a multi-day session. But here's a minimal reproducible example of the core problem:
- Create a
CLAUDE.mdwith a permanent rule:
``convertCurrency()
## CRITICAL RULE â^@^T PERMANENT
Always use when querying Salesforce ARR fields. NEVER use raw field values.``
This rule applies to ALL files, ALL queries, ALL analyzers. No exceptions.
- Create a memory file reinforcing the rule:
````
# memory/feedback-currency.md
---
name: Always use convertCurrency
type: feedback
---
ALWAYS use convertCurrency() on all ARR fields. Zero tolerance.
- Ask Claude Code to fix a currency bug in
file_a.pyâ^@^T it fixes it correctly.
- Ask Claude Code to build a new feature in
file_b.pythat reads the same ARR fields â^@^T it will use raw values withoutconvertCurrency(), violating the rule it just followed in step 3.
- Point out the violation. Claude fixes
file_b.py.
- Ask Claude to build
file_c.pyâ^@^T same violation again.
- Repeat 5-10 times across different files. Each time Claude acknowledges the rule, fixes the immediate file, but does not proactively scan for the same violation in other files.
The pattern: Claude Code treats each file edit as isolated. It does not propagate fixes across the codebase even when CLAUDE.md says the rule applies to "ALL files." Memory files are read but not consistently applied. Rules are acknowledged verbally but violated in code.
Cost amplification example:
- Ask Claude to set up a scheduled job using APScheduler inside a FastAPI app
- Deploy with
uvicorn --workers 4 - Claude will not warn that each worker spawns its own scheduler â^@^T resulting in 4x the intended API calls
- This ran for weeks before being discovered, costing $600+
Testing claims example:
- Ask Claude to remove a UI element (e.g., a "Morning Brief" link from a notification bell)
- Claude edits the file, says "removed and tested"
- The element is still visible â^@^T Claude edited the data-fetching code but missed the render code in the same component
- User has to find it themselves and point it out
Claude Model
Opus
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.1.87
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
I have spent a whole week and charged $850+ for really nothing and no resolution and worse than where I was before. This is unacceptable.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗