I think what is causing problems for @anthonykim1 is that calling executeCommand immediately after onDidChangeTerminalShellIntegration would fire multiple times and end up triggering an invalid onDidEndTerminalShellExecution with exitCode=undefined but the execution was set when it shouldn't have been. We should suppress this event if possible.