Simple C# code to retrieve a list of GitHub Copilot CLI sessions
Posted: (EET/GMT+2)
Three weeks ago, I wrote about taking the GitHub Copilot CLI's plan.md file with your version control commits/checkins. Today, I ran into another problem when I rebooted my computer: I had multiple Windows Terminal sessions open, but they were lost during reboot, so I had to start fresh. My workflow involves keeping multiple sessions open, allowing me to return to them quickly. So, the question became: how do I then know which sessions I can resume with copilot --resume <id>? If you know the ID, you can go to that session directly.
Turns out that GitHub Copilot CLI stores a file called workspace.yaml inside the same session folders I mentioned in my previous post. The YAML file looks something like this:
id: 12345abc-4433-2211-aabb-ccddeeff1122 cwd: C:\Code\MyProject summary: Plan Application Core Features in ASP.NET Core MVC summary_count: 2 created_at: 2026-03-27T09:44:46.224Z updated_at: 2026-05-03T15:53:02.475Z
You could go and read the "session-state" folders, looking for the YAML file and getting the session ID from the file manually. But of course, you can also write some C# to do that more easily.
Here's a quick example:
public record AiSessionInfo
{
public string Id { get; set; } = "";
public string Cwd { get; set; } = "";
public string Summary { get; set; } = "";
public string FilePath { get; set; } = "";
}
public class CopilotSessionReader
{
public static List GetWorkspaces(string rootFolder)
{
return FindWorkspaces(rootFolder);
}
internal static List FindWorkspaces(string rootFolder)
{
List results = [];
if (!Directory.Exists(rootFolder))
{
Console.WriteLine("Folder does not exist: " + rootFolder);
return results;
}
string[] files = Directory.GetFiles(rootFolder, "workspace.yaml", SearchOption.AllDirectories);
foreach (string file in files)
{
AiSessionInfo info = ParseWorkspaceYaml(file);
results.Add(info);
}
return results;
}
internal static AiSessionInfo ParseWorkspaceYaml(string filePath)
{
AiSessionInfo info = new()
{
FilePath = filePath
};
foreach (string line in File.ReadLines(filePath))
{
if (line.StartsWith("id:"))
{
info.Id = line["id:".Length..].Trim();
}
else if (line.StartsWith("cwd:"))
{
info.Cwd = line["cwd:".Length..].Trim();
}
else if (line.StartsWith("summary:"))
{
info.Summary = line["summary:".Length..].Trim();
}
}
return info;
}
}
Yes, I'm aware that you can say copilot --continue to go to the latest session, or just copilot --resume (without the ID) that allows me to pick a session from a list with my arrow keys, but that doesn't help with automation: opening multiple tabs automatically (including going to the correct folder) in my terminal.
That's why I think a solution like the above C# code is the best thing – at present.
Happy AI hacking!