The present invention relates to processes and intermediates for preparing compounds useful as inhibitors of ATR kinase, such as aminopyrazine-isoxazole derivatives and related molecules. The present invention also relates to compounds useful as inhibitors of ATR protein kinase. The invention relates to pharmaceutically acceptable compositions comprising the compounds of this invention; methods of treating of various diseases, disorders, and conditions using the compounds of this invention; processes for preparing the compounds of this invention; intermediates for the preparation of the compounds of this invention; and solid forms of the compounds of this invention. The compounds of this invention have formula I or II: wherein the variables are as defined herein.