Skip to content

Typing messes up terminal/venv activation #24589

Description

@j4k0xb

Type: Bug

Behaviour

The source /tmp/test/venv/bin/activate command 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:

  1. python3 -m venv venv
  2. Select Interpreter for this venv
  3. Open terminal with Ctrl+J and quickly type a letter

Output:

a%                                                                                                                                         
❯ asource /tmp/test/venv/bin/activate
zsh: command not found: asource
Peek.2024-12-12.01-15.mp4

Related issue: #23893

Diagnostic data

Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)

2024-12-12 04:02:31.032 [info] Telemetry level is off
2024-12-12 04:02:31.032 [info] Experiments are disabled, only manually opted experiments are active.
2024-12-12 04:02:31.032 [warning] Dir "/tmp/test/.pixi/envs" is not watchable (directory does not exist)
2024-12-12 04:02:31.032 [info] Python interpreter path: ./venv/bin/python
2024-12-12 04:02:31.053 [info] Starting Environment refresh
2024-12-12 04:02:31.053 [info] Searching for interpreters in posix paths locator
2024-12-12 04:02:31.055 [info] Searching for pyenv environments
2024-12-12 04:02:31.055 [info] Searching for conda environments
2024-12-12 04:02:31.055 [info] Searching for global virtual environments
2024-12-12 04:02:31.055 [info] Searching for custom virtual environments
2024-12-12 04:02:31.084 [info] > pyenv which python
2024-12-12 04:02:31.084 [info] cwd: .
2024-12-12 04:02:31.086 [info] pyenv is not installed
2024-12-12 04:02:31.086 [info] Finished searching for pyenv environments: 32 milliseconds
2024-12-12 04:02:31.086 [info] Finished searching for custom virtual envs: 31 milliseconds
2024-12-12 04:02:31.108 [info] > conda info --json
2024-12-12 04:02:31.138 [info] > hatch env show --json
2024-12-12 04:02:31.138 [info] cwd: .
2024-12-12 04:02:31.150 [info] Finished searching for global virtual envs: 96 milliseconds
2024-12-12 04:02:31.202 [info] Found: /bin/python --> /bin/python3.12
2024-12-12 04:02:31.658 [info] Found: /bin/python3 --> /bin/python3.12
2024-12-12 04:02:31.659 [info] Found: /bin/python3.12 --> /bin/python3.12
2024-12-12 04:02:31.796 [info] > /bin/python -I ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/interpreterInfo.py
2024-12-12 04:02:31.815 [info] Found: /sbin/python --> /sbin/python3.12
2024-12-12 04:02:31.816 [info] Found: /sbin/python3 --> /sbin/python3.12
2024-12-12 04:02:31.817 [info] Found: /sbin/python3.12 --> /sbin/python3.12
2024-12-12 04:02:31.859 [info] > ./venv/bin/python -I ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/interpreterInfo.py
2024-12-12 04:02:32.728 [info] Found: /usr/bin/python --> /usr/bin/python3.12
2024-12-12 04:02:32.731 [info] Found: /usr/bin/python3 --> /usr/bin/python3.12
2024-12-12 04:02:32.731 [info] Found: /usr/bin/python3.12 --> /usr/bin/python3.12
2024-12-12 04:02:32.796 [info] Found: /usr/sbin/python --> /usr/sbin/python3.12
2024-12-12 04:02:32.797 [info] Found: /usr/sbin/python3 --> /usr/sbin/python3.12
2024-12-12 04:02:32.797 [info] Found: /usr/sbin/python3.12 --> /usr/sbin/python3.12
2024-12-12 04:02:32.840 [info] > /sbin/python -I ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/interpreterInfo.py
2024-12-12 04:02:32.879 [info] Finished searching for interpreters in posix paths locator: 1806 milliseconds
2024-12-12 04:02:32.879 [info] > /usr/bin/python -I ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/interpreterInfo.py
2024-12-12 04:02:32.920 [info] > /usr/sbin/python -I ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/interpreterInfo.py
2024-12-12 04:02:32.920 [info] Environments refresh paths discovered (event): 1869 milliseconds
2024-12-12 04:02:32.920 [info] Environments refresh paths discovered: 1869 milliseconds
2024-12-12 04:02:32.971 [info] Environments refresh finished (event): 1920 milliseconds
2024-12-12 04:02:32.976 [info] Environment refresh took 1926 milliseconds
2024-12-12 04:02:33.462 [info] Starting Pylance language server.
2024-12-12 04:02:35.081 [info] Send text to terminal: source /tmp/test/venv/bin/activate

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 version (& distribution if applicable, e.g. Anaconda): 3.12.6
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
  • Value of the python.languageServer setting: Pylance
User Settings


languageServer: "Pylance"

Installed Extensions
Extension Name Extension Id Version
.NET Install Tool ms-dotnettools.vscode-dotnet-runtime 2.2.3
Abracadabra, refactor this! nicoespeon.abracadabra 9.4.8
Atom One Dark Theme akamud.vscode-theme-onedark 2.3.0
Auto Rename Tag formulahendry.auto-rename-tag 0.1.10
Auto Restart TypeScript / ESLint Servers neotan.vscode-auto-restart-typescript-eslint-servers 0.0.6
Azure Repos ms-vscode.azure-repos 0.40.0
Bash IDE mads-hartmann.bash-ide-vscode 1.43.0
Better C++ Syntax jeff-hykin.better-cpp-syntax 1.27.1
Better package.json ldd-vs-code.better-package-json 0.2.1
Bookmarks alefragnani.Bookmarks 13.5.0
C/C++ ms-vscode.cpptools 1.22.11
C/C++ Extension Pack ms-vscode.cpptools-extension-pack 1.3.0
C/C++ Snippets hars.CppSnippets 0.0.15
C/C++ Themes ms-vscode.cpptools-themes 2.0.0
C# ms-dotnettools.csharp 2.55.29
C# Dev Kit ms-dotnettools.csdevkit 1.14.14
Clang-Format xaver.clang-format 1.9.0
clangd llvm-vs-code-extensions.vscode-clangd 0.1.33
CMake twxs.cmake 0.0.17
CMake Language Support josetr.cmake-language-support-vscode 0.0.9
CMake Tools ms-vscode.cmake-tools 1.19.52
Code Spell Checker streetsidesoftware.code-spell-checker 4.0.21
CodeLLDB vadimcn.vscode-lldb 1.11.1
Compare Folders moshfeu.compare-folders 0.25.1
Complete JSDoc Tags HookyQR.JSDocTagComplete 0.0.2
Copy GitHub URL mattlott.copy-github-url 0.14.0
copy-json-path nidu.copy-json-path 0.4.0
CSS Formatter aeschli.vscode-css-formatter 1.0.2
deoptexplorer-vscode rbuckton.deoptexplorer-vscode 1.1.2
Dev Containers ms-vscode-remote.remote-containers 0.394.0
Docker ms-azuretools.vscode-docker 1.29.3
EditorConfig for VS Code EditorConfig.EditorConfig 0.16.4
esbuild Problem Matchers connor4312.esbuild-problem-matchers 0.0.3
ESLint dbaeumer.vscode-eslint 3.0.10
Eval and Replace Lebster.eval-and-replace 2.3.0
File Utils sleistner.vscode-fileutils 3.10.3
Flame Chart Visualizer for JavaScript Profiles ms-vscode.vscode-js-profile-flame 1.0.9
Git Graph mhutchie.git-graph 1.30.0
GitHub Actions github.vscode-github-actions 0.27.0
GitHub Codespaces GitHub.codespaces 1.17.3
GitHub Copilot GitHub.copilot 1.250.0
GitHub Copilot Chat GitHub.copilot-chat 0.23.0
GitHub Pull Requests GitHub.vscode-pull-request-github 0.102.0
GitHub Repositories GitHub.remotehub 0.64.0
GitHub Theme GitHub.github-vscode-theme 6.3.5
GitLens — Git supercharged eamodio.gitlens 16.0.5
GN npclaudiu.vscode-gn 1.1.0
Header source switch ryzngard.vscode-header-source 1.3.0
Hex Editor ms-vscode.hexeditor 1.11.1
Hover Converter bedrankara.hoverconverter 0.0.1
IntelliCode Completions VisualStudioExptTeam.vscodeintellicode-completions 2.0.1
IntelliCode for C# Dev Kit ms-dotnettools.vscodeintellicode-csharp 2.2.3
JavaScript Debugger ms-vscode.js-debug 1.96.0
JavaScript Debugger Companion Extension ms-vscode.js-debug-companion 1.1.3
JS Refactoring Assistant p42ai.refactor 3.0.1
Jupyter ms-toolsai.jupyter 2024.11.0
Jupyter Cell Tags ms-toolsai.vscode-jupyter-cell-tags 0.1.9
Jupyter Keymap ms-toolsai.jupyter-keymap 1.1.2
Jupyter Notebook Renderers ms-toolsai.jupyter-renderers 1.0.21
Jupyter Slide Show ms-toolsai.vscode-jupyter-slideshow 0.1.6
Language Support for Java(TM) by Red Hat redhat.java 1.37.0
LaTeX Workshop James-Yu.latex-workshop 10.7.0
Lebab mrmlnc.vscode-lebab 2.6.0
Markdown PDF yzane.markdown-pdf 1.5.0
markdownlint DavidAnson.vscode-markdownlint 0.57.0
node-snippets chris-noring.node-snippets 1.3.3
Paste JSON as Code quicktype.quicktype 23.0.170
Patch Extensions j4k0xb.patch-extensions 0.0.1
Peggy Language PeggyJS.peggy-language 3.0.2
PlatformIO IDE platformio.platformio-ide 3.3.3
Prettier - Code formatter esbenp.prettier-vscode 11.0.0
Pylance ms-python.vscode-pylance 2024.12.1
Python ms-python.python 2024.22.0
Python Debugger ms-python.debugpy 2024.14.0
Quokka.js WallabyJs.quokka-vscode 1.0.675
Rainbow CSV mechatroner.rainbow-csv 3.13.0
Remote - SSH ms-vscode-remote.remote-ssh 0.116.0
Remote - SSH: Editing Configuration Files ms-vscode-remote.remote-ssh-edit 0.87.0
Remote - Tunnels ms-vscode.remote-server 1.5.2
Remote Development ms-vscode-remote.vscode-remote-extensionpack 0.26.0
Remote Explorer ms-vscode.remote-explorer 0.4.3
Remote Repositories ms-vscode.remote-repositories 0.42.0
Ruff charliermarsh.ruff 2024.56.0
rust-analyzer rust-lang.rust-analyzer 0.3.2212
ShellCheck timonwong.shellcheck 0.37.1
Smalise LoyieKing.smalise 0.0.12
SQLite Viewer qwtel.sqlite-viewer 0.9.5
SQLTools mtxr.sqltools 0.28.3
SQLTools PostgreSQL/Cockroach Driver mtxr.sqltools-driver-pg 0.5.4
Stylelint stylelint.vscode-stylelint 1.4.0
Surround yatki.vscode-surround 1.5.0
SVG jock.svg 1.5.4
swapdiff shalimski.swapdiff 0.2.2
Table Visualizer for JavaScript Profiles ms-vscode.vscode-js-profile-table 1.0.10
Tailwind CSS IntelliSense bradlc.vscode-tailwindcss 0.12.16
Template String Converter j4k0xb.template-string-converter 0.1.0
Text Marker (Highlighter) ryu1kn.text-marker 1.11.0
Thunder Client rangav.vscode-thunder-client 2.32.10
Todo Tree Gruntfuggly.todo-tree 0.0.226
TOML Language Support be5invis.toml 0.6.0
TsAutoReturnType ebrithil30.vscode-ts-auto-return-type 1.1.0
Turbo Console Log ChakrounAnas.turbo-console-log 2.10.5
Twoslash Query Comments Orta.vscode-twoslash-queries 1.4.0
TypeScript Importer pmneo.tsimporter 2.0.1
Unity visualstudiotoolsforunity.vstuc 1.0.5
V8 Torque Language Support v8-torque.vscode-torque 1.0.3
v8-bytecode-highlight j4k0xb.v8-bytecode-highlight 0.2.0
Vencord Companion Vendicated.vencord-companion 0.1.3
Visual Studio Code Commitizen Support KnisterPeter.vscode-commitizen 1.1.0
Vitest vitest.explorer 1.8.3
vscode-base64 adamhartford.vscode-base64 0.1.0
vscode-icons vscode-icons-team.vscode-icons 12.9.0
vscode-position jtr.vscode-position 1.1.2
WebAssembly dtsvet.vscode-wasm 1.4.1
Wolf traBpUkciP.wolf 0.4.3
Workspace Storage Cleanup mehyaa.workspace-storage-cleanup 1.6.5
x86 and x86_64 Assembly 13xforever.language-x86-64-assembly 3.1.4
YAML redhat.vscode-yaml 1.15.0
undefined wmaurer.change-case 1.0.0
System Info
Item Value
CPUs Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz (12 x 2600)
GPU Status 2d_canvas: enabled
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
Load (avg) 2, 1, 1
Memory (System) 15.49GB (4.77GB free)
Process Argv
Screen Reader no
VM 0%
DESKTOP_SESSION plasma
XDG_CURRENT_DESKTOP KDE
XDG_SESSION_DESKTOP KDE
XDG_SESSION_TYPE x11

Activity

  1. changed the title [-]source command race condition[/-] [+]Typing messes up terminal/venv activation[/+] on Dec 12, 2024
  2. karthiknadig commented on Dec 12, 2024

    @karthiknadig
    Member

    We 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:

    1. Navigate to your project from an external terminal
    2. Activate your environment
    3. run code .

    This will star VS Code itself in an activated environment and there is no need for us to activate it later.

  3. j4k0xb commented on Dec 12, 2024

    @j4k0xb
    Author

    I don't mind if it's running activation scripts, but is it possible that it won't interfere with the terminal input?

  4. karthiknadig commented on Dec 12, 2024

    @karthiknadig
    Member

    The support for that requires "Shell Integration" feature to be on. With that it can work a little bit better, and hopefully we can do this better as the feature improves:
    Image

  5. j4k0xb commented on Dec 12, 2024

    @j4k0xb
    Author

    Unfortunately it has the same behavior with shell integration enabled

  6. anthonykim1 commented on Dec 12, 2024

    @anthonykim1

    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?

  7. j4k0xb commented on Dec 12, 2024

    @j4k0xb
    Author

    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

  8. anthonykim1 commented on Dec 12, 2024

    @anthonykim1

    Thanks 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?

  9. j4k0xb commented on Dec 12, 2024

    @j4k0xb
    Author

    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
  10. anthonykim1 commented on Jan 5, 2025

    @anthonykim1

    gotcha, thanks for the response.
    Will attach need-spike as it need further investigation.

  11. bersbersbers commented on Feb 11, 2025

    @bersbersbers

    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.

  12. karthiknadig commented on Feb 11, 2025

    @karthiknadig
    Member

    I 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.

  13. karthiknadig commented on Feb 11, 2025

    @karthiknadig
    Member

    bersbersbers try disabling shell integrations. That might help with restoring how it used to behave.

  14. bersbersbers commented on Feb 11, 2025

    @bersbersbers

    Karthik Nadig (@karthiknadig) you mean python.terminal.shellIntegration.enabled?

    This is already disabled :(

    Image

  15. karthiknadig commented on Feb 11, 2025

    @karthiknadig
    Member

    bersbersbers 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.

  16. bersbersbers commented on Feb 11, 2025

    @bersbersbers

    Karthik Nadig (@karthiknadig) I investigated this in a clean profile, and this seems to have been an interaction between the Python extension, the pythonTerminalEnvVarActivation experiment, 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,
  17. anthonykim1 commented on Feb 2, 2026

    @anthonykim1

    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.autoActivationType to shellStartup in 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

  18. dspyz-matician commented on Feb 26, 2026

    @dspyz-matician

    I don't see what this has to do with the ticket it was marked as a duplicate of

  19. karthiknadig commented on Feb 26, 2026

    @karthiknadig
    Member

    Activations 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.

  20. rmx90210 commented on Jul 19, 2026

    @rmx90210

    Hi all! I'm running into this as well as it's fairly annoying/disruptive. My steps to reproduce are:

    1. Open a new terminal in a uv-managed Python project.
    2. Start typing a command
    3. A few seconds later, I see something like source /path/to/cwd/.venv/bin/activate and 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!

  21. thephet commented on Jul 30, 2026

    @thephet

    I am having the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-terminalbugIssue identified by VS Code Team member as probable bugneeds spikeLabel for issues that need investigation before they can be worked on.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions