Background & Aims: Intratumor molecular heterogeneity is a key feature of tumorigenesis and is linked to treatment failure and patient prognosis. Herein, we aimed to determine what drives tumor cell evolution by performing single-cell transcriptomic analysis. Methods: We analyzed 46 hepatocellular carcinoma (HCC) and intrahepatic cholangiocarcinoma (iCCA) biopsies from 37 patients enrolled in interventional studies at the NIH Clinical Center, with 16 biopsies collected before and after treatment from 7 patients. We developed a novel machine learning-based consensus clustering approach to track cellular states of 57,000 malignant and non-malignant cells including tumor cell transcriptome-based functional clonality analysis. We determined tumor cell relationships using RNA velocity and reverse graph embedding. We also studied longitudinal samples from 4 patients to determine tumor cellular state and its evolution. We validated our findings in bulk transcriptomic data from 488 patients with HCC and 277 patients with iCCA. Results: Using transcriptomic clusters as a surrogate for functional clonality, we observed an increase in tumor cell state heterogeneity which was tightly linked to patient prognosis. Furthermore, increased functional clonality was accompanied by a polarized immune cell landscape which included an increase in pre-exhausted T cells. We found that SPP1 expression was tightly associated with tumor cell evolution and microenvironmental reprogramming. Finally, we developed a user-friendly online interface as a knowledge base for a single-cell atlas of liver cancer. Conclusions: Our study offers insight into the collective behavior of tumor cell communities in liver cancer as well as potential drivers of tumor evolution in response to therapy. Lay summary: Intratumor molecular heterogeneity is a key feature of tumorigenesis that is linked to treatment failure and patient prognosis. In this study, we present a single-cell atlas of liver tumors from patients treated with immunotherapy and describe intratumoral cell states and their hierarchical relationship. We suggest osteopontin, encoded by the gene SPP1, as a candidate regulator of tumor evolution in response to treatment.