If I think about leaving and immediately feel better and calmer, that's a sign for me.
What I do then is try to figure out why I feel like that and see if it can't be fixed in another way.
I usually do that by thinking about my reasons for staying vs leaving, once I even did it on a sheet of paper where I drew 3 columns with the headlines Reasons for Staying, Concerns, and Reasons for Leaving (the order in which you write them can be an indicator too.) If I have nothing in Reasons for Leaving and a manageable number in Concerns I stay and try to work them out. If I have even one thing in Reasons for Leaving I start keeping my eyes open for new opportunities. If I have more I do it more urgently.
The reasons can be anything e.g. not liking coworkers (never had that but would be a reason for leaving for me), nice offices, bad code and we're not fixing it, stagnating as a developer, not enough resources to develop good software etc.
I think it's important also to think about why things turned out the way they did. Was there a reason why we didn't do things right? Why didn't I like the coworkers? Could I have communicated better or differently? What will I do differently on my next job? Also, what did I do well? What have I learned?
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.