Abstract Postoperative tumor recurrence and metastases often lead to cancer treatment failure. Here, we develop a local embedded photodynamic immunomodulatory DNA hydrogel for early warning and inhibition of postoperative tumor recurrence. The DNA hydrogel contains PDL1 aptamers that capture and enrich in situ relapsed tumor cells, increasing local ATP concentration to provide a timely warning signal. When a positive signal is detected, local laser irradiation is performed to trigger photodynamic therapy to kill captured tumor cells and release tumor-associated antigens (TAA). In addition, reactive oxygen species break DNA strands in the hydrogel to release encoded PDL1 aptamer and CpG, which together with TAA promote sufficient systemic antitumor immunotherapy. In a murine model where tumor cells are injected at the surgical site to mimic tumor recurrence, we find that the hydrogel system enables timely detection of tumor recurrence by enriching relapsed tumor cells to increase local ATP concentrations. As a result, a significant inhibitory effect of approximately 88.1% on recurrent tumors and effectively suppressing metastasis, offering a promising avenue for timely and effective treatment of postoperative tumor recurrence.