diff --git a/src/Yi/Frontend/Vty.hs b/src/Yi/Frontend/Vty.hs
--- a/src/Yi/Frontend/Vty.hs
+++ b/src/Yi/Frontend/Vty.hs
@@ -61,6 +61,7 @@
                                                         vertCat, withBackColor,
                                                         withForeColor,
                                                         withStyle, (<|>))
+import           System.Exit                    (ExitCode, exitWith)
 import           Yi.Buffer
 import           Yi.Config
 import           Yi.Debug                       (logError, logPutStrLn)
@@ -86,7 +87,7 @@
 data FrontendState = FrontendState
     { fsVty :: Vty.Vty
     , fsConfig :: Config
-    , fsEndMain :: MVar ()
+    , fsEndMain :: MVar ExitCode
     , fsEndInputLoop :: MVar ()
     , fsEndRenderLoop :: MVar ()
     , fsDirty :: MVar ()
@@ -174,7 +175,8 @@
 main fs = do
     tid <- myThreadId
     labelThread tid "VtyMain"
-    takeMVar (fsEndMain fs)
+    exitCode <- takeMVar (fsEndMain fs)
+    exitWith exitCode
 
 layout :: FrontendState -> Editor -> IO Editor
 layout fs e = do
@@ -182,14 +184,15 @@
     let (e', _layout) = SL.layout colCount rowCount e
     return e'
 
-end :: FrontendState -> Bool -> IO ()
-end fs mustQuit = do
+end :: FrontendState -> Maybe ExitCode -> IO ()
+end fs mExit = do
     -- setTerminalAttributes stdInput (oAttrs ui) Immediately
     void $ tryPutMVar (fsEndInputLoop fs) ()
     void $ tryPutMVar (fsEndRenderLoop fs) ()
     Vty.shutdown (fsVty fs)
-    when mustQuit $
-        void (tryPutMVar (fsEndMain fs) ())
+    case mExit of
+      Nothing   -> pure ()
+      Just code -> void (tryPutMVar (fsEndMain fs) code)
 
 requestRefresh :: FrontendState -> Editor -> IO ()
 requestRefresh fs e = do
diff --git a/yi-frontend-vty.cabal b/yi-frontend-vty.cabal
--- a/yi-frontend-vty.cabal
+++ b/yi-frontend-vty.cabal
@@ -1,9 +1,9 @@
--- This file has been generated from package.yaml by hpack version 0.17.0.
+-- This file has been generated from package.yaml by hpack version 0.17.1.
 --
 -- see: https://github.com/sol/hpack
 
 name:           yi-frontend-vty
-version:        0.14.1
+version:        0.15.0
 synopsis:       Vty frontend for Yi editor
 category:       Yi
 homepage:       https://github.com/yi-editor/yi#readme
