Similar question here Shortcut for collapsing active module - Software / darktable - discuss.pixls.us
The PR mentioned in the discussion was later reversed due to insufficient testing. An alternative implementation can be found in fix header of first module at top of panel · dterrahe/darktable@e7f4fc3