Another option is to look at the parent process. When using crystal run, the parent is called crystal.
For example, on a Linux system
# crystal_run.cr
ppid = File.read("/proc/#{Process.pid}/status").scan(/(?<=PPid:\t)\d+/)[0]
crystal_run = File.read("/proc/#{ppid}/comm") == "crystal\n"
p! crystal_run
$ crystal run crystal_run.cr
crystal_run # => true
$ crystal build crystal_run.cr && ./crystal_run
crystal_run # => false