AI agents in VS Code use the wrong Python environment:
- Manual terminals: Use configured project environment
- AI agent terminals: Default to system base environment
AI agents request terminals directly from VS Code core, bypassing the Python extension's automatic environment activation.
Configure a custom terminal profile in .vscode/settings.json:
{
"python.defaultInterpreterPath": "/path/to/conda/envs/myenv/bin/python",
"python.terminal.activateEnvironment": true,
"python.terminal.activateEnvInCurrentTerminal": true,
"terminal.integrated.profiles.osx": {
"myenv": {
"path": "/bin/zsh",
"args": ["-c", "source /path/to/conda/etc/profile.d/conda.sh && conda activate myenv && exec zsh"]
}
},
"terminal.integrated.defaultProfile.osx": "myenv",
"terminal.integrated.env.osx": {
"CONDA_DEFAULT_ENV": "myenv",
"CONDA_PREFIX": "/path/to/conda/envs/myenv",
"PATH": "/path/to/conda/envs/myenv/bin:${env:PATH}",
"CONDA_AUTO_ACTIVATE_BASE": "false"
}
}Replace .osx with:
- macOS:
.osx - Windows:
.windows - Linux:
.linux
- Custom Profile:
terminal.integrated.profiles.osx.myenvcreates a profile that auto-activates conda - Default Profile:
terminal.integrated.defaultProfile.osxmakes it the default for ALL terminals - Args Chain: Sources conda, activates environment, starts interactive shell
The args array ensures every terminal:
- Loads conda functions
- Activates your environment
- Starts normal interactive shell
Test in fresh terminal:
echo $CONDA_DEFAULT_ENV # Should show: myenv
python --version
which python # Should point to your environment- Restart VS Code after configuration changes
- Verify all paths are correct for your system
- Ensure conda command works in your shell
- Use correct platform suffix (osx/windows/linux)
- Project-specific configuration
- Works for both manual and AI agent terminals
- No global system changes required
- Portable with your project