Skip to content

Document session restore interaction with command-line arguments#913

Draft
mattwojo with Copilot wants to merge 5 commits into
mainfrom
copilot/update-command-line-arguments-docs
Draft

Document session restore interaction with command-line arguments#913
mattwojo with Copilot wants to merge 5 commits into
mainfrom
copilot/update-command-line-arguments-docs

Conversation

Copilot AI commented Dec 18, 2025

Copy link
Copy Markdown
Contributor

When firstWindowPreference: "persistedWindowLayout" is enabled, running wt nt -p <profile> opens two windows: one restoring the previous session and one executing the command. This behavior was undocumented.

Changes

  • Added IMPORTANT callout in command-line syntax section explaining the dual-window behavior and referencing --window option for control
  • Added new section "Session restore and command line arguments" with three workarounds:
    • wt -w 0 nt -p <profile> - Opens in most recently used window (avoids second window)
    • wt -w -1 nt -p <profile> - Forces new window without session restore
    • wt -w <name> nt -p <profile> - Opens in named window
  • Included shell-specific examples for Command Prompt, PowerShell, and Linux/WSL

Example

// Without -w flag: opens TWO windows (restored session + new command)
wt nt -p "Ubuntu-18.04"

// With -w 0: opens ONE window (new tab in existing window)
wt -w 0 nt -p "Ubuntu-18.04"
Original prompt

This section details on the original issue you should resolve

<issue_title>Feedback: wt nt -p opens two windows</issue_title>
<issue_description>### Type of issue

Other (describe below)

Feedback

Currently, if "Startup / When Terminal starts = Open windows from a previous session" option is set, then a command like wt nt -p <profile> will open two windows. The documentation should add instructions to disable this feature when starting Windows Terminal from the command line, or add a switch to disable session restore.

Page URL

https://learn.microsoft.com/en-us/windows/terminal/command-line-arguments?tabs=windows

Content source URL

https://github.com/MicrosoftDocs/terminal/blob/main/TerminalDocs/command-line-arguments.md

Author

@nguyen-dows

Document Id

0d5d0fe3-01ef-66e8-263d-a0a7852ffa7a</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@learn-build-service-prod

Copy link
Copy Markdown
Contributor

Learn Build status updates of commit 10c15a7:

✅ Validation status: passed

For more details, please refer to the build report.

@learn-build-service-prod

Copy link
Copy Markdown
Contributor

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 and severity-2 issues. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

@learn-build-service-prod

Copy link
Copy Markdown
Contributor

Learn Build status updates of commit 397b755:

✅ Validation status: passed

File Status Preview URL Details
TerminalDocs/command-line-arguments.md ✅Succeeded View

For more details, please refer to the build report.

@learn-build-service-prod

Copy link
Copy Markdown
Contributor

Learn Build status updates of commit e1ee1d2:

✅ Validation status: passed

File Status Preview URL Details
TerminalDocs/command-line-arguments.md ✅Succeeded View

For more details, please refer to the build report.

@learn-build-service-prod

Copy link
Copy Markdown
Contributor

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 and severity-2 issues. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

@learn-build-service-prod

Copy link
Copy Markdown
Contributor

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 and severity-2 issues. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

@learn-build-service-prod

Copy link
Copy Markdown
Contributor

Learn Build status updates of commit fb863f0:

✅ Validation status: passed

File Status Preview URL Details
TerminalDocs/command-line-arguments.md ✅Succeeded View

For more details, please refer to the build report.

@learn-build-service-prod

Copy link
Copy Markdown
Contributor

Learn Build status updates of commit 84e538c:

✅ Validation status: passed

File Status Preview URL Details
TerminalDocs/command-line-arguments.md ✅Succeeded View

For more details, please refer to the build report.

@learn-build-service-prod

Copy link
Copy Markdown
Contributor

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 and severity-2 issues. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

Copilot AI changed the title [WIP] Update documentation to address multiple window issue Document session restore interaction with command-line arguments Dec 18, 2025
Copilot AI requested a review from mattwojo December 18, 2025 20:32

@zadjii-msft zadjii-msft left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as noted


> [!IMPORTANT]
> If you have enabled the **"Open windows from a previous session"** startup option ([`firstWindowPreference: "persistedWindowLayout"`](./customize-settings/startup.md#behavior-when-starting-a-new-terminal-session)), running `wt` from the command line will restore your previous session **and** execute the command you provided, potentially opening two windows. To prevent this behavior, use the `--window, -w` option to control where your command executes:
> - `wt -w 0 nt -p <profile>` - Opens in the most recently used window (prevents a second window from opening)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(starting from "To prevent this behavior, use the --window, -w option to control where your command executes:")

Nope. This doesn't work this way. Don't add any commentary on how to prevent that behavior - when firstWindowPreference is set to restore things, then any cold wt nt command will both restore and run the new command.

Comment on lines +229 to +274
To avoid this behavior when session restore is enabled, use the `--window, -w` option to control where your commands execute:

<!-- Start tab selectors. -->
#### [Command Prompt](#tab/windows)

```cmd
// Open a new tab with a specific profile in the most recently used window (avoids opening a second window)
wt -w 0 nt -p "Ubuntu-18.04"

// Force a new window with the profile, without restoring previous session
wt -w -1 nt -p "Command Prompt"

// Open in a named window (creates it only if it doesn't exist)
wt -w mywork nt -p "PowerShell"
```

#### [PowerShell](#tab/powershell)

```powershell
// Open a new tab with a specific profile in the most recently used window (avoids opening a second window)
wt -w 0 nt -p "Ubuntu-18.04"

// Force a new window with the profile, without restoring previous session
wt -w -1 nt -p "Command Prompt"

// Open in a named window (creates it only if it doesn't exist)
wt -w mywork nt -p "PowerShell"
```

#### [Linux](#tab/linux)

```bash
// Open a new tab with a specific profile in the most recently used window (avoids opening a second window)
cmd.exe /c "wt.exe" -w 0 nt -p "Ubuntu-18.04"

// Force a new window with the profile, without restoring previous session
cmd.exe /c "wt.exe" -w -1 nt -p "Command Prompt"

// Open in a named window (creates it only if it doesn't exist)
cmd.exe /c "wt.exe" -w mywork nt -p "PowerShell"
```

Execution aliases don't work in WSL distributions. If you want to use wt.exe from a WSL command line, you can spawn it from CMD directly by running `cmd.exe`. The `/c` option tells CMD to terminate after running.

---
<!-- End tab selectors. -->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly, drop this all.

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.

Feedback: wt nt -p <profile> opens two windows

3 participants