Running sbt from a terminal while IntelliJ's sbt shell is open
How I use IntelliJ’s sbt shell
I’ve been developing in Scala with IntelliJ for a long time, and more precisely using its sbt shell for project reload and build. It dates back to a time when this setup was the best way to avoid quirks where a project compiles with sbt but is red in IntelliJ. I’ve kept using it because it works.
IntelliJ launches sbt with this command (simplified for readability):
java -jar sbt-launch.jar idea-shell
Running another sbt in a terminal
Now, when Claude or I try to run sbt in a terminal:
❯ sbt
[info] sbt server is booting up
The process hangs. If I stop IntelliJ’s sbt shell, the terminal sbt unblocks and starts.
Analysis
- My terminal sbt (2.0.x) runs the native client,
sbtn, by default. sbtnfinds the boot socket, which means an sbt instance for this directory is still starting. It printssbt server is booting upand waits for the real server.- Normally, sbt starts its server when its
shellcommand begins, then closes the boot socket. IntelliJ replacesshellwithidea-shell, which never starts the server, so the boot socket stays open for the whole session. - The client waits for a server that never comes, so it looks stuck.
Possible fixes
1. Start the server from IntelliJ
Type startServer in IntelliJ’s sbt shell. sbt then opens its real server, and the terminal sbt connects to it and shares the same build. You can use both at once.
=> We have to remember to start the server every time we start IntelliJ’s sbt shell. It’s manual, so it’s error-prone and not very friendly.
2. Run a standalone sbt in the terminal
sbt --server runs in the foreground instead of going through sbtn. If it reports that a server is already booting, answer yes to start a separate one. You get two independent JVMs.
=> Two sbt servers writing to the same target/ directory may conflict.
3. Stop IntelliJ’s sbt shell
Close IntelliJ’s sbt shell window, or turn off “Use sbt shell for build and import” in Settings → Build Tools → sbt.
=> Only one sbt can run at a time, and switching is manual, so it doesn’t play well with agentic coding.
4. Switch to BSP
When you import an existing project, a pop-up asks you to choose between sbt and BSP.
=> I’m currently experimenting with this option.
Conclusion
By default, IntelliJ’s sbt shell doesn’t play well with Claude. This is an example of a broader topic: with the rise of AI, we spend less time coding and more time solving a new class of problems created by this new way of working.