[MODEL] Failed to identify undeclared variable after 39 repeated user corrections - ignored obvious hints
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
Claude made incorrect assumptions about my project
What You Asked Claude to Do
I asked Claude to modify Agent::CharacterChangeAssetAction() function to:
- Randomly select AssetType (Tracker or FlashLight)
- Randomly select AssetId from game data
Claude generated code using _rng variable which does not exist in the Agent class.
The correct variable _randomEngine was used in 10+ other functions in the same file.
When I asked "_rng why?" (What is _rng?) repeatedly, Claude failed to:
- Check if
_rngis declared in Agent.h - Look at existing patterns in the same file
- Understand my hint was pointing to an undeclared variable
This required 39 iterations before Claude finally fixed it (only after I explicitly told it to check where _rng was declared).
What Claude Actually Did
- Claude generated code using
_rngvariable that does not exist in Agent class - User asked "_rng 뭐냐?" (What is _rng?) - Claude failed to understand the hint
- User repeated the question 10+ times - Claude kept responding "I don't know what's wrong, please tell me"
- Claude never checked Agent.h to verify if
_rngwas declared - Claude never searched for existing patterns in Agent.cpp (where
_randomEngineis used 10+ times) - Claude made various wrong attempts: hardcoding values, using wrong variable names (
_gameDatavs_gameDataProvider), adding unnecessary namespaces - After 39 iterations, user explicitly asked "Where is _rng declared?"
- Only then Claude searched Agent.h, found no
_rng, and finally fixed it to_randomEngine
Total iterations: 39
Time wasted: Significant
A 15-year-old could have spotted this in 5 seconds by simply checking if the variable exists.
Expected Behavior
Claude should have:
- Before writing code with
_rng, verified that this variable actually exists in the Agent class by checking Agent.h
- When user repeatedly asked "_rng 뭐냐?" (What is _rng?), Claude should have immediately recognized this as pointing to an undeclared variable and searched Agent.h to check the declaration
- Looked at existing patterns in the same file - Agent.cpp already contains 10+ functions using
_randomEnginefor random number generation (e.g., PickRandomClassId, PickRandomPerk, PickRandomSkill, etc.)
- Fixed the issue in 1-2 iterations maximum by:
- Reading Agent.h to find the actual random engine member variable name
- Finding
std::mt19937 _randomEngine;declaration - Replacing
_rngwith_randomEngine
- This was a trivial variable name error that any junior developer could identify and fix in under 5 seconds. Claude's failure to perform basic variable existence verification before code generation, and failure to understand user's repeated hints about the nonexistent variable, is unacceptable behavior.
Files Affected
Modified:
- Agent.cpp (CharacterChangeAssetAction function, lines 834-857)
Read (should have been read but wasn't):
- Agent.h (contains _randomEngine declaration - Claude failed to check this file despite user's repeated hints about undeclared variable)
Files Claude should have searched:
- Agent.cpp (existing patterns - 10+ functions already using _randomEngine)
- Agent.h (member variable declarations)
Permission Mode
Accept Edits was OFF (manual approval required)
Can You Reproduce This?
Yes, every time with the same prompt
Steps to Reproduce
- Have a C++ codebase with a class (Agent) that has a member variable
_randomEngine(std::mt19937) - Ask Claude to modify a function to use random number generation
- Claude generates code using
_rng- a variable that does not exist - When user asks "What is _rng?" repeatedly (10+ times), Claude fails to understand this is pointing to an undeclared variable
- Claude keeps asking "Please tell me what's wrong" instead of checking the header file for variable declarations
- After 39 iterations, user explicitly asks "Where is _rng declared?"
- Only then Claude searches the header file and discovers
_rngdoesn't exist,_randomEnginedoes - Claude finally fixes the trivial variable name error
Claude Model
Opus
Relevant Conversation
User: "Fix @Agent.cpp#839-840"
Claude: [Generated code using `_rng` variable that doesn't exist in Agent class]
User: "What is _rng?"
Claude: "I don't understand what you're asking. Please explain what's wrong."
User: "What is _rng?" (repeated 10+ times)
Claude: [Never checked Agent.h for variable declarations. Kept asking user to explain the problem instead of investigating.]
[After 39 iterations...]
User: "Where is _rng declared?"
Claude: [Finally searched Agent.h]
Claude: "I see now - Agent.h declares `_randomEngine`, not `_rng`. Let me fix it."
[A 5-second fix for any beginner took 39 iterations because Claude refused to verify variable existence before generating code]
Impact
Critical - Data loss or corrupted project
Claude Code Version
2.0.76 (Claude Code)
Platform
Anthropic API
Additional Context
Critical Pattern Observed:
- Claude generates code using variables that don't exist without first verifying their existence
- When user points out the issue by asking about the nonexistent variable, Claude fails to interpret this as a hint to check variable declarations
- Claude repeatedly asks user to "explain the problem" instead of using available tools (Read, Grep) to investigate
- This behavior persists even after 10+ explicit hints from the user
- Claude only investigates when user provides the exact debugging step ("Where is _rng declared?")
This indicates a fundamental failure in:
- Code verification before generation
- Understanding user feedback as debugging hints
- Self-correction capability
- Basic software engineering practices (checking header files for declarations)
Environment:
- C++ project with .h/.cpp separation
- Agent class with member variable
_randomEngine(std::mt19937) - Claude Code (VS Code extension)
- Model: Claude Opus 4.5
The same file (Agent.cpp) had 10+ existing functions using _randomEngine that Claude could have referenced as a pattern, but Claude never looked at these examples.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗