The best way to prevent this (but not eliminate) is to not apply power to the circuit while you are building it. If you are probing with a meter or scope, do it carefully so as not to cause wires to become loose; there shouldn’t be any loose or single-ended wires near a project while power is applied.
Finally, if probing, do your best to do so “one handed”; this gets you used to this method, so that in the future if you are working on a project with a high-voltage component, or line voltage, you don’t have any way to make a conductive path across your heart via the hands holding the probes.
Learning to operate the circuit without having single-ended wires floating around, or working on the circuit “live” will also help keep you alive when it comes to working with line-level circuitry or high voltage.
For obvious reasons as can be seen from the above, though, you shouldn’t probe your circuits “live”; hook the probes up where they are needed prior to applying power to the circuit, double check connections, then apply power and read your measurements. Then turn off the power, remove/reposition the probes, and continue.