Skip to content

Terminal Ignoring First Character Of Input Via Terminal.sendText #215402

Closed

Description

@revrenlove

Type: Bug

So, I've been noticing this for a while now, but a lot of times (not every time) when I am using the terminal in VSCode and start typing, the initial first key press doesn't get recognized. I just thought it was a quirk and is easy enough to ignore...

BUT...

I have an extension I have authored that utilizes the terminal to execute commands. I have just noticed that (intermittently) when I call the sendText method, the first character of the string passed into that method also gets ignored.

Given the following code:

const terminal = vscode.window.createTerminal("MyTerminal");

terminal.sendText("cd ..");

I would expect the command being sent to the terminal to be cd .., but in the terminal (and only sometimes) it attempts to execute d .. - which is obviously not what is expected.

Is there any way to mitigate this? Is this just a bug in the actual terminal?

VS Code version: Code 1.90.0 (89de5a8, 2024-06-04T19:33:54.889Z)
OS version: Windows_NT x64 10.0.22631
Modes:

System Info
Item Value
CPUs 13th Gen Intel(R) Core(TM) i7-13620H (16 x 2918)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 15.71GB (6.22GB free)
Process Argv --crash-reporter-id 34d3cda8-5b84-4fa8-8387-6931ddf6106c
Screen Reader no
VM 0%
Extensions: none
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vscod805cf:30301675
binariesv615:30325510
vsaa593:30376534
py29gd2263:31024239
vscaat:30438848
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
pythongtdpath:30769146
welcomedialogc:30910334
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
pythontestfixt:30902429
pythonregdiag2:30936856
pythonmypyd1:30879173
h48ei257:31000450
pythontbext0:30879054
accentitlementst:30995554
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
jchc7451:31067544
showvideot:31016892
chatpanelc:31048052
dsvsc021:30996838
jg8ic977:31013176
pythoncenvpt:31062603
a69g1124:31058053
dvdeprecation:31068756
pythonprt:31056678
dwnewjupyter:31046869
newcmakeconfigv2:31071590
26j00206:31048877

Activity

  1. revrenlove commented on Jun 13, 2024

    @revrenlove
    Author
  2. meganrogge commented on Jun 13, 2024

    @meganrogge
    Collaborator

    what happens if you wait for this event and only then sendText?

    export const onDidOpenTerminal: Event<Terminal>;

  3. added
    info-needed
    on Jun 13, 2024
  4. revrenlove commented on Jun 13, 2024

    @revrenlove
    Author

    The issue still (sometimes) happens when sending the command to an existing terminal.

  5. revrenlove commented on Jun 13, 2024

    @revrenlove
    Author

    For context, this is the actual code. Basically, I check for a terminal named dotnet and use that if it already exists. The problem happens both on new terminal instances and existing ones.

    Further, the commands may execute fine several times in a row on an existing terminal, and then randomly, it'll drop the first character on a sendText call.

    import * as vscode from 'vscode';
    import { DotnetCommand } from '../models/dotnetCommand';
    
    const terminalName = 'dotnet';
    
    function executeCommand(directoryPath: string, dotnetCommand: DotnetCommand, ...commandArgs: string[]) {
    
        const terminal = ensureTerminal(directoryPath);
    
        let command = `dotnet ${dotnetCommand}`;
    
        if (commandArgs && commandArgs.length > 0) {
            command += ` ${commandArgs.join(' ')}`;
        }
    
        terminal.sendText(command);
    }
    
    function ensureTerminal(path: string): vscode.Terminal {
    
        let terminal: vscode.Terminal | undefined;
    
        vscode
            .window
            .terminals
            .forEach(t => {
                if (t.name === terminalName) {
                    terminal = t;
                }
            });
    
        if (!terminal) {
    
            const terminalOptions: vscode.TerminalOptions = {
                name: terminalName,
                cwd: path
            };
    
            terminal = vscode.window.createTerminal(terminalOptions);
        }
        else {
            terminal.sendText(['cd', `"${path}"`].join(' '), true);
        }
    
        return terminal;
    }
    
    export { executeCommand };
  6. added
    terminal
    and removed
    info-needed
    on Jun 13, 2024
  7. Tyriar commented on Jun 13, 2024

    @Tyriar
    Contributor

    Can you show a screenshot of the issue and provide your settings.json? I have a suspicion I know what this is (emoji or other ambiguous special chars in the prompt).

  8. added
    info-needed
    on Jun 13, 2024
  9. revrenlove commented on Jun 13, 2024

    @revrenlove
    Author

    Note the error: bash: d: command not found - it cut off the "c" character that should have been in there.

    vscode-error

    settings.json:

    {
        "workbench.sideBar.location": "right",
        "workbench.colorCustomizations": {
            "[Blueberry Banana]": {
                "statusBar.debuggingBackground": "#b9355d"
            }
        },
        "editor.codeActionsOnSave": {
            "source.fixAll": "explicit"
        },
        "todo-tree.tree.showScanModeButton": false,
        "editor.suggestSelection": "first",
        "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
        "editor.semanticHighlighting.enabled": true,
        "csharp.semanticHighlighting.enabled": true,
        "cSpell.userWords": [
            "Activable",
            "Acxiom",
            "appsettings",
            "Architected",
            "ASMX",
            "classlib",
            "Cookeville",
            "dawg",
            "Deloitte",
            "displayport",
            "Dtos",
            "elrod",
            "enablement",
            "endregion",
            "Envitia's",
            "EODG",
            "esbuild",
            "fucky",
            "geolocation",
            "Grpc",
            "Healthtrust",
            "Jira",
            "Laughlin",
            "localdb",
            "Lucero",
            "microservice",
            "mocharc",
            "multitenant",
            "Murfreesboro",
            "nuget",
            "POCOs",
            "Readonly",
            "Referer",
            "repos",
            "Revren",
            "revrenlove",
            "RXNT",
            "Ryman",
            "Sencha",
            "SQLEXPRESS",
            "SSRS",
            "strang",
            "transpiled",
            "tsdoc",
            "Tweetinvi",
            "typeof",
            "Usings",
            "webapi",
            "Winform",
            "Xunit"
        ],
        "files.exclude": {
            "**/.vs": true,
            "**/node_modules": true,
            "**/bin": true,
            "**/obj": true
        },
        "javascript.referencesCodeLens.enabled": true,
        "typescript.referencesCodeLens.enabled": true,
        "typescript.implementationsCodeLens.enabled": true,
        "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
        "glassit.alpha": 255,
        "workbench.iconTheme": "material-icon-theme",
        "omnisharp.enableRoslynAnalyzers": true,
        "[html]": {
            "editor.defaultFormatter": "vscode.html-language-features"
        },
        "[typescript]": {
            "editor.defaultFormatter": "vscode.typescript-language-features"
        },
        "[css]": {
            "editor.defaultFormatter": "esbenp.prettier-vscode"
        },
        "[yaml]": {
            "editor.insertSpaces": true,
            "editor.tabSize": 2,
            "editor.autoIndent": "advanced",
            "diffEditor.ignoreTrimWhitespace": false
        },
        "typescript.updateImportsOnFileMove.enabled": "always",
        "git.autofetch": true,
        "debug.onTaskErrors": "debugAnyway",
        "[javascript]": {
            "editor.defaultFormatter": "esbenp.prettier-vscode"
        },
        "mocha.coverage": {
            "enable": false
        },
        "mocha.files.glob": "test/**/*.ts",
        "explorer.compactFolders": false,
        "python.languageServer": "Jedi",
        "csharpsortusings.sort.usings.splitGroups": false,
        "todo-tree.general.tags": [
            "BUG",
            "HACK",
            "FIXME",
            "TODO",
            "XXX",
            "[ ]",
            "[x]"
        ],
        "todo-tree.regex.regex": "(//|#|<!--|;|/\\*|^|^\\s*(-|\\d+.))\\s*($TAGS)",
        "security.workspace.trust.untrustedFiles": "open",
        "[markdown]": {
            "editor.defaultFormatter": "DavidAnson.vscode-markdownlint"
        },
        "editor.defaultFormatter": "esbenp.prettier-vscode",
        "editor.formatOnSave": true,
        "javascript.referencesCodeLens.showOnAllFunctions": true,
        "typescript.referencesCodeLens.showOnAllFunctions": true,
        "bracket-pair-colorizer-2.depreciation-notice": false,
        "[csharp]": {
            "editor.defaultFormatter": "ms-dotnettools.csharp"
        },
        "terminal.integrated.enableMultiLinePasteWarning": false,
        "git.confirmSync": false,
        "debug.javascript.unmapMissingSources": true,
        "typescript.tsserver.experimental.enableProjectDiagnostics": true,
        "todo-tree.highlights.customHighlight": {
            "BUG": {
                "icon": "bug"
            },
            "HACK": {
                "icon": "tools"
            },
            "FIXME": {
                "icon": "flame"
            },
            "XXX": {
                "icon": "x"
            },
            "[ ]": {
                "icon": "issue-draft"
            },
            "[x]": {
                "icon": "issue-closed"
            }
        },
        "terminal.integrated.defaultProfile.windows": "Git Bash",
        "git.enableSmartCommit": true,
        "[typescriptreact]": {
            "editor.tabSize": 4
        },
        "cSpell.ignorePaths": [
            "package-lock.json",
            "node_modules",
            "vscode-extension",
            ".git/objects",
            ".vscode",
            ".vscode-insiders",
            "secrets.json"
        ],
        "prettier.tabWidth": 4,
        "c-sharp-utilities.jimTestConfigNext": 8673,
        "revUtil.Sandwich.IntToo": 97688,
        "cmake.configureOnOpen": true,
        "[aspnetcorerazor]": {
            "editor.defaultFormatter": "ms-dotnettools.csharp"
        },
        "editor.minimap.enabled": false,
        "azureFunctions.showCoreToolsWarning": false,
        "c-sharp-utilities.usingStatementsToInclude": ["item 1", "item 2"],
        "c-sharp-utilities.newItemTemplate.namespacesToInclude": [
            "System",
            "System.Text"
        ],
        "c-sharp-utilities.newItemTemplate.includeUsingStatements": true,
        "c-sharp-utilities.newItemTemplate.fileScopedNamespace": false,
        "githubIssues.queries": [
            {
                "label": "My Issues",
                "query": "is:open assignee:${user} repo:${owner}/${repository}",
                "groupBy": ["milestone"]
            },
            {
                "label": "Created Issues",
                "query": "author:${user} state:open repo:${owner}/${repository} sort:created-desc"
            },
            {
                "label": "Recent Issues",
                "query": "state:open repo:${owner}/${repository} sort:updated-desc"
            }
        ],
        "c-sharp-utilities2.newItemTemplate.namespacesToInclude": [
            "System",
            "System.Text",
            "Madness",
            "fssf",
            "sfsfn"
        ],
        "prettier.singleQuote": true
    }
    
  10. 12 remaining items

  11. adamerose commented on Mar 11, 2025

    @adamerose

    This is a VERY annoying bug that happens on many different Windows machines for me for a long time now.


    • It only happens with Git Bash as the default terminal, never with Command Prompt or PowerShell
    • It seems to just happen randomly. Sometimes when I paste a command. Sometimes when I click the "Run" button for a Python script. It seems to happen for any feature or extension that sends text to the terminal.
    • The most reliable way I've found to reproduce it is to open Cursor and ask the AI to run 20 random terminal commands for me and usually at least one will have the first character cut off.
    • Still happens with all extensions and settings disabled
    • I am NOT able to reliably reproduce the bug the way OP said by calling createTerminal and then sendText... I even made an extension to test it a bunch of times in a row but it never triggers it for me
    for (let i = 0; i < 30; i++) {
        const terminal = vscode.window.createTerminal(`Test-${i+1}-${Date.now()}`);
        // If terminal stays open, bug reproduced! Because echo will fail if the first character is missed.
        terminal.sendText("echo 'hello world' && exit");
        terminal.show();
    }
    
    • Changing the values of the settings people mentioned above doesn't seem to make any difference
      • terminal.integrated.shellIntegration.enabled
      • terminal.integrated.scrollback
      • terminal.integrated.enablePersistentSessions
      • terminal.integrated.commandsToSkipShell
    • Doesn't matter whether I use the built-in Git Bash profile like "terminal.integrated.defaultProfile.windows": "Git Bash" or define my own custom profile with a path like this:
      "terminal.integrated.defaultProfile.windows": "GitBash",
      "terminal.integrated.profiles.windows": {
        "GitBash": {
          "path": "C:\\Program Files\\Git\\bin\\bash.exe",
          "args": ["-i", "-l"]  // Bug happens with and without these args as well
        }
      },
    

    Image

  12. quyenvsp commented on Mar 11, 2025

    @quyenvsp

    Adam Rose (@adamerose) agree, it very annoying and not easy to reproduce. All I know is it happen from Jun 2, 2023 when Git for Windows v2.41.0.windows.1 released #187804 xtermjs/xterm.js#4600

    Side question, do you use PowerToys or Windows Terminal (Preview)? I suspect this is coming from git bash rather than vscode

  13. revrenlove commented on Mar 11, 2025

    @revrenlove
    Author

    I was looking for a source (couldn't find one), but at one point, I think I read that it has something to do with Windows's bash "emulator"... It's possible I'm talking out of my ass.

    v2.😮 of C# Utilities Extension with functionality that doesn't need to worry about this coming soon.

  14. adamerose commented on Mar 11, 2025

    @adamerose

    All I know is it happen from Jun 2, 2023 when Git for Windows v2.41.0.windows.1

    I just spent an hour testing various Git Bash versions and it goes back much further than this. I reproduced the bug on every version I tried, which included 2.48.1, 2.41, 2.40, 2.29, 2.16 and even 2.7.4 from 2016

    Image

    Side question, do you use PowerToys or Windows Terminal (Preview)? I suspect this is coming from git bash rather than vscode

    PowerToys the set of Windows utilities? I do use that, but not sure how it relates to Git Bash.

    I thought the issue only happened when running Git Bash through the VS Code integrated terminal. I can confirm the bug happens in VS Code regardless of whether you install Git Bash with "Use MinTTY" or "Use Windows' default console window". This makes sense because the VSC integrated terminal is just using ConPTY with the Git Bash shell, it doesn't depend on what you pick as the Git Bash terminal.

    I'll come back and update if I ever do run into it with the dedicated Git Bash terminal.

  15. quyenvsp commented on May 14, 2025

    @quyenvsp

    Adam Rose (@adamerose) these are new setting terminal.integrated.windowsUseConptyDll can you try?

  16. UncleGus commented on May 21, 2025

    @UncleGus

    I'm glad to find that it's not only affecting me. The number of times I have seen
    $ it push --force bash: it: command not found
    is too damn high.

  17. quyenvsp commented on May 29, 2025

    @quyenvsp

    After 2 weeks, I confirm terminal.integrated.windowsUseConptyDll really did something helpful. Before about 3 times / day, after that setting only about 2 times / 2 weeks. Less painful but still here!

  18. nycpivot commented on Jul 30, 2025

    @nycpivot

    I'm getting sick of this too. FIX IT.

  19. revrenlove commented on Jul 30, 2025

    @revrenlove
    Author
  20. Tyriar commented on Jul 31, 2025

    @Tyriar
    Contributor

    FYI the original report is different to the conpty problem which is tracked in #243584

    terminal.integrated.windowsUseConptyDll was true for a while in insiders but was switched back to false because of some outstanding problems which the first input getting missed after reloading the window being one of the bigger ones. Setting that to false should fix that problem specifically if you has it explicitly set (since false is the default).

  21. quyenlv-unicloud commented on Aug 8, 2025

    @quyenlv-unicloud

    from May 29 terminal.integrated.windowsUseConptyDll: true work fine for me on Git bash for Windows with Zsh + Pure theme. Only about 3 times / 2 months.
    But now when upgrade latest version 1.102.3 it happen again too many times again per day, really hope we will found stable version of conpty soon.

  22. Tyriar commented on Oct 15, 2025

    @Tyriar
    Contributor

    /duplicate #243584

  23. added
    *duplicate
    on Oct 15, 2025
  24. locked and limited conversation to collaborators on Nov 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

*duplicateapibugterminal-input

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions