A Ghost in the Machine is a crime novel written by English writer Caroline Graham and first published by Headline in 2004. The story follows Chief Inspector Tom Barnaby investigating the case of the death of an antique collector. It is the seventh and final volume in Graham's Chief Inspector Barnaby series and preceded by A Place of Safety.
Unlike the majority of Graham's previous Chief Inspector Barnaby novels, A Ghost in the Machine was not adapted for the television series Midsomer Murders. According to Graham, this was because Chief Inspector Barnaby and Sergeant Troy are absent through the first half of the novel.