Claude repeatedly adds inline imports despite corrections and context

Resolved 💬 3 comments Opened Nov 10, 2025 by Cybis320 Closed Nov 13, 2025

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:

  1. Module-level imports already existing for the same module
  2. Being corrected multiple times in the same conversation
  3. Previous discussions about multiprocessing/pickling issues caused by inline imports
  4. 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:

  1. Check if module is already imported at file level
  2. Only add inline imports when explicitly needed (dynamic imports, type checking, etc.)
  3. 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

View original on GitHub ↗

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