Over revving

when I put the clutch in, the engine revs up to about 4,000. It will stay there sometimes for 30 seconds before coming down to about 1600 (which seems to be the idle rpm lately) and other times it will only stay up for a couple of seconds. There are also times that this does not happen at all. This only happens when the engine is hot.

Have you checked the throttle linkage to see if something is sticking?

What year, which engine, and how many miles?

2000 SVT 2.4 V6 with 108K miles.
The linkage is not sticking nor are the butter-fly valves on the throttle body.