Cyclic dinucleotides (CDNs) play central roles in bacterial pathogenesis and innate immunity. The mammalian enzyme cGAS synthesizes a unique cyclic dinucleotide (cGAMP) containing a 2ʹ–5ʹ phosphodiester linkage essential for optimal immune stimulation, but the molecular basis for linkage specificity is unknown. Here, we show that the Vibrio cholerae pathogenicity factor DncV is a prokaryotic cGAS-like enzyme whose activity provides a mechanistic rationale for the unique ability of cGAS to produce 2ʹ–5ʹ cGAMP. Three high-resolution crystal structures show that DncV and human cGAS generate CDNs in sequential reactions that proceed in opposing directions. We explain 2ʹ and 3ʹ linkage specificity and test this model by reprogramming the human cGAS active site to produce 3ʹ–5ʹ cGAMP, leading to selective stimulation of alternative STING adaptor alleles in cells. These results demonstrate mechanistic homology between bacterial signaling and mammalian innate immunity and explain how active site configuration controls linkage chemistry for pathway-specific signaling.