Subaru forester revving

I have a 2003 subaru forester that occasionally revs high for no apparent reason. If we’ve been driving around town, and come to a stop i.e. when the clutch is depressed, it will rev and gets worse and worse each time. Could this be something to do with a faulty coolant temp. sensor? Or any other suggestions? I should mention that after we’ve been driving on the highway i.e. non-stop and go driving, it doesn’t seem to do it.

Is your Check engine light on and the code is for faulty coolant temp sensor?

If the answer is yes the items are directly correlated. When your engine is cold via reading from the coolant temp sensor the computer revs your engine faster until warm based on that (faulty) temp sensor.

Check engine light has never come on. Any other ideas what could cause this?