context-fold does this:

https://pi.dev/packages/context-fold