

Tl dr the solution is to run sudo cp -R /Library/Developer/CommandLineTools/SDKs/MacOSX12* /Applications/Xcode.app/Contents/Developer/Platforms/atform/Developer/SDKs/ I had this same problem, but none of the solutions above worked for me. Keep in mind that the Xcode tools when opening Xcode after further updates will need to be updated, but in my experience this should NOT affect the CLI tools. It seems the issue is not related to the architecture of the mac (M1 or Intel) or the Xcode version! Keep in mind, tools for the platforms you chose will be downloaded in the background, which might take a bit. Close and re-open your Terminal and try your CLI tools again.

Choose as few as possible as these take hard disk space!

If you use command line tools like Homebrew, you might have received the following error (the part below is just an excerpt of it): clang: error: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/atform/Developer/SDKs/MacOSX.sdk -find clang 2> /dev/null' failed with exit code 34304: (null) (errno=Invalid argument) This issue happened on my MacBook Air M1 machine after update macOS Monterey 12.6 released recently and installing Xcode CLI tools version 14.0.
