The 26-year-old joined the Town on a one-year deal last summer after being released by AFC Wimbledon and has made five appearances so far, all in the Checkatrade Trophy, while pushing Marek Stech for a starting spot in Nathan Jones' side.
After signing his new deal at Kenilworth Road, the former Arsenal keeper said: "I'm delighted to extend my contract by another two years. When the gaffer approached me about extending it, I couldn't wait to get it done.
"I've really enjoyed my time here, even though I haven't played as much as I'd have liked. But it's one of those situations where I have to hold my hands up, Stechy has played so well. I have to bide my time and hopefully one day I'll be in that team, but I'm over the moon to extend my contract.
"I've enjoyed every single minute with the gaffer and working with Kev Dearden, who has been absolutely brilliant with us this year. Every day in training he works us hard with really good sessions. We get exactly what we need out of them, and I'm looking forward to working with him a lot more."
Shea travels up from his home in Islington on the train each day to work at The Brache, and he added: "I feel so settled here and that's one thing I'm really happy about. I've got a young family, so it's a great place to come every day. I can still live at home. I don't have to move anywhere, so all the boxes are ticked – it's perfect for me."
Boss Jones was delighted to extend the Londoner's contract.
"We've been really happy with James," said the Welshman. "We brought him in to push Marek because we believe we've got two number one keepers at the club, and he's done exactly that.
"He's been a little bit unfortunate that due to the form of Marek, his game time is limited, but he has developed as a goalkeeper.
"He's a great character and he's one that we feel whatever level we are at, he has the experience and quality to keep taking us forward, so we're delighted to extend his contract."
Congratulations on the new deal, James!