Prior to the start of his political career, Hanvey worked in the National Health Service for 25 years, latterly as Divisional Nurse Director for Rare Cancer at the Royal Marsden Hospital in London. After returning to Scotland, he was elected as a Scottish National Party councillor in the 2012 Scottish local elections for the Dunfermline Central ward in Fife. He became the SNP group leader on the council in 2017, but lost his seat three months later at the 2017 local elections. In October 2019, he was selected as the SNP candidate for the Kirkcaldy and Cowdenbeath constituency at the 2019 general election. Shortly after his selection, Hanvey was criticised by rival candidates and trans people within and outwith his party for voicing his opposition to the SNP's policy of support for transgender self-identification. Discussing proposed reforms to the Gender Recognition Act 2004, Hanvey said his "biggest concern is that there has been a growing attempt by MAP and paedophiles to add their initials to the LGBT+ group". Later in November, he was suspended from the party following allegations that he had made anti-Semitic social media posts, in which he compared Israeli treatment of the Palestinian people to the Holocaust and criticised the alleged influence of George Soros. Hanvey had SNP support for his campaign withdrawn but remained as the party candidate on the ballot paper, as the 14 November 2019 deadline for nominations had already passed. Hanvey supported the decision to suspend him and apologised for the offending posts, stating "Although I do not in anyway consider myself anti-Semitic, on reflection the language I used was, and this is clearly unacceptable." Hanvey was elected as MP for Kirkcaldy and Cowdenbeath at the 2019 general election, gaining the seat from the Labour Party's shadow Scottish secretary Lesley Laird by a narrow majority of 1,243 votes or 2.6%. He sat as an independent MP upon his election. It is thought to be the first time a challenger has undergone suspension as candidate from a party, won the seat and then sat as an independent. In March 2020, the SNP's conduct committee agreed to readmit Hanvey to the party in May 2020, on completion of an education course at a Holocaust centre. Hanvey announced that he had been re-admitted to sit as an SNP MP in June 2020.
Personal life
Hanvey is one of 45 openly LGBT MPs. He is a supporter of the controversial "LGB Alliance" group.