Background: Cholangiocarcinoma (CCA) is the most common malignancy of the biliary tract with a dismal prognosis. Increasing evidence suggests that tumor microenvironment (TME) is closely associated with cancer prognosis. However, the prognostic signature for CCA based on TME has not yet been reported. This study aimed to develop a TME-related prognostic signature for accurately predicting the prognosis of patients with CCA. Methods: Based on the TCGA database, we calculated the stromal and immune scores using the ESTIMATE algorithm to assess TME in stromal and immune cells derived from CCA. TME-related differentially expressed genes were identified, followed by functional enrichment analysis and PPI network analysis. Univariate Cox regression analysis, Lasso Cox regression model and multivariable Cox regression analysis were performed to identify and construct the TME-related prognostic gene signature. Gene Set Enrichment Analyses (GSEA) was performed to further investigate the potential molecular mechanisms. The correlations between the risk scores and tumor infiltration immune cells were analyzed using Tumor Immune Estimation Resource (TIMER) database. Results: A total of 784 TME-related differentially expressed genes (DEGs) were identified, which were mainly enriched in immune-related processes and pathways. Among these TME-related DEGs, A novel two‑gene signature (including GAD1 and KLRB1) was constructed for CCA prognosis prediction. The AUC of the prognostic model for predicting the survival of patients at 1-, 2-, and 3- years was 0.811, 0.772, and 0.844, respectively. Cox regression analysis showed that the two‑gene signature was an independent prognostic factor. Based on the risk scores of the prognostic model, CCA patients were divided into high- and low-risk groups, and patients with high-risk score had shorter survival time than those with low-risk score. Furthermore, we found that the risk scores were negatively correlated with TME-scores and the number of several tumor infiltration immune cells, including B cells and CD4+ T cells. Conclusion: Our study established a novel TME-related gene signature to predict the prognosis of patients with CCA. This might provide a new understanding of the potential relationship between TME and CCA prognosis, and serve as a prognosis stratification tool for guiding personalized treatment of CCA patients.