Repository navigation
Slow virtualenv activation in terminal may cause wrong command execution and potential data loss #25435
Description
Type: Bug
Behaviour
When opening a terminal, the Python virtualenv activation command (e..g source /path/to/.venv/bin/activate) is issued too late. Most of the time, I’ve already started typing another command before activation occurs. As a result, the activation command is appended to whatever I was typing, and the combined text is executed as-is. This causes the virtualenv activation to fail, and the command I was entering is also lost.
This seems potentially dangerous, because it can result in excuting commands I never intended to run. For example, if I type rm and the activation triggers right after, the executed command becomes: rm source /path/to/.venv/bin/activate. This would obviously delete the listed paths.
This appears to be the same issue described in the now-closed #15719 (2021). That issue includes a video that already demonstrates the problem well, so I haven’t recorded a new one. Here's the video from the old issue:
Peek.19-03-2021.07-50.mp4
The problem seems to be shell-agnostic: I can reproduce it in both Bash and Fish. It’s also not caused by my custom shell configuration, since it still happens when running Bash with --noprofile --norc.
Steps to reproduce:
- Open a new internal terminal (panel or editor area)
- Start typing a command immediately
- Notice that your input is appended with the virtualenv command and executed together
Diagnostic data
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
2025-09-04 13:19:15.065 [info] > pyenv which python
2025-09-04 13:19:15.066 [info] cwd: .
2025-09-04 13:19:28.051 [info] Active interpreter [/home/ige/repos/pythontest]: /home/ige/repos/pythontest/.venv/bin/python
2025-09-04 13:19:30.733 [info] Starting Pylance language server.
2025-09-04 13:19:37.000 [info] Send text to terminal: source /home/ige/repos/pythontest/.venv/bin/activate
Extension version: 2025.12.0
VS Code version: Code 1.103.1 (360a4e4fd251bfce169a4ddf857c7d25d1ad40da, 2025-08-12T16:25:40.542Z)
OS version: Linux x64 6.15.9-201.fc42.x86_64+debug
Modes:
Remote OS version: Linux x64 6.15.9-201.fc42.x86_64+debug
- Python version: 3.13.3
- Type of virtual environment used: venv
- Value of the
python.languageServersetting: Default
User Settings
languageServer: "Pylance"
testing
• pytestArgs: "<placeholder>"
• pytestEnabled: true
• pytestPath: "<placeholder>"
experiments
• enabled: false
• optOutFrom: ["pythonTerminalEnvVarActivation"]
Installed Extensions
| Extension Name | Extension Id | Version |
|---|---|---|
| Bookmarks | ale | 13.5.0 |
| cloudcode | goo | 2.36.0 |
| code-spell-checker | str | 4.2.6 |
| copilot | Git | 1.364.0 |
| copilot-chat | Git | 0.30.3 |
| debugpy | ms- | 2025.10.0 |
| even-better-toml | tam | 0.21.2 |
| geminicodeassist | goo | 2.47.0 |
| gitlab-workflow | Git | 6.40.1 |
| gitlens | eam | 17.4.1 |
| js-debug | ms- | 1.102.0 |
| markdown-all-in-one | yzh | 3.6.3 |
| python | ms- | 2025.12.0 |
| ruff | cha | 2025.24.0 |
| shellcheck | tim | 0.38.3 |
| vscode-js-profile-table | ms- | 1.0.10 |
| vscode-kubernetes-tools | ms- | 1.3.26 |
| vscode-markdownlint | Dav | 0.60.0 |
| vscode-pylance | ms- | 2025.7.1 |
| vscode-python-envs | ms- | 1.2.0 |
| vscode-yaml | red | 1.18.0 |
System Info
| Item | Value |
|---|---|
| CPUs | AMD Ryzen 7 PRO 4750U with Radeon Graphics (16 x 1409) |
| GPU Status | 2d_canvas: enabled direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_graphite: disabled_off trees_in_viz: disabled_off video_decode: enabled video_encode: disabled_software vulkan: disabled_off webgl: enabled webgl2: enabled webgpu: disabled_off webnn: disabled_off |
| Load (avg) | 6, 6, 5 |
| Memory (System) | 26.49GB (6.57GB free) |
| Process Argv | --new-window --crash-reporter-id b1a9997c-d502-48ce-9353-1ad864d1ffab |
| Screen Reader | no |
| VM | 0% |
| DESKTOP_SESSION | gnome |
| XDG_CURRENT_DESKTOP | GNOME |
| XDG_SESSION_DESKTOP | gnome |
| XDG_SESSION_TYPE | wayland |
| Item | Value |
|---|---|
| Remote | Dev Container: zeevending-support-backend @ unix:///run/user/1000/podman/podman.sock |
| OS | Linux x64 6.15.9-201.fc42.x86_64+debug |
| CPUs | AMD Ryzen 7 PRO 4750U with Radeon Graphics (16 x 3217) |
| Memory (System) | 26.49GB (6.56GB free) |
| VM | 0% |
A/B Experiments
vsliv368cf:30146710
vswsl492:30256859
binariesv615:30325510
nativeloc1:31344060
dwcopilot:31170013
dwoutputs:31242946
copilot_t_ci:31333650
e5gg6876:31282496
996jf627:31283433
pythonrdcb7:31342333
usemplatestapi:31297334
747dc170:31275177
aj953862:31281341
nesew2to5:31336538
agentclaude:31350858
nes-set-on:31351930
testaa123cf:31335227
onetestforazureexp:31335613
6abeh943:31336334
0927b901:31350571
custommodel2t:31371781
45650338:31358607
0cj2b977:31352657
cloudbuttonc:31374191
retryenabled:31370050
todos-0:31378732
search_len_ctrl:31378778
3efgi100_wstrepl:31374188
Activity
danielpassy commentedon Sep 4, 2025
Extra issue with that:
Sometimes I run something with
run and debugIt opens a new console, insert the command but then a env activation stops the command.
launch.json{ "version": "0.2.0", "configurations": [ { "name": "Django Debug", "type": "debugpy", "request": "launch", "program": "${workspaceFolder}/manage.py", "args": [ "runserver", "0.0.0.0:8000" ], "django": true, "justMyCode": false, "env": { "MANAGE_PY_PATH": "manage.py" }, }, ] }Results:
The debugger hangs for quite a while and then
The workaround is quite simple, bug really annoying, stop the debugger and let this shell open
anthonykim1 commentedon Sep 8, 2025
Make sure you have environment extension enabled and set
python-envs.terminal.autoActivationTypeto shellStartup.Try with vscode insiders https://code.visualstudio.com/insiders/ and latest pre-release of environment extension.
If you do shell startup, you dont have to rely on the order of commands being sent to terminal.
eleanorjboyd commentedon Sep 12, 2025
Let us know if this helps at all- we are continuing to investigate slowness in the terminal and believe it might be part of the transition to the environments extension which should be fixed once we fully switch and can remove old code as well
github-actions commentedon Oct 13, 2025
Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on, then we will be happy to re-open this issue to pick up where we left off.
Happy Coding!
Ige-kun commentedon Oct 14, 2025
Anthony Kim (@anthonykim1) Eleanor Boyd (@eleanorjboyd) This is still reproducible on the latest Insiders (1.106.0-insider) and the latest Python Environments extension preview (1.11.12861008) when using the default settings.
Only when setting
"python-envs.terminal.autoActivationType": "shellStartup"does the issue go away.