diff --git a/scripts/lib/devtool/ide_plugins/ide_code.py b/scripts/lib/devtool/ide_plugins/ide_code.py
index 081dc08657..39356dcfb1 100644
--- a/scripts/lib/devtool/ide_plugins/ide_code.py
+++ b/scripts/lib/devtool/ide_plugins/ide_code.py
@@ -77,6 +77,7 @@ class IdeVSCode(IdeBase):
     A workspace cannot be created because there is no recipe that defines how a workspace could
     be set up.
     - cmake: adds a cmake-kit to .local/share/CMakeTools/cmake-tools-kits.json
+             (below XDG_DATA_HOME instead of .local/share if it is set)
              The cmake-kit uses the environment script and the tool-chain file
              generated by meta-ide-support.
     - meson: Meson needs manual workspace configuration.
@@ -95,8 +96,10 @@ class IdeVSCode(IdeBase):
         deploy_dir_image = shared_env.ide_support.deploy_dir_image
         real_multimach_target_sys = shared_env.ide_support.real_multimach_target_sys
         standalone_sysroot_native = shared_env.build_sysroots.standalone_sysroot_native
-        vscode_ws_path = os.path.join(
-            os.environ['HOME'], '.local', 'share', 'CMakeTools')
+        # CMake Tools stores its user data in XDG_DATA_HOME, if it is set
+        data_home = os.environ.get('XDG_DATA_HOME') or os.path.join(
+            os.environ['HOME'], '.local', 'share')
+        vscode_ws_path = os.path.join(data_home, 'CMakeTools')
         cmake_kits_path = os.path.join(vscode_ws_path, 'cmake-tools-kits.json')
         oecmake_generator = "Ninja"
         env_script = os.path.join(
