1

I have a couple scripts that rewrite my windows terminal settings.json file from a template.

While fixing a bug I noticed another file, state.json. But I can't find any documentation for it. Here's my redacted version:

{
    "dismissedMessages" : 
    [
        "setAsDefault"
    ],
    "generatedProfiles" : 
    [
        "{<some-guid1>}",
        "{<some-guid2>}",
        "{<some-guid3>}",
        "{<some-guid4>}",
        "{<some-guid5>}",
        "{<some-guid6>}"
    ],
    "settingsHash" : "<some-hash<"
}

What do these key/values mean?

xdhmoore
  • 675

2 Answers2

2

The only info I've found on the Microsoft Terminal doc site is this page with the following statement in the context of reseting your settings.json to defaults:

As of Windows Terminal version 1.10 or greater, you'll also need to delete the state.json file in the same directory as the settings.json file to fully reset the settings to the defaults.

In the github repo I found this spec page, which says among other things:

Terminal is going to need a place to store application "state", including:

  • Dialogs the user has chosen to hide with a [ ] Do not ask again checkbox, as proposed in issue 6641
  • Which dynamic profiles have been generated, as a way to resolve user dissatisfaction around profiles "coming back"
  • On-screen position of the window, active session state, layout, etc. for eventual restoration

This specification provides for a place to store these things.

I didn't find a schema for this file like they have for settings.json, but this .h file appears to be where at least some of these fields are declared.

So, this appears to be a file for Terminal to keep state that won't be blown away by a user's editing of settings.json. It also seems like one focus is storing state related to Terminal's interactions with a settings.json file that has also been edited directly by a user.

The keys in my json file are self-evident in context of the above spec, though I'm less sure of settingsHash. This appears to be where it is currently used, as a way to avoid recomputation of the "JumpList". This seems to indicate that settingsHash should be a hash of all the current settings including user's settings.json edits, and not just the original settings generated by Terminal.

Why computing the JumpList would be CPU-intensive, I don't know. Perhaps it's not, it just involves slow API calls to the OS.

In particular, I see no reason to edit or modify this file unless I want to reset my settings.json back to factory defaults.

xdhmoore
  • 675
  • 1
    I'd recommend changing the question to more useful "What is Windows Terminal's state.json file?' or "What does Windows Terminal's state.json file do?" or anything alike, which is also more fitting for the answer you've provided. – Destroy666 Jul 31 '23 at 04:20
  • 2
    @Destroy666 changed. – xdhmoore Jul 31 '23 at 21:02
  • 1
    "Perhaps it's not, it just involves slow API calls to the OS" - That's exactly the reason it's there. Setting up the Jumplist involves a bunch of COM calls, and doing those during startup pretty heavily impacts startup perf for the Terminal – zadjii Aug 02 '23 at 17:51
1

Although I didn't find any official doc, state.json is used for saving the Windows Terminal session state when Open windows from previous session setting is enabled ("firstWindowPreference": "persistedWindowLayout" in settings.json as described here.

I'm fiddling with state.json a lot because I'm constantly customizing my startup tabs, directories etc. and it seems it works with the concept of actions. It seems that Windows Terminal replays actions specified in state.json upon WT startup while possible actions might be "open tab in this directory with such title", "rename the tab to 'something'" etc.

I tried to search for some state.json spec briefly and I was unsuccessful, but it seems the list of available actions is specified here in WT github

One can deduce a lot from their names. For example, the action switchToTab allows setting the default active tab upon WT start.

Here is a snippet from my state.json, that opens two tabs and sets the second one to active:

{
    "action" : "newTab",
    "commandline" : "\"C:\\Program Files\\PowerShell\\7\\pwsh.exe\"",
    "profile" : "PowerShell",
    "startingDirectory" : "P:\\git-cz-moneta-wps\\wps\\devops\\openapi-codegen\\output",
    "suppressApplicationTitle" : false,
    "tabTitle" : "openapi-codegen/output"
},
{
    "action" : "newTab",
    "commandline" : "\"C:\\Program Files\\PowerShell\\7\\pwsh.exe\"",
    "profile" : "PowerShell",
    "startingDirectory" : "s:\\",
    "suppressApplicationTitle" : false,
    "tabTitle" : "scripts"
},
{
    "action" : "switchToTab",
    "index" : 1
}
brkerez
  • 11