Code is already running / Cannot edit in read-only editor

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
5 min

banner

# Code is already running / Cannot edit in read-only editor

The following two VS Code errors occur for the same reasons:

  • Code is already running
  • Cannot edit in read-only editor

cannot edit in read only editor settings json

The most common causes are:

  1. Trying to edit code in the Output view (e.g. when using the Code Runner extension). Instead, you should run your code in the terminal.
  2. Trying to edit your default settings.json file. Instead, you should edit the global user settings.json file.
  3. Trying to edit the left side of a git diff file comparison. Instead, you should open the file in editable mode.

# Trying to edit code in the Output view in VS Code

To solve the errors in VS Code:

  1. Press Ctrl + Shift + P (or Command + Shift + P on macOS).
Note: you can also press F1 to open the Command Palette.
  1. Type user settings and select Preferences: Open User Settings.

open user settings

You can also open the settings screen by pressing Ctrl + , on Windows and Linux or Cmd + , on macOS.

  1. Type Code Runner terminal and tick the Code-runner: Run in terminal checkbox.

tick-code-runner-run-in-terminal-checkbox

Make sure to check the Code-runner: Run in terminal checkbox as shown in the code sample.

Alternatively, you can enable the setting directly in your settings.json file.

  1. Press Ctrl + Shift + P (or Command + Shift + P on macOS).
Note: you can also press F1 to open the Command Palette.
  1. Type user settings json.

  2. Click on Preferences: Open User Settings (JSON)

preferences open user settings

  1. Add the following line to your settings.json file.
settings.json
{ "code-runner.runInTerminal": true }

set code runner to run in terminal

Either approach works.

After you set the setting, restart VS Code:

  1. Press Ctrl + Shift + P (or Command + Shift + P on macOS).
Note: you can also press F1 to open the Command Palette.
  1. Type reload window and select Developer: Reload Window.

reload window

Try to run your code after having enabled the setting.

You can click on the arrow in the top right corner to run your code in the terminal.

click on arrow to run your code

You can also right-click in the editor window and select Run Code.

right click run code

You can also use the Command Palette:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Run code and select the command.

run code using command palette

# Using the Stop Code Run command in the Output tab

If your code is stuck in the Output tab, right-click and select Stop Code Run.

right click select stop code run

You can also stop the Code Runner process by using a keyboard shortcut:

  • Ctrl + Alt + M on Windows and Linux.
  • Cmd + Option + M on macOS.

# Restart all VS Code instances if the error persists

If the error persists, you might have a VS Code process that runs in the background.

On Windows, open CMD and run the following command to stop all VS Code processes.

cmd
# Windows taskkill /F /IM code.exe

On macOS and Linux, run the following command to stop all VS Code processes.

shell
# macOS and Linux killall code

If the killall command doesn't succeed on macOS or Linux, try issuing the following command instead.

shell
ps -ef | grep code | awk {'print $2'} | xargs kill -9

Once you run the command and stop all VS Code processes, restart the IDE and try to run your code.

# Closing the terminal properly once you're done

Note that when you click on the x icon at the top right corner of the terminal, you don't actually close it.

close terminal properly

If you click on the x icon, the terminal still runs in the background.

You need to click on the trash bin icon to close it and stop the process.

# Trying to edit your default settings.json file

You can't edit the default settings.json file because it is in read-only mode.

cannot edit in read only editor settings json

Instead, you should open the global user's settings.json file which is editable.

  1. Press Ctrl + Shift + P (or Command + Shift + P on macOS).
Note: you can also press F1 to open the Command Palette.
  1. Type user settings json.

  2. Click on Preferences: Open User Settings (JSON)

preferences open user settings

Now you can edit the non-default version of the settings.json file.

If you want to read more about the different ways to open and edit settings.json, check out my other article:

# Trying to edit the left side of a git diff file comparison

If you clicked on the source control icon in the Activity bar on the left, you most likely opened a git diff split screen.

The left side of the screen is the previous version of the file, so you aren't able to edit it.

cannot edit in read only editor git diff

To resolve the issue, click on the explorer icon at the top of the Activity bar and open the file in editable mode.

open file in editable mode

You shouldn't see two versions of the file in a split screen once you open it in editable mode.

# Try to disable your extensions

If the error persists, try to disable your extensions.

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type disable extensions and select Extensions: Disable all installed extensions.

  2. Restart VS Code.

  3. Check if you can edit the file.

If you can edit the file after disabling all installed extensions, try to enable them one by one to see which extension caused the issue.

I've also written an error on how to solve the issue where the Live Server extension doesn't work in VS Code.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.