Here is the method:
Information about the build hooks that were used to delete the build output files here:
https://arduino.github.io/arduino-cli/latest/platform-specification/#pre-and-post-build-hooks-since-arduino-ide-165
If you are modifying an existing boards platform, you might find this feature useful:
https://arduino.github.io/arduino-cli/latest/platform-specification/#platformlocaltxt