← Back to Pull requests

Add a startup code page setting for terminal profiles #20817

Open
s911415 opened this pull request with 877 lines diff across 37 files
View on GitHub
s911415 s911415 commented on Oct 17, 2026 15:19 UTC
Author

Summary of the Pull Request

Windows Terminal is a terminal host rather than a traditional console application, so the per-application settings under HKCU\Console do not apply to wt.exe in the same way they apply to applications running inside a console. In addition, ConPTY sessions intentionally ignore console user settings, including the registry CodePage value.

As a result, users cannot configure the initial code page of a Windows Terminal session through the Console registry. Running chcp or a shell startup script is not equivalent because it occurs after the console and client process have already been initialized, and it is not a shell-independent profile setting.

This change adds an opt-in, profile-level codePage setting and passes the resolved value to the bundled OpenConsole host before launching the client process.

The setting is intentionally opt-in. This PR does not make code page 65001 the default because changing the startup code page of all existing profiles could break legacy applications that depend on an OEM or locale-specific code page. Users can enable UTF-8 through profiles.defaults or select another installed code page for an individual profile.

When the setting is omitted, the existing console-host default is preserved.

References and Relevant Issues

Closes #15678

Detailed Description of the Pull Request / Additional comments


Settings model and precedence

Adds codePage as an inheritable profile setting with the following precedence:

1. Individual profile
2. profiles.defaults
3. Existing console-host default

The unset value is represented internally as 0. This preserves the existing host behavior rather than explicitly selecting a code page.

The profile schema accepts integer code page identifiers. OpenConsole validates a nonzero value with the Windows Code Page APIs before applying it.

Settings UI

Adds a searchable Code Page picker to the Advanced profile settings page.

The picker:

  • Enumerates installed code pages with EnumSystemCodePagesW.

  • Uses names returned by GetCPInfoExW.

  • Searches only the displayed code page number and system-provided name.

  • Does not add hard-coded aliases.

  • Displays (Default) for Profile Defaults when unset.

  • Displays (Inherited) for an individual profile when unset.

  • Displays the selected code page number and system-provided name for an explicit value.
  • Selecting the first entry, using the AutoSuggestBox clear button, or using the reset button clears only the current profile layer.

    ConPTY and OpenConsole initialization

    For local terminal sessions, Windows Terminal places the resolved code page in the existing connection ValueSet. The public ConptyConnection::CreateSettings() WinRT signature remains unchanged.

    An internal ConPTY creation path passes the requested value to the bundled OpenConsole.exe through:

    --codepage <value>
    

    OpenConsole applies the code page before screen-buffer initialization and before launching the client process. Input and output DBCS metadata are initialized after selecting the startup code page.

    The custom argument is never passed to the inbox conhost.exe fallback because that host does not support it. If a profile requests a code page while Windows Terminal must use the inbox host, the existing fallback behavior is preserved and Windows Terminal displays a warning that the requested code page could not be applied.

    Backward compatibility

    Code page 65001 is not enabled by default.

    Changing the default would alter every existing local profile and could break legacy applications that use code page-dependent console APIs or expect the current OEM or locale-specific code page.

    Users who want UTF-8 for all profiles can configure:

    "profiles": {
        "defaults": {
            "codePage": 65001
        },
        "list": []
    }
    

    An individual profile can override the shared default when it requires another installed code page.

    Demo


    <img width="800" height="449" alt="722e2af7-db7d-48fa-8020-04c789514d18" src="https://github.com/user-attachments/assets/85d3cdcc-242b-4a53-aecc-32eec30e4837" />

    <img width="1112" height="626" alt="image" src="https://github.com/user-attachments/assets/5242d0f4-642c-4088-a63b-58eb7f2682b8" />

    Validation Steps Performed

    The complete change was reviewed and tested manually on Windows with an x64 Release build.

    Manual validation covered:

  • Profile Defaults displaying (Default) when unset.

  • Individual profiles displaying (Inherited) when unset.

  • Searching for and selecting installed code pages.

  • Clearing the current layer with the first entry, clear button, and reset button.

  • Individual-profile and profiles.defaults precedence.

  • Preserving the existing host behavior when codePage is omitted.

  • Launching a CMD profile with code page 65001 and verifying the result with chcp.
  • All tests added for this change passed in the x64 Release configuration:

  • ConsoleArgumentsTests::CodePageArgTests

  • InitTests::TestInitializeConsoleCodePage

  • TerminalSettingsTests::CodePagePrecedence

  • CodePageUtilsTests::UnsetTextMatchesProfileLayer

  • CodePageUtilsTests::FilterMatchesOnlyDisplayedText

  • CodePageUtilsTests::ClearRequiresEmptyUserInput

  • CodePageUtilsTests::SingleResultCommitRequiresNoChosenSuggestion

  • ConPtyTests::CodePageTests
  • The settings-model tests cover:

  • Individual-profile and profiles.defaults precedence.

  • Clearing an individual override.

  • Serialization and deserialization.

  • Propagating the unset value that preserves the existing host default.
  • The picker helper tests cover:

  • (Default) and (Inherited) selection.

  • Displayed-text filtering.

  • Clear behavior.

  • Single-result commit behavior.
  • The ConPTY tests cover:

  • Bundled and fallback host argument generation.

  • Omitting the argument for an unset value.

  • Rejecting invalid code pages.

  • Creating a pseudoconsole with code page 65001.

  • Launching cmd.exe /d /c chcp and verifying that its output reports code page 65001.
  • PR Checklist

  • Closes #15678

  • Tests added/passed

  • Documentation updated

  • - A paired MicrosoftDocs/terminal PR will be filed after initial review confirms the approach.
  • Schema updated
  • Diff: 877 lines (+837 / -40) across 37 files Reviewer: lhecker Review duration: 40662m
    All Vouch review confidence checks passed
    Residual risk 0.06 = Change Risk (0.72) × (1 − Review Confidence (0.91)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.72 · 877 lines diff across 37 files
    0.72
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.91 · 5 substantive comment(s)
    0.91
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    91%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Mass File Touch mass_file_touch
    0.080
    Real PR Conversation Timeline
    6 items
    azure-pipelines[bot] azure-pipelines[bot] commented on Oct 17, 2026 15:19 UTC
    Bot

    <!-- AzurePipelinesStatusComment -->
    <samp>
    Azure Pipelines:<br>
    There may be pipelines that require an authorized user to comment /azp run to run.<br>

    </samp>

    github-advanced-security[bot] github-advanced-security[bot] commented on code on Oct 17, 2026 15:23 UTC
    Code Review
    src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp:1
    @@ -27,6 +28,41 @@
     
         Windows::Foundation::Collections::IObservableVector<Editor::Font> ProfileViewModel::_MonospaceFontList{ nullptr };
         Windows::Foundation::Collections::IObservableVector<Editor::Font> ProfileViewModel::_FontList{ nullptr };
    +    Windows::Foundation::Collections::IObservableVector<Editor::EnumEntry> ProfileViewModel::_CodePageList{ nullptr };
    +
    +    static thread_local std::vector<Editor::EnumEntry>* codePageCollector{ nullptr };
    +
    +    static BOOL CALLBACK _CollectCodePage(wchar_t* value)
    +    {
    +        if (!codePageCollector)
    +        {
    +            return FALSE;
    +        }
    +
    +        wchar_t* end = nullptr;
    +        const auto parsed = wcstoul(value, &end, 10);
    +        if (!end || *end != L'\0' || parsed > UINT_MAX)
    +        {
    +            return TRUE;
    +        }
    +
    +        const auto codePage = static_cast<uint32_t>(parsed);
    +        CPINFOEXW info{};
    

    check-spelling / Unrecognized Spelling

    [CPINFOEXW](#security-tab) is not a recognized word

    Show more details

    github-actions[bot] github-actions[bot] commented on Oct 17, 2026 15:23 UTC
    Bot

    @check-spelling-bot Report

    🔴 Please review


    See the 📂 files view, the 📜action log, 👼 SARIF report, or 📝 job summary for details.

    Unrecognized words (1)

    CPINFOEXW

    <details><summary>These words are not needed and should be removed
    </summary>ADDREF CLAUDE yizz
    </details><p></p>

    <details><summary>To accept these unrecognized words as correct and remove the previously acknowledged and now absent words,
    you could run the following commands</summary>

    ... in a clone of the git@github.com:s911415/windows-terminal.git repository
    on the dev/s911415/profile-codepage branch ([ℹ️ how do I use this?](
    https://docs.check-spelling.dev/Accepting-Suggestions)):

    `` sh
    curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/cfb6f7e75bbfc89c71eaa30366d0c166f1bd9c8c/apply.pl' |
    perl - 'https://github.com/microsoft/terminal/actions/runs/39044528464/attempts/1' &&
    git commit -m 'Update check-spelling metadata'

    </details>
    
    <details><summary>Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary</summary>
    
    This includes both **expected items** (2030) from .github/actions/spelling/expect/alphabet.txt .github/actions/spelling/expect/expect.txt .github/actions/spelling/expect/web.txt and **unrecognized words** (1)
    
    Dictionary | Entries | Covers | Uniquely
    -|-|-|-
    [cspell:cpp/src/lang-keywords.txt](https://raw.githubusercontent.com/check-spelling/cspell-dicts/v20230509/dictionaries/cpp/src/lang-keywords.txt)|44|3|3|
    [cspell:csharp/csharp.txt](https://raw.githubusercontent.com/check-spelling/cspell-dicts/v20230509/dictionaries/csharp/csharp.txt)|32|2|2|
    [cspell:cpp/src/compiler-clang-attributes.txt](https://raw.githubusercontent.com/check-spelling/cspell-dicts/v20230509/dictionaries/cpp/src/compiler-clang-attributes.txt)|46|2|2|
    [cspell:aws/aws.txt](https://raw.githubusercontent.com/check-spelling/cspell-dicts/v20230509/dictionaries/aws/aws.txt)|218|2|2|
    [cspell:python/src/python/python.txt](https://raw.githubusercontent.com/check-spelling/cspell-dicts/v20230509/dictionaries/python/src/python/python.txt)|392|2|2|
    
    Consider adding to the `extra_dictionaries` array (in the `.github/actions/spelling/config.json` file):
    
    json
    "cspell:cpp/src/lang-keywords.txt",
    "cspell:csharp/csharp.txt",
    "cspell:cpp/src/compiler-clang-attributes.txt",
    "cspell:aws/aws.txt",
    "cspell:python/src/python/python.txt",

    To stop checking additional dictionaries, put (in the `.github/actions/spelling/config.json` file):
    
    json
    "check_extra_dictionaries": []
    `

    </details>

    <!-- See https://github.com/check-spelling/check-spelling/wiki/Configuration-Examples%3A-advice --> <!-- markdownlint-disable MD033 MD041 -->
    <details>
    <summary>
    :pencil2: Contributor please read this
    </summary>

    By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

    If the listed items are:

    ... misspelled, then please correct them instead of using the command.
    ... names, please add them to
    .github/actions/spelling/allow/names.txt.
    ... APIs, you can add them to a file in
    .github/actions/spelling/allow/.
    ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
    ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in
    .github/actions/spelling/patterns/.

    See the README.md in each directory for more information.

    :microscope: You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. :wink:

    <details><summary>If the flagged items are :exploding_head: false positives</summary>

    If items relate to a ...

    binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can [test](
    https://www.regexplanet.com/advanced/perl/) yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude [README.md](
    ../tree/HEAD/README.md) (on whichever branch you're using).

  • well-formed pattern.
  • If you can write a [pattern](
    https://github.com/check-spelling/check-spelling/wiki/Configuration-Examples:-patterns
    ) that would match it,
    try adding it to the
    patterns.txt` file.

    Patterns are Perl 5 Regular Expressions - you can [test](
    https://www.regexplanet.com/advanced/perl/) yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.
    </details>

    </details>

    s911415 s911415 commented on Oct 17, 2026 15:24 UTC
    Author

    @microsoft-github-policy-service agree

    lhecker lhecker commented on code on Oct 19, 2026 15:06 UTC
    Code Review
    src/winconpty/winconpty.cpp:1
    @@ -116,13 +120,38 @@ static bool _HandleIsValid(HANDLE h) noexcept
         return (h != INVALID_HANDLE_VALUE) && (h != nullptr);
     }
     
    +HRESULT _GenerateCodePageArgument(const bool supportsCodePageArgument,
    +                                  const UINT codePage,
    +                                  _Out_writes_(codePageArgumentLength) wchar_t* const codePageArgument,
    +                                  const size_t codePageArgumentLength,
    +                                  _Out_ BOOL* const useCodePageArgument)
    +{
    +    RETURN_HR_IF(E_INVALIDARG, !codePageArgument || codePageArgumentLength == 0 || !useCodePageArgument);
    +    codePageArgument[0] = L'\0';
    +    *useCodePageArgument = FALSE;
    +
    +    if (codePage != 0 && supportsCodePageArgument)
    +    {
    +        RETURN_IF_FAILED(StringCchPrintfW(codePageArgument, codePageArgumentLength, L"--codepage %u ", codePage));
    

    I wonder if this one should wait for inproc-ConPTY where this can be achieved trivially. It _is_ somewhat rare for a person to want to change the default CP used by conhost after all.

    Reviewers
    Assignees
    s911415 s911415
    Labels
    risk: low confidence: 91.3% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 71.5% (HIGH) · Higher = larger blast radius
    71.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 91.3% · Lower = rushed or shallow review
    91.3%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 6.2% · Safe to merge
    6.2%