Used when someone acts without restriction, does something at their own discretion, or has unrestricted access to something.
See also: 自由
どうぞ自由に使ってください。
Please feel free to use it.
彼は自由に意見を述べた。
He freely expressed his opinion.
自由に is the general word for doing something freely or without restriction, while 気の向くままに specifically emphasizes drifting along with one's mood at the moment.
Adverbial form of 自由 (freedom), which is a Sino-Japanese word from Middle Chinese 自由 (dzijH yuw).