So far $GALAXY_SLOTS seems to be working nicely for me.
However, I am wondering if it would be possible to use it inside the <configfile> section? Is that run at the time of job creation on the Galaxy server (where determining the number of threads may be hard) or as part of job execution (e.g. on the cluster, when $GALAXY_SLOTS would be known).
Unfortunately, the former, and there is no easy way to change this. One could do some simple variable substitution on the config file when the job runs though (sed would do the job here, not pretty but it works).