Repository navigation
Typing messes up terminal/venv activation #24589
Description
Activity
- addedtriage-neededNeeds assignment to the proper sub-teamNeeds assignment to the proper sub-team
on Dec 12, 2024 - changed the title
[-]source command race condition[/-][+]Typing messes up terminal/venv activation[/+]on Dec 12, 2024 karthiknadig commented
on Dec 12, 2024 MemberMore actionsWe can’t avoid running activation scripts in cases where VS Code is not launched from an activated environment. The best thing to do here is turn off activation and launch VS Code from an activated environment.
Here is how:
- Navigate to your project from an external terminal
- Activate your environment
- run
code .
This will star VS Code itself in an activated environment and there is no need for us to activate it later.
- addedinfo-neededIssue requires more information from posterIssue requires more information from poster
on Dec 12, 2024 I don't mind if it's running activation scripts, but is it possible that it won't interfere with the terminal input?
- removedinfo-neededIssue requires more information from posterIssue requires more information from poster
on Dec 12, 2024 karthiknadig commented
on Dec 12, 2024 MemberMore actionsUnfortunately it has the same behavior with shell integration enabled
- added and removedtriage-neededNeeds assignment to the proper sub-teamNeeds assignment to the proper sub-team
on Dec 12, 2024 It looks like timeout https://github.com/microsoft/vscode-python/blob/main/src/client/common/terminal/service.ts#L100 is not "long enough" to wait for executeCommand.
If j4k0xb check your Python output after setting your log level to "trace"
You will see something along the lines of "send text...source /tmp/test/venv/bin/activate..." instead of "executeCommand...source /tmp/test/venv/bin/activate..."We may have to do improve to more frequently use executeCommand such as via caching shell integration state from previous session. Or figure out different way to completely wait for activate command before allowing user input in terminal.
Using pwsh 6 or 7 instead of the default windows pwsh provided by Microsoft can really help with executeCommand, shell integration related.
j4k0xb I assume you will notice the duplicate commands wont really happen after the very first run in terminal. Is that correct?
- addedbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bug
on Dec 12, 2024 check your Python output after setting your log level to "trace"
You will see something along the lines of "send text...source /tmp/test/venv/bin/activate..." instead of "executeCommand...source /tmp/test/venv/bin/activate..."yes
I assume you will notice the duplicate commands wont really happen after the very first run in terminal. Is that correct?
I only encountered this issue during the first activation in a terminal
Reacted by Anthony KimThanks for the info
j4k0xb Can you switch to using pwsh 6 or pwsh 7 instead of the windows powershell provided by default in your Windows OS and see if you can still repro the problem?instead of the windows powershell provided by default in your Windows OS
(I don't use Windows or PowerShell)
but can repro with bash, sh, zsh in Linux
pwsh 7 behaves a bit different as it only inserts the command but doesn't execute it (have to press enter):Peek.2024-12-12.19-55.mp4
gotcha, thanks for the response.
Will attach need-spike as it need further investigation.- addedneeds spikeLabel for issues that need investigation before they can be worked on.Label for issues that need investigation before they can be worked on.
on Jan 5, 2025 I feel this is a regression from earlier behavior, as this has been working fine for months or even years (I was using
pythonTerminalEnvVarActivation). Something seems to have changed around the time that 1.97.0 was released. I know there is a lot of work around this experiment and moving to the environments extension, but in my opinion, this transition should smoother for folks that have been using the experiment fine for a long time.karthiknadig commented
on Feb 11, 2025 MemberMore actionsI am working on a replacement the env var experiment, that should give a better outcome. The way it is done currently breaks shell aliases added to the terminal shell on activation. The new approach hopefully will handle that.
Another issue is that we capture env variables for default terminal shell, this causes issues with the prompt when other shells are run.
karthiknadig commented
on Feb 11, 2025 MemberMore actionsbersbersbers try disabling shell integrations. That might help with restoring how it used to behave.
Karthik Nadig (@karthiknadig) you mean
python.terminal.shellIntegration.enabled?This is already disabled :(
karthiknadig commented
on Feb 11, 2025 MemberMore actionsbersbersbers Can you create a separate bug? All the new stuff that we are adding should be turned off, if this is disabled. This is a regression if it is not.
Karthik Nadig (@karthiknadig) I investigated this in a clean profile, and this seems to have been an interaction between the Python extension, the
pythonTerminalEnvVarActivationexperiment, and the Python environments extension. I actually get the best results currently with the Python extension opted into the experiment; the environments extension disabled; and"python.terminal.shellIntegration.enabled": false, "python.terminal.activateEnvironment": true,
We're planning to move towards better auto-activation experience:
Try install https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-python-envs , and download the latest-pre-release.
Please set
python-envs.terminal.autoActivationTypetoshellStartupin your settings.
Also add"python.useEnvironmentsExtension": true,to your settings.json.Please file issue on https://github.com/microsoft/vscode-python-environments/issues if you see problem again, thanks.
Closing aginst: microsoft/vscode-python-environments#962
I don't see what this has to do with the ticket it was marked as a duplicate of
karthiknadig commented
on Feb 26, 2026 MemberMore actionsActivations will not send a command but instead will happen as a part of terminal shell startup. So there is no command to execute at the prompt. So prompt will be ready for user import and activation won’t be disrupted by command execution.
Reacted by Chris TomkinsHi all! I'm running into this as well as it's fairly annoying/disruptive. My steps to reproduce are:
- Open a new terminal in a uv-managed Python project.
- Start typing a command
- A few seconds later, I see something like
source /path/to/cwd/.venv/bin/activateand I'm returned to a fresh command prompt, losing what I was typing in Step 2.
I'm using macOS 26.5.1, VS Code 1.129.1. I use Starship for my zsh prompt. I've confirmed that shell integration is active (i.e.
$VSCODE_SHELL_INTEGRATION=1) and I see gutter icons in the terminal.Anthony Kim (@anthonykim1) Karthik Nadig (@karthiknadig) by any chance are there any updates on when a fix will land in VS Code? Thank you in advance for any updates on this!
thephet commented
on Jul 30, 2026 More actionsI am having the same issue.


Type: Bug
Behaviour
The
source /tmp/test/venv/bin/activatecommand is appended to the current terminal input, which messes it up.This often happens when typing shortly after launching a new terminal, or when the extension finishes loading at a later time (e.g. due to other extensions or when viewing a large file).
Steps to reproduce:
python3 -m venv venvOutput:
a% ❯ asource /tmp/test/venv/bin/activate zsh: command not found: asourcePeek.2024-12-12.01-15.mp4
Related issue: #23893
Diagnostic data
Output for
Pythonin theOutputpanel (View→Output, change the drop-down the upper-right of theOutputpanel toPython)Extension version: 2024.22.0
VS Code version: Code 1.96.0 (138f619c86f1199955d53b4166bef66ef252935c, 2024-12-11T02:29:09.626Z)
OS version: Linux x64 6.6.54-2-MANJARO
Modes:
python.languageServersetting: PylanceUser Settings
Installed Extensions
System Info
canvas_oop_rasterization: enabled_on
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
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
webnn: disabled_off