PurposeMost Hepatocellular carcinoma (HCC) patients are in advanced or metastatic stage at the time of diagnosis. Prognosis for advanced HCC patients is dismal. This study was based on our previous microarray results, and aimed to explore the promising diagnostic and prognostic markers for advanced HCC by focusing on the important function of KLF2.MethodsThe Cancer Genome Atlas (TCGA), Cancer Genome Consortium database (ICGC), and the Gene Expression Comprehensive Database (GEO) provided the raw data of this study research. The cBioPortal platform, CeDR Atlas platform, and the Human Protein Atlas (HPA) website were applied to analyze the mutational landscape and single-cell sequencing data of KLF2. Basing on the results of single-cell sequencing analyses, we further explored the molecular mechanism of KLF2 regulation in the fibrosis and immune infiltration of HCC.ResultsDecreased KLF2 expression was discovered to be mainly regulated by hypermethylation, and indicated a poor prognosis of HCC. Single-cell level expression analyses revealed KLF2 was highly expressed in immune cells and fibroblasts. The function enrichment analysis of KLF2 targets indicated the crucial association between KLF2 and tumor matrix. 33-genes related with cancer associated fibroblasts (CAFs) were collected to identify the significant association of KLF2 with fibrosis. And SPP1 was validated as a promising prognostic and diagnostic marker for advanced HCC patients. CXCR6 CD8+T cells were noted as a predominant proportion in the immune microenvironment, and T cell receptor CD3D was discovered to be a potential therapeutic biomarker for HCC immunotherapy.ConclusionThis study identified that KLF2 is an important factor promoting HCC progression by affecting the fibrosis and immune infiltration, highlighting its great potential as a novel prognostic biomarker for advanced HCC.Supplementary InformationThe online version contains supplementary material available at 10.1186/s12859-023-05391-0.