Microsoft/vscode

Better integration of pre-commit hooks with Python virtual environments.

Open

#265,613 opened on Sep 8, 2025

View on GitHub
 (0 comments) (2 reactions) (1 assignee)TypeScript (74,848 stars) (10,221 forks)batch import
feature-requestgithelp wanted

Description

Currently, pre-commit hooks inside VS Code cannot find tools installed in a project’s virtual environment unless VS Code itself is launched from within that environment.

Example

  • I have a pre-commit hook configured to run isort.
  • If I open the project directly in VS Code, pre-commit fails because isort cannot be found.
  • If instead I activate the virtual environment in a terminal and then start VS Code with code ., the environment is inherited correctly and pre-commit works.

This makes the workflow inconvenient since developers must remember to always launch VS Code from an activated venv.


Steps to Reproduce

  1. Create a Python project with a virtual environment.
  2. Install isort (or another tool) in the venv.
  3. Add a .pre-commit-config.yaml with a hook that uses the tool.
  4. Open the project in VS Code without starting from the venv.
  5. Run a commit → pre-commit fails with tool not found.

Expected Behavior / Feature Proposal

It would be very useful if VS Code could automatically detect and use the project’s Python virtual environment when running pre-commit hooks.
This way, pre-commit would always work consistently regardless of how VS Code was launched.


Why This Matters

  • Improves developer experience by reducing friction.
  • Makes pre-commit integration more reliable for Python projects.
  • Aligns with how VS Code already handles selecting Python interpreters for debugging and linting.

Contributor guide