Check if running in VS Code inside startup.jl

Is there a way to determine, inside of startup.jl, whether a Julia REPL session is running inside of VS Code?

Checking if Logging.current_logger() isa VSCodeServer.VSCodeLogger seems to work once the REPL prompt is actually available, but in startup.jl will fail with UndefVarError: `VSCodeServer` not defined outside of an atreplinit or will return false if inside of one.

I guess other than at startup I’d be interested to know if there’s a way of checking if a script is running in VS Code but for now my use case is just at REPL startup, in order to decide whether or not to import certain things, e.g. OhMyREPL or TerminalExtensions.

You can check the environment for ENV["TERM_PROGRAM"] == "vscode".

3 Likes