The genetic code allows most amino acids a choice of optimal and nonoptimal codons. We report that synonymous codon choice is tuned to promote interaction of nascent polypeptides with the signal recognition particle (SRP), which assists in protein translocation across membranes. Cotranslational recognition by the SRP in vivo is enhanced when mRNAs contain nonoptimal codon clusters 35-40 codons downstream of the SRP-binding site, the distance that spans the ribosomal polypeptide exit tunnel. A local translation slowdown upon ribosomal exit of SRP-binding elements in mRNAs containing these nonoptimal codon clusters is supported experimentally by ribosome profiling analyses in yeast. Modulation of local elongation rates through codon choice appears to kinetically enhance recognition by ribosome-associated factors. We propose that cotranslational regulation of nascent-chain fate may be a general constraint shaping codon usage in the genome.