How does it know?
Climbing beans twine anti-clockwise, as do most, but not all, climbing plants. The technical term for this is circumnutation, the name given by Darwin although he was not the first to note the phenomenon: it was surely recognised by plant lovers and growers way back.
The growing tip waves around in search of an object to fasten upon and when it does off it goes. But you can't make it twine in the opposite direction however hard you try.