Suicide is a tremendous threat to global public health, and a large number of people who committed suicide suffered the pain of mental diseases, especially major depressive disorder (MDD). Previous study showed that ketamine could reduce suicidal ideation (SI), potentially by improving the impaired working memory (WM). The objective of current study was to illuminate the relationship between WM and SI in MDD with repeated ketamine treatment. MDD patients with SI (n = 59) and without SI (n = 37) completed six intravenous infusions of ketamine (0.5 mg/kg over 40 min) over 12 days (Day 1, 3, 5, 8, 10 and 12). The severity of depressive symptoms, SI and WM were assessed at baseline, day 13 and day 26. We found that WM was significantly improved after 6 ketamine infusions (F = 161.284, p = 0.009) in a linear mixed model. Correlation analysis showed that the improvement of depressive symptom was significantly associated with WM at baseline (r =  − 0.265, p = 0.042) and the reduction in SSI-part I was related to the change of WM (r = 0.276, p = 0.034) in the MDD patients with SI. Furthermore, Logistic regression analysis showed that improvement in WM might predict the anti-SI response of ketamine. Our findings suggest that the improvement of working memory may partly account for the anti-SI effect of ketamine, and intervention of improving working memory function may be capable of reducing suicidal ideation.