anchor.diff:              |> Promise.suppress
               |> ignore)
   
  +
  +    let private clearOldTerminalState () =
  +        fsiOutput |> Option.iter (fun t -> t.dispose())
  +
       let private handleCloseTerminal (terminal : Terminal) =
  -        fsiOutputPID
  -        |> Option.iter (fun currentTerminalPID ->
  -            terminal.processId
  -            |> Promise.onSuccess (fun closedTerminalPID ->
  -                if closedTerminalPID = currentTerminalPID then
  -                    fsiOutput <- None
  -                    fsiOutputPID <- None
  -                    lastCd <- None
  -                    lastCurrentFile <- None)
  -            |> Promise.suppress // prevent unhandled promise exception
  -            |> ignore)
  -        |> ignore
  +        fsiOutput <- None
  +        fsiOutputPID <- None
  +        lastCd <- None
  +        lastCurrentFile <- None
  +        ()
  +
  +    // when a new terminal is created, if it's FSI and if we don't already have a terminal then setup the state for tracking FSI
  +    let private handleOpenTerminal (terminal: Terminal): unit =
  +        if terminal.name = fsiNetCoreName || terminal.name = fsiNetFrameworkName
  +        then
  +            clearOldTerminalState ()
  +            setupTerminalState terminal
  +            // initially have to set up the terminal to be in the correct start directory
  +            sendCd window.activeTextEditor
   
       let private generateProjectReferences () =
           let ctn =
  
positive.code:                     window.showErrorMessage("Unable to spawn FSI", null) |> ignore
                      failwith "unable to spawn FSI"
              let w = Fable.Core.JsInterop.import "window" "vscode"
              let terminal: Terminal = w?createTerminal(profile.options)
              terminal.processId |> Promise.onSuccess (fun pId -> fsiOutputPID <- Some pId) |> ignore
              lastCd <- None
              lastCurrentFile <- None
              fsiOutput <- Some terminal
              sendCd window.activeTextEditor
              terminal.show(true)
              return terminal
          }
  
negative.code:                 Some (U2.Case2 work)
              }
  
      let private setupTerminalState (terminal: Terminal) =
          terminal.processId |> Promise.onSuccess (fun pId -> fsiOutputPID <- Some pId) |> ignore
          lastCd <- None
          lastCurrentFile <- None
          fsiOutput <- Some terminal
  
      let private start () =
          fsiOutput |> Option.iter (fun n -> n.dispose())
          promise {
  