Skip to content

Auto restore last session

Cameron Ring edited this page Aug 21, 2025 · 1 revision

This optional feature enables the keeping track and loading of the last session. The last session is only loaded at startup if there isn't already a session for the current working directory. This feature can come in handy when starting Neovim from a GUI for example.

⚠️ If the directory does not exist, default directory will be used and an error message will be printed.
⚠️ This feature is still experimental and as of right now it interferes with the plugin's ability to auto create new sessions when opening Neovim in a new directory.

require("auto-session").setup {
  auto_restore_last_session = true,
}

A quick workaround for inability to auto create new sessions is to conditionally enable last session.

require("auto-session").setup {
  auto_restore_last_session = vim.loop.cwd() == vim.loop.os_homedir(),
}

Now last session will be restored only when Neovim is launched in the home directory, which is usually right after launching the terminal or Neovim GUI clients.

Clone this wiki locally