After years of installing things, the list of manually installed packages on my systems is a mess, and apt autoremove can only clean what is marked automatic. This command shrinks that list.
sudo apt-mark minimize-manual
The man page says minimize-manual marks the (transitive) dependencies of metapackages as automatically installed. It suggests using it after an installation to reduce the number of manually installed packages. It can also be run continuously on systems managed by system configuration metapackages.
Here is how I’d use it. First look at what is marked manual:
apt-mark showmanual | wc -l
sudo apt-mark minimize-manual
apt-mark showmanual | wc -l
apt autoremove --dry-run
The first and third commands show how many packages dropped off the manual list. The last one only simulates, so you can read what autoremove would delete before anything is touched.
The caveat: once a dependency of a metapackage is automatic, apt may remove it as soon as nothing manual needs it. That is the point, but it also means a tool you use by hand and that happens to be a dependency of a metapackage can show up in the autoremove list. If you want to keep it, mark it again:
sudo apt-mark manual somepackage
The manual page does not say more about what happens to specific packages, so read the dry run output first. State is kept in the file extended_states in the directory set by Dir::State, unless you pass another file with -f.
Further reading: apt-mark(8)