In this study, molecular simulation is utilized to explore the charge effect in COF membranes on separation performance. Three types of COF membranes with different functional groups (Tp-Tta-COOH, Tp-Tta-COO − and Tp-Tta-NH 3 + ) and thus different charges are designed. It is found that the positively charged membrane (Tp-Tta-NH 3 + ) shows higher ion selectivity in mixed Li + /Mg 2+ ion solution, compared with the negatively charged and neutral membranes. In Tp-Tta-NH 3 + membrane, the effective pore size is reduced by the secondary confinement effect of Cl − ions. The orderly arranged anions (Cl − ) reduce the actual pore size and generate the secondary confinement effect, which fortifies the pore-entrance sieving effect, and due to the large difference in hydration energies of Li + and Mg 2+ ions, the former is easier to dehydrate and enter the pore. The charge effect in Li + /Mg 2+ separation uncovered by molecular simulation is microscopically insightful toward the design of COF membranes and other organic framework membranes for high-performance ion separation. • Three types of COF membranes with positive, neutral, negative charges are constructed. • MD simulation is applied to elucidate Li + /Mg 2+ separation in COF membranes. • The positively charged COF membrane exhibits the highest selectivity. • The secondary confinement and differentiated dehydration provide high selectivity.