Claude repeatedly adds inline imports despite corrections and context
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?
Category: Code Quality / Learning from Corrections
Description:
Claude consistently adds inline import statements inside functions despite:
- Module-level imports already existing for the same module
- Being corrected multiple times in the same conversation
- Previous discussions about multiprocessing/pickling issues caused by inline imports
- Clear context that inline imports are problematic
Example from today's session:
# Module already has: import time (line 21)
# But Claude added inside worker function:
def process_flight_masks_worker(args):
import time # ← Added despite module-level import!
t_start = time.perf_counter()
# ...
Frequency: Recurring issue over months of use
Context: Python multiprocessing code, spawn context, module-level worker functions
What Should Happen?
Expected behavior:
Before adding any import, Claude should:
- Check if module is already imported at file level
- Only add inline imports when explicitly needed (dynamic imports, type checking, etc.)
- Learn from corrections within the conversation
Frequency: Recurring issue over months of use
Context: Python multiprocessing code, spawn context, module-level worker functions
Error Messages/Logs
Steps to Reproduce
Not sure
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.0.36
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
VS Code integrated terminal
Additional Information
Issue has been present since version 1
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗