A compound of formula I, or a pharmaceutically acceptable salt thereof, wherein: Ring A is a 5-6 membered monocyclic heteroaryl ring having 1-4 heteroatoms independently selected from nitrogen, oxygen, or sulfur; which is optionally substituted; X is absent, -O-, -S-, -SO 2 -, -SO-, -C -, -CO 2 -, -C N -, -OC N -, -NRC -, -NRC N -, -NRSO 2 -, or -N -; or X is m -O-, - m S-, - m SO 2 -, - m SO-, - m C -, - m CO 2 -, - m C N -, - m OC N -,- m NRC -, - m NRC N -, - m NRSO 2 -, or - m N -; Y is an optionally substituted C 1-6 aliphatic; Z is absent, a divalent C 3-10 aryl, a divalent 3-8 membered saturated or partially unsaturated carbocyclic ring, a divalent 3-7 membered heterocylic ring having 1-4 heteroatoms independently selected from nitrogen, oxygen, or sulfur, or a divalent 5-6 membered monocyclic heteroaryl ring having 1-4 heteroatoms independently selected from nitrogen, oxygen, or sulfur; each of which is optionally substituted; or Z is -O-, -S-, -SO 2 -, -SO-, -C -, -CO 2 -, -C N -, -OC N -, -NRC -, -NRC N -, -NRSO 2 -, or-N -; W is CR or N; each R is independently hydrogen, C 1-6 aliphatic, C 3-10 aryl, a 3-8 membered saturated or partially unsaturated carbocyclic ring, a 3-7 membered heterocylic ring having 1-4 heteroatoms independently selected from nitrogen, oxygen, or sulfur, or a 5-6 membered monocyclic heteroaryl ring having 1-4 heteroatoms independently selected from nitrogen, oxygen, or sulfur; each of which is optionally substituted; or two R groups on the same atom are taken together with the atom to which they are attached to form a C 3-10 aryl, a 3-8 membered saturated or partially unsaturated carbocyclic ring, a 3-7 membered heterocylic ring having 1-4 heteroatoms independently selected from nitrogen, oxygen, or sulfur, or a 5-6 membered monocyclic heteroaryl ring having 1-4 heteroatoms independently selected from nitrogen, oxygen, or sulfur; each of which is optionally substituted; each R 1 is independently -R, halogen, -OR, -SR, -CN, -NO 2, -SO 2 R, -SOR, -C R, -CO 2 R, -C N 2, -NRC R, -NRC N 2, -NRSO 2 R, or -N 2; R 2 is -R, halogen, -OR, -SR, -CN, -NO 2, -SO 2 R, -SOR, -C R, -CO 2 R, -C N 2,-NRC R, -NRC N 2, -NRSO 2 R, or -N 2; R 4 is -R, halogen, -OR, -SR, -CN, -NO 2, -SO 2 R, -SOR, -C R, -CO 2 R, -C N 2,-NRC R, -NRC N 2, -NRSO 2 R, or -N 2; each m is independently 1 or 2; and n is 0, 1, 2, 3, 4, or 5. Ring A is a 5-6 membered monocyclic heteroaryl ring having 1-4 heteroatoms independently selected from nitrogen, oxygen, or sulfur; which is optionally substituted; X is absent, -O-, -S-, -SO 2 -, -SO-, -C -, -CO 2 -, -C N -, -OC N -, -NRC -, -NRC N -, -NRSO 2 -, or -N -; or X is m -O-, - m S-, - m SO 2 -, - m SO-, - m C -, - m CO 2 -, - m C N -, - m OC N -,- m NRC -, - m NRC N -, - m NRSO 2 -, or - m N -; Y is an optionally substituted C 1-6 aliphatic; Z is absent, a divalent C 3-10 aryl, a divalent 3-8 membered saturated or partially unsaturated carbocyclic ring, a divalent 3-7 membered heterocylic ring having 1-4 heteroatoms independently selected from nitrogen, oxygen, or sulfur, or a divalent 5-6 membered monocyclic heteroaryl ring having 1-4 heteroatoms independently selected from nitrogen, oxygen, or sulfur; each of which is optionally substituted; or Z is -O-, -S-, -SO 2 -, -SO-, -C -, -CO 2 -, -C N -, -OC N -, -NRC -, -NRC N -, -NRSO 2 -, or-N -; W is CR or N; each R is independently hydrogen, C 1-6 aliphatic, C 3-10 aryl, a 3-8 membered saturated or partially unsaturated carbocyclic ring, a 3-7 membered heterocylic ring having 1-4 heteroatoms independently selected from nitrogen, oxygen, or sulfur, or a 5-6 membered monocyclic heteroaryl ring having 1-4 heteroatoms independently selected from nitrogen, oxygen, or sulfur; each of which is optionally substituted; or two R groups on the same atom are taken together with the atom to which they are attached to form a C 3-10 aryl, a 3-8 membered saturated or partially unsaturated carbocyclic ring, a 3-7 membered heterocylic ring having 1-4 heteroatoms independently selected from nitrogen, oxygen, or sulfur, or a 5-6 membered monocyclic heteroaryl ring having 1-4 heteroatoms independently selected from nitrogen, oxygen, or sulfur; each of which is optionally substituted; each R 1 is independently -R, halogen, -OR, -SR, -CN, -NO 2, -SO 2 R, -SOR, -C R, -CO 2 R, -C N 2, -NRC R, -NRC N 2, -NRSO 2 R, or -N 2; R 2 is -R, halogen, -OR, -SR, -CN, -NO 2, -SO 2 R, -SOR, -C R, -CO 2 R, -C N 2,-NRC R, -NRC N 2, -NRSO 2 R, or -N 2; R 4 is -R, halogen, -OR, -SR, -CN, -NO 2, -SO 2 R, -SOR, -C R, -CO 2 R, -C N 2,-NRC R, -NRC N 2, -NRSO 2 R, or -N 2; each m is independently 1 or 2; and n is 0, 1, 2, 3, 4, or 5.