BackgroundThe continuous emergence of novel SARS-CoV-2 variants with markedly increased transmissibility presents major challenges to the zero-COVID policy in China. It is critical to adjust aspects of the policy about non-pharmaceutical interventions (NPIs) by searching for and implementing more effective ways. We use a mathematical model to mimic the epidemic pattern of the Omicron variant in Shanghai to quantitatively show the control challenges and investigate the feasibility of different control patterns in avoiding other epidemic waves.MethodsWe initially construct a dynamic model with a core step-by-step release strategy to reveal its role in controlling the spread of COVID-19, including the city-based pattern and the district-based pattern. We used the least squares method and real reported case data to fit the model for Shanghai and its 16 districts, respectively. Optimal control theory was utilized to explore the quantitative and optimal solutions of the time-varying control strength (i.e., contact rate) to suppress the highly transmissible SARS-CoV-2 variants.ResultsThe necessary period for reaching the zero-COVID goal can be nearly 4 months, and the final epidemic size was 629,625 (95%CI: [608,049, 651,201]). By adopting the city-based pattern, 7 out of 16 strategies released the NPIs more or earlier than the baseline and ensured a zero-resurgence risk at the average cost of 10 to 129 more cases in June. By adopting the district-based pattern, a regional linked release can allow resumption of social activity to ~ 100% in the boundary-region group about 14 days earlier and allow people to flow between different districts without causing infection resurgence. Optimal solutions of the contact rate were obtained with various testing intensities, and higher diagnosis rate correlated with higher optimal contact rate while the number of daily reported cases remained almost unchanged.ConclusionsShanghai could have been bolder and more flexible in unleashing social activity than they did. The boundary-region group should be relaxed earlier and more attention should be paid to the centre-region group. With a more intensive testing strategy, people could return to normal life as much as possible but still ensure the epidemic was maintained at a relatively low level.Supplementary InformationThe online version contains supplementary material available at 10.1186/s12879-023-08316-7.