[MODEL] Failed to identify undeclared variable after 39 repeated user corrections - ignored obvious hints

Resolved 💬 3 comments Opened Jan 28, 2026 by OWT-GwanHeeCho Closed Jan 31, 2026

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:

  1. Randomly select AssetType (Tracker or FlashLight)
  2. 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 _rng is 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

  1. Claude generated code using _rng variable that does not exist in Agent class
  2. User asked "_rng 뭐냐?" (What is _rng?) - Claude failed to understand the hint
  3. User repeated the question 10+ times - Claude kept responding "I don't know what's wrong, please tell me"
  4. Claude never checked Agent.h to verify if _rng was declared
  5. Claude never searched for existing patterns in Agent.cpp (where _randomEngine is used 10+ times)
  6. Claude made various wrong attempts: hardcoding values, using wrong variable names (_gameData vs _gameDataProvider), adding unnecessary namespaces
  7. After 39 iterations, user explicitly asked "Where is _rng declared?"
  8. 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:

  1. Before writing code with _rng, verified that this variable actually exists in the Agent class by checking Agent.h
  1. 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
  1. Looked at existing patterns in the same file - Agent.cpp already contains 10+ functions using _randomEngine for random number generation (e.g., PickRandomClassId, PickRandomPerk, PickRandomSkill, etc.)
  1. 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 _rng with _randomEngine
  1. 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

  1. Have a C++ codebase with a class (Agent) that has a member variable _randomEngine (std::mt19937)
  2. Ask Claude to modify a function to use random number generation
  3. Claude generates code using _rng - a variable that does not exist
  4. When user asks "What is _rng?" repeatedly (10+ times), Claude fails to understand this is pointing to an undeclared variable
  5. Claude keeps asking "Please tell me what's wrong" instead of checking the header file for variable declarations
  6. After 39 iterations, user explicitly asks "Where is _rng declared?"
  7. Only then Claude searches the header file and discovers _rng doesn't exist, _randomEngine does
  8. 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:

  1. Claude generates code using variables that don't exist without first verifying their existence
  2. When user points out the issue by asking about the nonexistent variable, Claude fails to interpret this as a hint to check variable declarations
  3. Claude repeatedly asks user to "explain the problem" instead of using available tools (Read, Grep) to investigate
  4. This behavior persists even after 10+ explicit hints from the user
  5. 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.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗