The invention is fused heterocyclic compounds of formula (I), and salts thereof, compositions thereof, and methods of use therefor. In particular, disclosed herein are certain fused heterocyclic compounds that can be useful for inhibiting protein kinase, including Brutons tyrosine kinase (Btk), and for treating disorders mediated thereby.