Where VS Code stores the list of open files?

I'm pretty sure you're right with AppData\Roaming\Code being the location in question. Specifically:

  • AppData\Roaming\Code\storage.json and in that the windowsState section.
  • AppData\Roaming\Code\Backups\workspaces.json

These files (or at least storage.json) do not get updated until you exit Code (File > Exit). If you are leaving Code open on your work machine and not seeing the changes when you get to your home machine, that might be why you're not seeing the expected.

Code / Atom also stores state information in sqlite3 databases and lots of state information is stored in there:

  • AppData\Roaming\Code\Local Storage\file__0.localstorage

Use an SQLite browser tool such as http://sqlitebrowser.org/ to open it up. You'll see lots of familiar path references in the table ItemTable. The column value shows as "BLOB" (binary) but you can click on any row and export the data to a file. Do this and open up it up in a text editor (e.g. Code! :)) and you'll see it's just a JSON string.

(As VS Code is based on GitHub's Atom editor, searching for issues using "Atom" rather than "Code" often digs up information you might not otherwise find.)


I'm totally agree with @Jonathan and want to add a bit more.

For the question, the opened files was stored in file__0.localstorage which is a sqlite file. And I just write a bit of code for extract the list of opened files. Hope it helps.

import sqlite3
import pandas as pd
import json

fn = r"C:\Users\HelloWorld\AppData\Roaming\Code\Local Storage\file__0.localstorage"
conn = sqlite3.connect(fn)
df = pd.read_sql("select key, value as _value from ItemTable", conn)
df["v"] = df.pop("_value").map(lambda x: x.decode("utf-16"))

# should be choosen carefully
known_file_opened = "numpy"
known_file_closed = "aws"

df_check = df[
    df.v.str.contains(known_file_opened)
    &(~df.v.str.contains(known_file_closed))
]
assert len(df_check) == 1

js = json.loads(df_check.v.iloc[0])
editors = js["groups"][0]["editors"]
print("Found %d editors" %(len(editors)))

paths = []
for editor in editors:
    js_ = json.loads(editor["value"])
    path = js_["resourceJSON"]["fsPath"]
    paths.append(path)

print("Found opened file list:\n%s" %(paths))