Use the thor debug option instead of the environment variable

Fixes #2790