Accurate prediction of peritoneal recurrence for gastric cancer (GC) is crucial in clinic. The collagen alterations in tumor microenvironment affect the migration and treatment response of cancer cells. Herein, we proposed multitask machine learning-based tumor-associated collagen signatures (TACS), which are composed of quantitative collagen features derived from multiphoton imaging, to simultaneously predict peritoneal recurrence (TACSPR) and disease-free survival (TACSDFS). Among 713 consecutive patients, with 275 in training cohort, 222 patients in internal validation cohort, and 216 patients in external validation cohort, we developed and validated a multitask machine learning model for simultaneously predicting peritoneal recurrence (TACSPR) and disease-free survival (TACSDFS). The accuracy of the model for prediction of peritoneal recurrence and prognosis as well as its association with adjuvant chemotherapy were evaluated. The TACSPR and TACSDFS were independently associated with peritoneal recurrence and disease-free survival in three cohorts, respectively (all P < 0.001). The TACSPR demonstrated a favorable performance for peritoneal recurrence in all three cohorts. In addition, the TACSDFS also showed a satisfactory accuracy for disease-free survival among included patients. For stage II and III diseases, adjuvant chemotherapy improved the survival of patients with low TACSPR and low TACSDFS, or high TACSPR and low TACSDFS, or low TACSPR and high TACSDFS, but had no impact on patients with high TACSPR and high TACSDFS. The multitask machine learning model allows accurate prediction of peritoneal recurrence and survival for GC and could distinguish patients who might benefit from adjuvant chemotherapy.