Arduino IDE 2.x bug recipe.hook

I think the best way to provide for this use case would be the addition of a property that indicates whether it is a normal compilation or the compilation database generation. You could pass that property to your prebuild.exe tool via an argument and then the tool's code (or a wrapper script/command if the tool code can't be modified) could determine whether or not to increment the build number based on the value of the argument.

Something similar was done for identification of when the recipe.preproc.macros command is ran for library discovery:

My suggestion is that you submit a feature request to the Arduino CLI issue tracker.

https://github.com/arduino/arduino-cli/issues/new/choose

Obviously that won't solve your problem immediately. It may be that the other forum members have some ideas about how to work around this issue. I think they might be better equipped to do so if you provide more information about how this build number system works. Is the tool writing the build number to a header file or something?