[BUG] Extension deletes claudeCode.environmentVariables from settings.json upon activation in trusted workspace

Resolved 💬 4 comments Opened Oct 24, 2025 by fairplayapps Closed Oct 24, 2025

Preflight Checklist

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

What's Wrong?

The claudeCode.environmentVariables setting, specifically containing the ANTHROPIC_API_KEY, disappears from the User settings.json file every time VS Code is restarted, but only when the Claude Code extension is enabled and the workspace is trusted. The setting saves and persists correctly under other conditions.

What Should Happen?

The key should save and persist.

Error Messages/Logs

Expected behavior The claudeCode.environmentVariables section with the API key should still be present in the settings.json file.

Actual behavior The entire claudeCode.environmentVariables section (or sometimes just its content) is missing from the settings.json file. The extension effectively deletes its own configuration upon restart/activation.

Additional context/Troubleshooting:

This issue does not occur if the Claude Code extension is disabled.

This issue does not occur if the workspace is opened in Restricted Mode (even with the extension enabled). The setting only disappears after trusting the workspace and restarting.

This issue does not occur in a clean installation of VS Code Insiders (tested version [If you tested, enter Insiders version]).

This issue was reproduced on two separate computers with different user accounts and VS Code profiles (different sign-ins).

Settings Sync was confirmed to be disabled during testing.

All other extensions were disabled during testing.

VS Code was tested running as administrator (on Windows) with no change in behavior.

Antivirus and OneDrive sync were temporarily disabled with no change in behavior.

Creating a fresh settings.json file (by renaming the old one) did not solve the issue.

Workaround: Setting the ANTHROPIC_API_KEY as a system/user environment variable allows the extension to authenticate correctly, even though it removes the setting from settings.json.

Steps to Reproduce

Ensure the workspace/folder is trusted (VS Code is not in Restricted Mode).

Ensure the Claude Code extension is enabled.

Open User settings.json (Ctrl+Shift+P -> Preferences: Open User Settings (JSON)).

Add or ensure the following configuration exists, replacing the placeholder value with a valid API key:

JSON

"claudeCode.environmentVariables": [
{
"name": "ANTHROPIC_API_KEY",
"value": "sk-ant-..."
}
]
Save the settings.json file. The changes are visibly saved.

Completely close VS Code.

Reopen VS Code and the same workspace/folder.

Open User settings.json again.

Claude Model

Not sure / Multiple models

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.0.26

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

_No response_

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗