How does a circuit "know" the resistance?
It does NOT know in advance. 

When you connect a resistor to a battery, current starts to flow from zero and quickly ramps up until the voltage across the load (the resistor) matches the voltage of the battery. 

Voltage Across Resistor = Current x Resistance Value


When that happens the current can no longer grow. It balances out.

NOTHING ever happens instantaneously. But it happens so fast in human terms, it appears that way. 

Actually the math is a bit more complicated than that.. but it boils down to the same thing.