Skip to content

Support new variable ${targetDir} in terminal profiles for right-click 'Open in Terminal' #252766

Open
@jkadw

Description

@jkadw

Feature Request: Add ${targetDir} variable to terminal profiles

Problem

When right-clicking a folder in the VS Code Explorer and selecting "Open in Integrated Terminal", the built-in terminal correctly starts in the clicked directory. However, when using a custom terminal profile via terminal.integrated.profiles.*, this context is lost.

Currently, ${cwd} and ${workspaceFolder} are the only available variables, and both point to the workspace root – not the folder that was right-clicked.

Why it matters

This limitation makes it impossible to:

  • Launch container shells or scripts with contextual awareness of the folder selected.
  • Provide smart terminal profiles that behave like the default one.

It severely limits the usefulness of custom terminal profiles for advanced workflows, especially when combined with Docker, SSH, or remote mounts.

Proposed Solution

Introduce a new variable:

${targetDir}

…that resolves to the actual folder the user right-clicked when opening the terminal. If the terminal is launched from the command palette or normal view, ${targetDir} should fall back to ${cwd} or ${workspaceFolder}.

Example Usage

"terminal.integrated.profiles.linux": {
  "SSH to Server": {
    "path": "/usr/bin/ssh",
    "args": [
      "-tt",
      "user@host",
      "cd \"${targetDir}\" || cd ~; exec bash"
    ]
  }
}

Workaround Today

Not possible. ${cwd} always resolves to the project root when using a custom terminal profile – even if a subfolder was explicitly clicked.

Request Summary

Please add a ${targetDir} variable to allow custom terminal profiles to receive the actual path that the user opened the terminal for. This would bring custom profiles to feature parity with the default terminal behavior.

Thanks for your consideration!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions