@@ -484,6 +484,14 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
484484 protected readonly _osBackend : Promise < OperatingSystem > ;
485485
486486 private static readonly _activeExecutions = new Map < string , IActiveTerminalExecution & { dispose ( ) : void } > ( ) ;
487+
488+ /**
489+ * Terminal IDs currently being disposed by `kill_terminal`. Used to
490+ * suppress redundant steering messages in `_registerCompletionNotification`'s
491+ * `onDisposed` handler — the agent already receives the output through the
492+ * `kill_terminal` tool result.
493+ */
494+ private static readonly _killedByTool = new Set < string > ( ) ;
487495 public static getBackgroundOutput ( id : string ) : string {
488496 const execution = RunInTerminalTool . _activeExecutions . get ( id ) ;
489497 if ( ! execution ) {
@@ -514,6 +522,15 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
514522 return true ;
515523 }
516524
525+ /**
526+ * Marks a terminal ID as being killed by the `kill_terminal` tool so that
527+ * the `onDisposed` handler in `_registerCompletionNotification` skips the
528+ * redundant steering message.
529+ */
530+ public static markKilledByTool ( id : string ) : void {
531+ RunInTerminalTool . _killedByTool . add ( id ) ;
532+ }
533+
517534 private _resolveExecutionOptions ( args : IRunInTerminalInputParams ) : IResolvedExecutionOptions {
518535 const mode = args . mode ?? ( args . isBackground ? 'async' : 'sync' ) ;
519536 switch ( mode ) {
@@ -2320,6 +2337,13 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
23202337 // _activeExecutions.
23212338 const executionForDisposal = RunInTerminalTool . _activeExecutions . get ( termId ) ;
23222339 store . add ( terminalInstance . onDisposed ( ( ) => {
2340+ // If kill_terminal is disposing this terminal, the agent will
2341+ // receive the output through the normal tool-result flow —
2342+ // skip the redundant steering message.
2343+ if ( RunInTerminalTool . _killedByTool . has ( termId ) ) {
2344+ disposeNotification ( ) ;
2345+ return ;
2346+ }
23232347 if ( handleSessionCancelled ( ) ) {
23242348 return ;
23252349 }
0 commit comments