All the calls to the Termux:API will hang the process. E.g. running termux-battery-status on the Termux command line does not return any information and waits forever (Ctrl-C to break).
It seems that battery optimization against Termux:API is the problem. Disabling the Settings ⇒ DuraSpeed option for all the system solved the problem. Unfortunately at the moment there is not an option to disable DuraSpeed for Termux:API only.
Trying to add the Termux:Widget on the desktop, only the Termux shortcut 1×1 option is available, the larger and resizable Termux widget 2×2 is not listed as an option.
It turned out that installing the Termux:Widget app into the external SD card is the problem. From Settings ⇒ Storage ⇒ SD Card ⇒ Apps ⇒ Termux:Widget ⇒ Storage used ⇒ Change it is possible to move the app to the internal shared storage.
After some time of usage the widget suddendly stops working. Pressing the reload icon does not longer show the “Termux shortucts reloaded” toast. Tapping anyone of the items does not start the relevant script. Sometimes the list of items resets itself, displaying the “No files in $HOME/.shortcuts/” .
The problem is caused by battery optimization: disabling the Settings ⇒ DuraSpeed option solves the problem. Starting from Termux:Widget version 0.13.0 it is possibile to disable DuraSpeed for the app only, leaving it enabled for the other apps.
Starting from Android 10 the Termux:Widget requires that Termux app gets the permission to draw over other apps, otherwise it cannot start a terminal session from the background. Unfortunately some Android versions deny to grant such permission to Termux… add the error message here.