It would be useful to have access $__history_id__ in the same way as one accesses $__user_id__.  I am running a local instance of galaxy and have modified the following file to achieve this:
lib/galaxy/jobs/__init__.py

At line ~694:
        incoming['__user_name__'] = user_name
+       if job.history and job.history.id:
+           incoming['__history_id__'] = job.history.id
+       else:
+           incoming['__history_id__'] = 'unknown'
I have tested this change and it appears to give me exactly what I want.  My question: does this change appear correct and can it be incorporated into the main galaxy code-base?

Thanks,
-tim