Despite the fact that the genetic code is known to vary between organisms in rare cases, it is believed that in the lifetime of a single cell the code is stable. We found Acetohalobium arabaticum cells grown on pyruvate genetically encode 20 amino acids, but in the presence of trimethylamine (TMA), A. arabaticum dynamically expands its genetic code to 21 amino acids including pyrrolysine (Pyl). A. arabaticum is the only known organism that modulates the size of its genetic code in response to its environment and energy source. The gene cassette pylTSBCD, required to biosynthesize and genetically encode UAG codons as Pyl, is present in the genomes of 24 anaerobic archaea and bacteria. Unlike archaeal Pyl-decoding organisms that constitutively encode Pyl, we observed that A. arabaticum controls Pyl encoding by down-regulating transcription of the entire Pyl operon under growth conditions lacking TMA, to the point where no detectable Pyl-tRNAPyl is made in vivo. Pyl-decoding archaea adapted to an expanded genetic code by minimizing TAG codon frequency to typically ∼5% of ORFs, whereas Pyl-decoding bacteria (∼20% of ORFs contain in-frame TAGs) regulate Pyl-tRNAPyl formation and translation of UAG by transcriptional deactivation of genes in the Pyl operon. We further demonstrate that Pyl encoding occurs in a bacterium that naturally encodes the Pyl operon, and identified Pyl residues by mass spectrometry in A. arabaticum proteins including two methylamine methyltransferases.