I know that the i3 state is stored in a tree somewhere. Does anyone know how I could retrieve the state of my i3 environment to deal with as I wish?
i3 lets you see its internals at various levels and which level is useful to you depends on what you want to do with it.
To graphically view the tree, the i3 source code includes gtk-tree-watch, which displays the tree in a GTK window.
If you want to dump the layout to restore it later on, i3 allows saving and restoring layouts and the commands for that include one that will dump the layout,
If you want very detailed information about the tree, use the
get_tree message from i3's IPC mechanism. You can do that for example with
i3-msg -t get_tree