mpremote: could not enter raw repl, or the port is in use

Both errors come from mpremote needing the board’s serial port to itself, and a clean hand-over to the raw REPL. Here is what each one means, what to check first, and how a coding agent can work in the REPL your terminal already has open.

The two errors

mpremote: failed to access COM5 (it may be in use by another program)

mpremote could not open the port. On Linux the same line names /dev/ttyACM0 or /dev/ttyUSB0. With no port named, mpremote tries each USB serial port and skips the ones it cannot open, so a busy board can also end in no device found.

mpremote: could not enter raw repl

The port opened, but the board did not answer the raw REPL hand-over in time (10 s by default).

Why it happens

A serial port has one owner. Thonny, a serial monitor, a VS Code extension, a second mpremote, or a terminal tab that is still connected all hold it, and on Windows the next program gets failed to access.

To run anything, mpremote sends Ctrl+C to stop the running program, Ctrl+A to enter the raw REPL, then Ctrl+D for a soft reset, and waits for raw REPL; CTRL-B to exit and soft reboot. It gives up with could not enter raw repl when one of them does not arrive: a main.py that does not stop on Ctrl+C or keeps printing, a boot.py that takes longer than the timeout, or a board that restarts when the port opens. ESP32 boards with an auto-reset circuit, and ESP32-C3 and C6 boards on their built-in USB, can restart on open; the bytes mpremote sent then land before the new prompt.

Check first

  • Close every other program on the port, then run mpremote connect list to see the port name and its USB ID.
  • Open the plain REPL and press Ctrl+C. No >>> means the program does not stop; rename main.py from a fresh boot, or reflash.
  • mpremote resume skips the soft reset, so a slow boot.py does not run again. It still sends Ctrl+C.
  • For a board that restarts on open, wait for the prompt and run mpremote again.

Sources: transport_serial.py and commands.py in mpremote, and Thonny issue #3921 (August 2026) on a board that resets when the port opens.

With a coding agent in NeuroTerm

A coding agent that runs mpremote while your terminal holds the port meets the first error; one that opens the port again each time restarts some boards. In NeuroTerm the serial tab keeps the port open, and Terminal Use, NeuroTerm’s MCP server, lets Claude Code or Codex work in that tab instead: it reads the REPL’s output there, and it types into it, text and keys such as Ctrl+C, Ctrl+E for paste mode and Ctrl+D, waiting for >>> before it goes on.

Reading needs no approval. Before the agent types, the tab shows the request and waits for Allow or Deny. When it needs mpremote itself, for example for mpremote cp or mip install, it asks to borrow the port: NeuroTerm closes it so the agent’s mpremote can use it, and reopens it in the tab when the agent gives it back. Reopening may reset the board.

Claude Code and Codex on your serial port · Terminal Use (MCP) setup and tools