Some long noncoding RNAs (ncRNAs) transcribed by RNA polymerase II (RNAPII) are retained on chromatin, where they regulate RNAi and chromatin structure. The molecular basis of this retention remains unknown. We show that in fission yeast serine 7 (Ser7) of the C-terminal domain (CTD) of RNAPII is required for efficient siRNA generation for RNAi-dependent heterochromatin formation. Surprisingly, Ser7 facilitates chromatin retention of nascent heterochromatic RNAs (hRNAs). Chromatin retention of hRNAs and siRNA generation requires both Ser7 and an RNA-binding activity of the chromodomain of Chp1, a subunit of the RNA-induced transcriptional silencing (RITS) complex. Furthermore, RITS associates with RNAPII in a Ser7-dependent manner. We propose that Ser7 promotes cotranscriptional chromatin retention of hRNA by recruiting the RNA-chromatin connector protein Chp1, which facilitates RNAi-dependent heterochromatin formation. Our findings reveal a function of the CTD code: linking ncRNA transcription to RNAi for heterochromatin formation.