[BUG] Claude code places methods in the wrong code-block in large files.
Environment
- Platform (select one): Anthropic API
- Claude CLI version:
1.0.31 (Claude Code) - Operating System: Macos 14.7
- Terminal: Android Studio terminal
Bug Description
In short - Claude sometimes accidentally adds new methods to the wrong class.
Detail: I'm making an Android app, and I've got the classic "Android Burrito" going on (a 2600 line MainActivity.kt). Yes, not great practice, but it happens. The structure is
// imports
class MainActivity : AppCompatActivity() {
// A huge wad of code
}
...
fun IDrone.getLatestLaserMeasureInfo(maxAgeMillis: Int = 5000): Result<LaserMeasureInformation_> {
// Function body
}
Claude tries to add some methods (onPause(), onResume()) to MainActivity, but they end up being added to the IDrone... block instead, causing compile errors.
ie, I get
// imports
class MainActivity : AppCompatActivity() {
// A huge wad of code
// onResume SHOULD HAVE BEEN PUT HERE
}
...
fun IDrone.getLatestLaserMeasureInfo(maxAgeMillis: Int = 5000): Result<LaserMeasureInformation_> {
// Function body
override fun onResume() { // SHOULD NOT HAVE BEEN PUT HERE
...
}
}
Yes it's kind of my fault for stuffing so many things in one file - but it would help for claude to have access to some sort of "append method to class" functionality to avoid this mistake.
I've had this happen a few times now.
Steps to Reproduce
- Make Giant class
- Make another class or function in the same file after it
- Ask claude to add method to giant class
- See that claude tries to add it to second class/function in same file instead
Expected Behavior
Method is added to giant class
Actual Behavior
Method gets added to wrong class - resulting in compile errors because method tries to reference properties of giant claass.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗