A tool feels slow on an M-series Mac and you wonder if it runs through Rosetta. The binary itself says which architectures it was built for.
lipo -archs prints only the architecture names, one word each, which makes it easy to use in scripts:
lipo -archs /opt/homebrew/bin/gh
arm64
lipo -archs /bin/ls
x86_64 arm64e arm64e.x1
arm64 alone means Apple silicon only, and the arm64e variants are what Apple uses for its own system binaries. x86_64 alone means Intel only, so on an M-series Mac it runs under Rosetta 2. Both together is a universal binary. For an app, point it at the executable inside the bundle:
lipo -archs /Applications/SomeApp.app/Contents/MacOS/SomeApp
I’d check this when a command line tool came from a random download rather than Homebrew, because those are the ones that are still Intel only.
It only looks at Mach-O files. Point it at a shell script or a Python entry point and it complains that the file is not an object file, because the real work happens in the interpreter. In that case check the interpreter instead, for example lipo -archs $(which python3). Activity Monitor shows the same thing for running apps in its Kind column.
Further reading: lipo man page (macOS)