Skip to content

Blog

Solution for the Codex plugin failing to open when launching VS Code from the taskbar on Linux

About 7 min read

Existing English translations were reused. 1 current source blocks remain in Simplified Chinese, without triggering paid translation.

1.Problem symptom

In a Linux desktop environment, I encountered a very strange problem:

  • Run in the terminalcode .Startup VS Code, and the Codex plug-in can open normally;
  • Start it by clicking the VS Code icon in the KDE taskbar, but the Codex plug-in fails to load properly.

If you have also encountered the situation where "the same VS Code starts normally from the terminal but abnormally from the taskbar," you can first check whether the programs actually executed by the two startup methods are the same.

2.Differences between the two startup methods

In my system, after VS Code is installed, the following two entries exist:

/usr/share/code/code
/usr/bin/code

They all appear to be able to launch VS Code, but their actual uses are not exactly the same.

2.1./usr/share/code/code

This is VS Code's Electron main program, that is, the actual GUI executable file.

Run directly:

/usr/share/code/code .

Equivalent to directly launching an Electron application.

2.2./usr/bin/code

This is the command-line launch entry point provided by VS Code. On my system, it is a symbolic link:

ls -l /usr/bin/code

Output similar to:

/usr/bin/code -> /usr/share/code/bin/code

/usr/share/code/bin/codeIt is a Shell script. It will invoke VS Code's CLI logic, and then the CLI will create a new window or connect to an already running VS Code process.

You can view the actual path:

readlink -f /usr/bin/code

Therefore, the following command does not simply execute the Electron main program directly:

code .

3.How to confirm whether it is a problem with the startup entry point

First exit all VS Code windows normally, then test the following two commands separately.

Run the GUI program directly:

/usr/share/code/code .

Run through the official CLI entry point:

/usr/bin/code .

In my environment, the former method cannot properly enter the Codex plugin, while the latter method works normally.

Next, check the system's VS Code desktop launcher:

grep '^Exec=' /usr/share/applications/code.desktop

The original configuration was:

Exec=/usr/share/code/code %F
Exec=/usr/share/code/code --new-window %F

这就解释了为什么点击任务栏图标和在终端执行code会得到不同结果:任务栏直接执行了Electron主程序,而终端使用的是VS Code CLI入口。

Paths may differ across distributions and installation methods. Before making changes, first confirm the actual path throughcommand -v code、readlink -f "$(command -v code)"and theExecfield in the desktop file.

4.Fix using user-level desktop file

Not recommended to modify directly:

/usr/share/applications/code.desktop

This file is managed by the system package manager and may be overwritten after a VS Code upgrade. A more appropriate method is to create a desktop file with the same name in the current user directory to override the system launcher.

4.1.1. Create a user-level application directory

mkdir -p ~/.local/share/applications

4.2.2. Copy the system desktop file

cp /usr/share/applications/code.desktop \
  ~/.local/share/applications/code.desktop

4.3.3. Modify the startup path

Replace all/usr/share/code/codewith/usr/bin/code:

sed -i \
  's#/usr/share/code/code#/usr/bin/code#g' \
  ~/.local/share/applications/code.desktop

4.4.4. Check the modification result

grep '^Exec=' ~/.local/share/applications/code.desktop

The correct result should be:

Exec=/usr/bin/code %F
Exec=/usr/bin/code --new-window %F

4.5.5. Refresh desktop app cache

A general desktop database can be refreshed as follows:

update-desktop-database ~/.local/share/applications

If using KDE Plasma, then run:

kbuildsycoca6 --noincremental

Older KDE versions may use:

kbuildsycoca5 --noincremental

5.Repin Taskbar Icon

Even if the desktop file has been modified, the original pinned icon in the KDE taskbar may still retain old launch information. Therefore, you also need to:

  1. Unpin the original VS Code icon from the taskbar;
  2. Search for "Visual Studio Code" again in the application menu;
  3. Launch it once from the application menu and test the Codex plugin;
  4. After confirming it works properly, pin the new icon to the taskbar.

Afterwards, launching VS Code from the taskbar will use:

/usr/bin/code

It uses the same startup entry point as thecodecommand in the terminal.

6.Restore original configuration

If restoration is needed after modification, simply delete the user-level override file and refresh the cache:

rm ~/.local/share/applications/code.desktop
update-desktop-database ~/.local/share/applications
kbuildsycoca6 --noincremental

After deletion, the system will reuse:

/usr/share/applications/code.desktop

7.Summary

The key to this issue is not the Codex plugin itself, but the different startup entry points of VS Code:

任务栏 → /usr/share/code/code → 直接启动Electron主程序
终端   → /usr/bin/code        → 通过VS Code CLI启动

Change the desktop startup command in the taskbar to/usr/bin/codeAfter that, the two startup methods remain consistent, and the Codex plugin can also enter normally.