Support for Pre-execution Script in Windows Terminal #22941

Closed
opened 2026-01-31 08:27:59 +00:00 by claunia · 1 comment
Owner

Originally created by @marcuwynu23 on GitHub (Feb 19, 2025).

Description of the new feature

🚀 Feature Request: Support for Pre-execution Script in Windows Terminal

✨ Description

It would be beneficial if Windows Terminal supported pre-execution scripts, allowing users to run commands before opening a new terminal session.

🎯 Use Case

  • Users who frequently use doskey for aliasing commands (e.g., doskey gs=git status) have to manually add them to cmd.exe startup scripts.
  • A built-in mechanism to execute predefined scripts when launching Windows Terminal would improve automation and workflow efficiency.

💡 Proposed Solution

  • Add a pre-execution script option in Windows Terminal settings (settings.json).
  • Allow specifying a script (e.g., .cmd, .ps1, .bat) to run before the shell starts.

Example Implementation in settings.json:

{
  "profiles": {
    "defaults": {
      "preExecutionScript": "C:\\path\\to\\myscript.cmd"
    }
  }
}


### Proposed technical implementation details

_No response_
Originally created by @marcuwynu23 on GitHub (Feb 19, 2025). ### Description of the new feature # 🚀 Feature Request: Support for Pre-execution Script in Windows Terminal ## ✨ Description It would be beneficial if Windows Terminal supported **pre-execution scripts**, allowing users to run commands before opening a new terminal session. ## 🎯 Use Case - Users who frequently use `doskey` for aliasing commands (e.g., `doskey gs=git status`) have to manually add them to `cmd.exe` startup scripts. - A built-in mechanism to execute predefined scripts when launching Windows Terminal would improve automation and workflow efficiency. ## 💡 Proposed Solution - Add a **pre-execution script option** in Windows Terminal settings (`settings.json`). - Allow specifying a script (e.g., `.cmd`, `.ps1`, `.bat`) to run **before** the shell starts. ### Example Implementation in `settings.json`: ```json { "profiles": { "defaults": { "preExecutionScript": "C:\\path\\to\\myscript.cmd" } } } ### Proposed technical implementation details _No response_
claunia added the Issue-FeatureNeeds-TriageNeeds-Tag-Fix labels 2026-01-31 08:27:59 +00:00
Author
Owner

@DHowett commented on GitHub (Feb 19, 2025):

Thanks!

That's actually the purpose of letting you control the commandline of each profile. Because we can't know which shell you're going to use, or whether you're going to be accessing a local or remote machine (like running SSH inside a profile!), there's no way for us to actually run a pre-execution script in the right context in the right scripting language.

For your use case, you should be able to set your commandline to cmd /s /k c:\\path\\to\\myscript.cmd or pwsh -noexit -command c:\\path\\to\\myscript.ps1. :)

@DHowett commented on GitHub (Feb 19, 2025): Thanks! That's actually the purpose of letting you control the commandline of each profile. Because we can't know which shell you're going to use, or whether you're going to be accessing a local or remote machine (like running SSH inside a profile!), there's no way for us to actually _run a pre-execution script_ in the right context in the right scripting language. For your use case, you should be able to set your commandline to `cmd /s /k c:\\path\\to\\myscript.cmd` or `pwsh -noexit -command c:\\path\\to\\myscript.ps1`. :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#22941