We study commutation properties of subsets of right-angled Artin groups and trace monoids. We show that if Γ is any graph not containing a four-cycle without chords, then the group G(Γ) does not contain four elements whose commutation graph is a four-cycle; a consequence is that G(Γ) does not have a subgroup isomorphic to a direct product of non-abelian groups. We also obtain corresponding and more general results in the monoid case.