Skip to content

feat: terminals can activate a Python environment, including conda - #186

Merged
adampeterhiggins merged 1 commit into
mainfrom
ah/terminal-venv-autosource
Oct 6, 2026
Merged

adampeterhiggins merged 1 commit into
mainfrom
ah/terminal-venv-autosource

Conversation

@adampeterhiggins

Copy link
Copy Markdown
Owner

T3 Code terminals open without the project's Python environment, so every new terminal needs a manual source .venv/bin/activate (or conda activate). VS Code handles this with python.terminal.activateEnvironment and python.defaultInterpreterPath.

What changed

  • Activate Python environment in terminals (Settings → General → Projects & threads, off by default). When a terminal starts or restarts, the server types the activation command into the shell. Typing it, rather than setting PATH directly, means it runs after the user's rc files, which often rebuild PATH. Supported shells: bash, zsh, sh, fish, csh, PowerShell and cmd.
  • Python interpreter path, like python.defaultInterpreterPath. When empty, the terminal uses the .venv or venv in its working directory. Otherwise it takes an interpreter or environment folder (.venv/bin/python, ~/miniconda3/envs/app); ~ is expanded and relative paths start at the terminal's cwd. A folder with conda-meta is activated with conda activate <env>, which needs conda init. Anything else uses its own activate script.
  • Per-project and t3.json. Both settings can be overridden per project; the server finds the terminal's project from its thread, falling back to its cwd. The path is also backed by t3.json ("pythonInterpreterPath"). The order is project override, then environment, then the checkout's t3.json, then auto-detect. The on/off switch is deliberately not readable from t3.json, so a cloned repo can't opt anyone into running commands.
  • Surfaces. Both settings are in web and desktop settings, mobile server settings (New threads → Terminal) and the MCP t3_environment_* preference tools. The terminal user guide and docs/fork-differences.md are updated.

Code: apps/server/src/terminal/pythonEnvironment.ts builds the activation command, and resolveTerminalPythonEnvironment / startSession in apps/server/src/terminal/Manager.ts apply it.

Testing

  • pythonEnvironment.test.ts covers per-shell commands and quoting, .venv over venv, configured venv and conda paths, and a missing path.
  • Manager.test.ts covers activation being written only when enabled, and the order between settings and t3.json.
  • Typecheck is clean for contracts, shared, server, web and mobile. Targeted tests pass: server terminal and MCP, shared settings and t3.json, web settings, mobile settings.
  • Not yet checked in a running client, and the before/after screenshots of the settings rows aren't attached yet.

Done by Claude Opus 5.5 in Claude Code (via T3 Code).

🤖 Generated with Claude Code

Add VS Code-style Python environment activation for integrated terminals.
"Activate Python environment in terminals" (off by default) types the
activation command into new and restarted shells. "Python interpreter path"
mirrors python.defaultInterpreterPath: empty finds a .venv or venv in the
terminal's cwd; otherwise an interpreter or environment folder, with conda
environments activated through `conda activate`.

Both settings are project-scoped, and the path is also file-backed, so a
repository can set "pythonInterpreterPath" in t3.json. Exposed in web,
desktop and mobile settings and the MCP environment preferences tools.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant