# How can I prevent org-mode reading agenda files when started?

My org-mode agenda files are on a remote machine, accessed via ssh using tramp. When org-mode starts it always reads this file, which is inconvenient as it makes opening any org file very slow. I would prefer for it to read the agenda files only when I actually look at the agenda. Is there a way to do this?

My .emacs currently sets the agenda location in this way:

  (setq org-agenda-files '("/-:somehost:somefile.org"))

• Perhaps you could have a generic local location for org-files on the host computer (which can be an empty directory or a directory with no org-files at all) and then modify the value for org-agenda-files when you do whatever it is that is meant to query off-site files. Sep 20, 2019 at 6:23
• Ah, I see what you mean. The org-files that I need to see the agenda from could set org-agenda-files. Yes! Sep 20, 2019 at 12:39
• If just loading org-mode causes Emacs to try and read your agenda file and hence open a Tramp connection, then I'd recommend you report it as a bug: M-x report-emacs-bug. It's normal that it fetches the file when you want to view your agenda, but not when you're looking at some unrelated org-mode file. Sep 20, 2019 at 18:23

I'd use use-package, treat org-agenda as separate package, defer its loading and declare org-agenda-files there. It should load the variable just before the agenda is loaded.
Alternatively I guess that you can exclude that file from your init file, and use add-to-list in org-agenda-mode-hookor any other convenient place you'll call before loading agenda-mode. This way will allow you to set conditional statements conveniently.
The solution I settled on was to remove the setting for org-agenda-files from my .emacs and instead to set org-agenda-files within some file local variables in the org-mode files that were actually relevant to the agenda. i.e. a block of code like this at the end of those files:
# Local Variables: