  Fault-tolerant syndrome extraction is a key ingredient in implementing
fault-tolerant quantum computations. While conventional methods use a number of
extra qubits linear in the weight of the syndrome, several improvements have
been introduced using flag gadgets. In this work, we develop a framework to
design flag gadgets using classical codes. Using this framework we show how to
perform fault-tolerant syndrome extraction for any stabilizer code with
arbitrary distance using exponentially fewer qubits than conventional methods
when qubit measurement and reset are relatively slow compared to a round of
error correction. We further take advantage of the saving provided by our
construction to fault-tolerantly measure multiple stabilizers using a single
gadget, and show that it maintains the same exponential advantage when it is
used to fault-tolerantly extract the syndrome of quantum LDPC codes. Using the
developed framework we perform computer-assisted search to find several small
examples where our constructions reduce the number of qubits required. These
small examples may be relevant to near-term experiments on small-scale quantum
computers.
