The simple task of walking up a sidewalk curb is actually a dynamic prediction task. The curb is a disturbance that could cause a loss of momentum if not anticipated and compensated for. It might be possible to adjust momentum sufficiently to ensure undisturbed time of arrival, but there are infinite possible ways to do so. Much of steady, level gait is determined by energy economy, which should be at least as important with terrain disturbances. It is, however, unknown whether economy also governs walking up a curb, and whether anticipation helps. Here we show that humans compensate with an anticipatory pattern of forward speed adjustments, predicted by a criterion of minimizing mechanical energy input. The strategy is mechanistically predicted by optimal control for a simple model of bipedal walking dynamics, with each leg's push-off work as input. Optimization predicts a tri-phasic trajectory of speed (and thus momentum) adjustments, including an anticipatory phase. In experiment, human subjects ascend an artificial curb with the predicted tri-phasic trajectory, which approximately conserves overall walking speed relative to undisturbed flat ground. The trajectory involves speeding up in a few steps before the curb, losing considerable momentum from ascending it, and then regaining speed in a few steps thereafter. Descending the curb entails a nearly opposite, but still anticipatory, speed fluctuation trajectory, in agreement with model predictions that speed fluctuation amplitudes should scale linearly with curb height. The fluctuation amplitudes also decrease slightly with faster average speeds, also as predicted by model. Humans can reason about the dynamics of walking to plan anticipatory and economical control, even with a sidewalk curb in the way.