Skip to content

[BUG] VSCode Extension fails to load with ServiceWorker error when ~/.claude/projects folder doesn't exist #17822

Description

@NiceBlueSky8

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

The Claude Code VSCode extension fails to load with a ServiceWorker registration error. The webview remains blank and displays the error:

Error loading webview: Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state..
Image

After debugging, I found two issues:

  1. Missing projects folder: The extension tries to scandir on ~/.claude/projects/ which doesn't exist. The folder was never created during installation.

  2. Corrupted Service Worker cache: The %APPDATA%\Code\Service Worker folder contained corrupted cache data.

Workaround:

  1. Create the missing folder: mkdir "$env:USERPROFILE\.claude\projects"
  2. Close VSCode, delete %APPDATA%\Code\Service Worker, restart VSCode

What Should Happen?

The extension should:
1. Automatically create `~/.claude/projects` folder if it doesn't exist during initialization
2. Handle missing project subdirectories gracefully without crashing
3. Not leave the webview in an unrecoverable ServiceWorker error state

Error Messages/Logs

[Extension Host] rejected promise not handled within 1 second: Error: ENOENT: no such file or directory, scandir 'C:\Users\sample_user\.claude\projects\c--Users-sample_user-dev-sample-project'

[Extension Host] stack trace: Error: ENOENT: no such file or directory, scandir 'C:\Users\sample_user\.claude\projects\c--Users-sample_user-dev-sample-project'
	at async readdir (node:internal/fs/promises:958:18)
	at async t.performRefresh (c:\Users\sample_user\.vscode\extensions\anthropic.claude-code-2.1.5-win32-x64\extension.js:17:7322)
	at async t.load (c:\Users\sample_user\.vscode\extensions\anthropic.claude-code-2.1.5-win32-x64\extension.js:17:7148)

[Anthropic.claude-code] ENOENT: no such file or directory, scandir 'C:\Users\sample_user\.claude\projects\c--Users-sample_user-dev-sample-project'

Webview fatal error: Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state..

Error loading webview: Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state..

Steps to Reproduce

  1. Fresh install (or reinstall) Claude Code VSCode extension v2.1.5
  2. Ensure ~/.claude/projects folder does NOT exist (only ~/.claude/ide exists)
  3. Open any project in VSCode
  4. Click the Claude Code icon to open the panel
  5. Extension fails to load with ServiceWorker error and blank webview

Environment:

  • Windows 11
  • VSCode (latest stable)
  • Claude Code Extension v2.1.5

Claude Model

None

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.5

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

Suggested Fix:

Add defensive initialization code in the extension:

const projectsDir = path.join(os.homedir(), '.claude', 'projects');
if (!fs.existsSync(projectsDir)) {
  fs.mkdirSync(projectsDir, { recursive: true });
}

Notes:

  • The ~/.claude/ide folder was correctly created by the extension
  • Only the projects folder was missing
  • This appears to be a missing initialization step during extension setup

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions