The genesis of the novel was in two Doctor Who serials written by Adams, City of Death (in which an alien tries to change history at the cost of erasing humanity from existence) and in particular the cancelled serial Shada, which first introduces a Cambridge professor called Chronotis who is hundreds of years old. He has been living and working at a Cambridge college for centuries, apparently attracting no attention (noting with appreciation that the porters are very discreet). In Shada, Chronotis's longevity is due to him being a Time Lord, and his time machine is an early model TARDIS. These trademark elements from Doctor Who were removed by Adams for Dirk Gently. Shada was cancelled before completion due to a production strike and later released on VHS with Tom Baker narrating the unfilmed segments.[1]
A number of elements in the novel were inspired by Adams' time at university. For example, one plot thread involves moving a sofa which is irreversibly stuck on the staircase to Richard MacDuff's apartment; according to his simulations, not only is it impossible to remove it, but there is no way for it to have got into that position in the first place. In a similar incident that occurred while Douglas Adams attended St John's College, Cambridge, furniture was placed in the rooms overlooking the river in Third Court while the staircases were being refurbished. When the staircases were completed, it was discovered that the sofas could no longer be removed from the rooms, and the sofas remained in those rooms for several decades.
The South Bank Show revealed that Adams based Chronotis' rooms on the rooms he occupied in his third year at university. Likewise, Richard's room – filled with Macintosh computers and synthesisers – was based on Adams' own flat (visited and photographed by Hi-Fi Choice Magazine). The piece of music by Bach that is heard aboard the satellite is "Ach bleib bei uns, Herr Jesu Christ" from the cantata "Bleib bei uns, denn es will Abend werden", BWV 6 (also an organ chorale BWV 649). Adams stated that this was his personal "absolutely perfect" piece of music, and that he listened to it "over and over; drove my wife completely insane" while writing Dirk Gently's Holistic Detective Agency.[2]