Last updated: ยท Applies to: Claude Code in VS Code; qualified and older webview ServiceWorker errors
Error loading webview provided by 'anthropic.claude-code': Could not register service worker: InvalidStateError / Error loading webview: Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state.
For Error loading webview provided by 'anthropic.claude-code': Could not register service worker: InvalidStateError, or the older Error loading webview: Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state., start by fully quitting VS Code. Then test an isolated environment and, if needed, a reversible rename of only its Service Worker directory.
Recognize both error wordings
The qualified message is Error loading webview provided by 'anthropic.claude-code': Could not register service worker: InvalidStateError. Older reports show Error loading webview: Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state. without an extension identifier. Both describe the same VS Code webview ServiceWorker registration failure; the Codex counterpart names openai.chatgpt instead.
VS Code issue #330595 reports the error with Claude and Git Graph. Claude Code issue #24142 includes users for whom reinstalling did not help. Reinstalling Claude Code alone often does not fix this reported failure; the extension name in the message is not proof that its installation is the cause.
Recover in this order
Fully quit every VS Code window
Save your work and exit every VS Code window. Check that editor processes belonging to your session have stopped before reopening. A window reload is not enough for this test: one Codex report found lingering processes after Reload Webviews failed. In VS Code #330595, a contributor suggested restarting and the reporter confirmed recovery after another restart. Reopen VS Code and test Claude Code.
Test fresh user-data and extension directories
The official VS Code CLI supports both isolation flags. For a standard, non-portable installation, use fresh, unused paths. This example is for Windows Command Prompt (
cmd.exe):code --user-data-dir "%TEMP%\claude-webview-test-data" --extensions-dir "%TEMP%\claude-webview-test-extensions"On Linux or macOS, substitute new temporary directory paths. Install only Claude Code in that isolated environment and test without importing your usual profile. A successful test identifies an environment difference; it does not identify a particular cache or extension as the cause. Portable Mode: its
datafolder overrides both directory flags, so use a standard, non-portable VS Code installation for this test.After full exit, rename only the Service Worker directory
If needed, fully exit VS Code again. In File Explorer, rename
%APPDATA%\Code\Service Workerto an unused backup name, such asService Worker.backup-2026-11-12. Keep the backup. This adapts the reversible Windows workaround in Codex #14745; one Claude Code user in #17822 also recovered after clearing only that folder.For standard Linux VS Code, the corresponding default path is
~/.config/Code/Service Worker. Linux reports in #24142 describe the same symptom, while the Portable Mode documentation identifies the default user-data root. A rename there is a reversible troubleshooting test, not a verified Linux cure. If you use a custom user-data location, inspect that location instead of assuming these defaults.Reopen and test. If ineffective, fully exit again, move any newly created
Service Workerdirectory aside, then restore the backup to its original name. Do not overwrite your backup or blindly wipestate.vscdb,globalStorageor all of.claude.Verify the panel and a small request
Confirm Claude Code opens and a small request completes. If the error persists, record the exact message, OS, editor and extension versions, and isolated-test result. These steps are conservative diagnostics based on official VS Code facilities and community recovery reports; the cited sources do not establish an official Anthropic fix.
What individual reports do and do not establish
In #17822, one reporter also lacked ~/.claude/projects; another user recovered by clearing only the Service Worker folder. The missing directory is an observation from one report, not a universal cause or a reason to erase Claude state.
#24142 includes individual workarounds involving broader cache directories or resource pressure. Those reports do not establish first-line official fixes. The Fedora report in Codex #58111 shows the same failure with another extension name and a version comparison; it does not justify installing a Codex version to repair Claude Code.
FAQ
Does reinstalling Claude Code fix this error?
Reinstalling Claude Code alone often does not fix this reported webview failure. Start with a full VS Code exit, then compare an isolated environment before trying a reversible Service Worker directory rename.
Should I delete state.vscdb, globalStorage or all of .claude?
No. Preserve editor and Claude data. After a full editor exit, rename only the Service Worker directory to an unused backup name for this test. Keep the backup and restore it if the test is ineffective.
Is this the same ServiceWorker error as Codex?
Yes. Both messages describe a VS Code webview ServiceWorker registration failure, with a different extension identifier. That shared symptom does not establish a single root cause or guarantee the same workaround will work.
Sources
- VS Code #330595: restart advice and reported recovery
- Official VS Code command-line options
- Official VS Code Portable Mode and user-data locations
- Claude Code #17822: ServiceWorker community reports
- Claude Code #24142: cross-platform reports and individual workarounds
- Codex #58111: Fedora report with the same webview failure
- Codex #14745: full exit and reversible Windows folder rename
This is an independent, unofficial help site. It is not affiliated with or endorsed by Anthropic or OpenAI. Check the linked documentation and reports for your environment.