The hedgehog (Hh) signaling pathway plays a central role during embryonic development, and its aberrant activation has been implicated in the development and progression of several human cancers. Major efforts toward the identification of chemical modulators of the hedgehog pathway have yielded several antagonists of the GPCR-like smoothened receptor. In contrast, potent inhibitors of the sonic hedgehog/patched interaction, the most upstream event in ligand-induced activation of this signaling pathway, have been elusive. To address this gap, a genetically encoded cyclic peptide was designed based on the sonic hedgehog (Shh)-binding loop of hedgehog-interacting protein (HHIP) and subjected to multiple rounds of affinity maturation through the screening of macrocyclic peptide libraries produced in E. coli cells. Using this approach, an optimized macrocyclic peptide inhibitor (HL2-m5) was obtained that binds Shh with a KD of 170 nM, which corresponds to a 120-fold affinity improvement compared to the parent molecule. Importantly, HL2-m5 is able to effectively suppress Shh-mediated hedgehog signaling and Gli-controlled gene transcription in living cells (IC50 = 230 nM), providing the most potent inhibitor of the sonic hedgehog/patched interaction reported to date. This first-in-class macrocyclic peptide modulator of the hedgehog pathway is expected to provide a valuable probe for investigating and targeting ligand-dependent hedgehog pathway activation in cancer and other pathologies. This work also introduces a general strategy for the development of cyclopeptide inhibitors of protein-protein interactions.