You use the phrase ‘Knee Jerk Reaction’ to indicate that you’ve made an automatic response to something.
Example of use: “I hauled off and hit him when he jumped out at me. I know he was playing a trick, but it was a knee jerk reaction!”
The expression ‘knee jerk reaction’ comes from medicine, where the jerking motion the knee makes when tapped is called the patellar reflex. First seen in print in 1877, it became common in the early 20th century.