BackgroundThe lack of effective and accurate predictive indicators remains a major bottleneck for the improvement of the prognosis of patients with hepatitis B virus (HBV)-related hepatocellular carcinoma (HCC). Hepatitis B virus X (HBx) has been widely suggested as a critical pathogenic protein for HBV-driven liver carcinogenesis, while tumor-associated macrophage (TAM) infiltration is also closely related to the tumorigenesis and progression of HCC. However, few studies have determined whether combining HBx expression with TAM populations could increase the accuracy of prognostic prediction for HBV-related HCC.MethodsThe study cohort enrolling 251 patients with HBV-related HCC was randomly split into a training and a validation group (ratio 1:1). The expression levels of HBx and TAM marker CD68 in HCC samples were detected by immunohistochemistry. Kaplan–Meier curves, Cox regression and Harrell’s concordance index (C-index) analysis were conducted to evaluate the prognostic significance of these indicators alone or in combination.ResultsThe expression level of HBx was strongly correlated with CD68+TAM infiltration in HCC tissues. Elevated HBx or CD68 expression indicated poorer overall survival (OS) and progression-free survival (PFS) after hepatectomy, and both of them were independent risk factors for postoperative survival. Meanwhile, patients with both high HBx and CD68 levels had worst clinical outcomes. Moreover, integrating HBx and CD68 expression with clinical indicators (tumor size and micro-vascular invasion) showed the best prognostic potential with highest C-index value for survival predictivity, and this proposed model also performed better than several conventional classifications of HCC.ConclusionCombining the expression of intratumoral HBx, CD68+TAM population and clinical variables could enable better prognostication for HBV-related HCC after hepatectomy, thus providing novel insights into developing more effective clinical prediction model based on both molecular phenotypes and tumor-immune microenvironment.Supplementary InformationThe online version contains supplementary material available at 10.1186/s12885-023-11027-6.