Also facing the same situation.
I'd like to run a script that generates code (the script is in the package directory, and the generated code should also end up in the package directory).
Using a buildTool plugin, I can get the plugin to run before each build, but cannot get it to save files outside of DerivedData directory, which is the issue @benkai is hitting.
If I change it to a command() plugin, I can get it to write to the package directory, but can't figure out how to run it without manually typing swift package <command>.
Has anyone discovered if it's possible to do both:
Run a script before each package build (like a .buildTool plugin)
Write to the package directory (like a command plugin)
How can I just give my buildTool plugin permission to write anywhere?