If you want to introduce a file type and that file type can only be identified by examining the contents of such files then you'll need to add appropriate logic to a file named scripts.vim.
But first, let's take a step back and look at the broader picture.
File type detection is enabled with the command :filetype on (this is usually added to your vimrc file)....
In the end, the comments above were very helpful in narrowing down the problem - thanks, everyone! I've resolved it now, and the filetype is only set once. To summarize, there were several issues here:
The problem only affected Markdown files, which I didn't originally realise - sorry for not being more thorough in my original problem determination. This ...
You can create $HOME/.vim/scripts.vim of your own, as $VIMRUNTIME/filetype.vim will source it by executing :runtime! scripts.vim if needed. It's enough to put only these lines:
if getline(1) =~# '^Client:.'
Note that .* at the end of a pattern does nothing (always matches).
Yes, you should be able to set the filetype based on the contents of the file.
If you add a script to the ftdetect directory, this script should set up a new autocmd to trigger when a file of a specific extension or file name pattern (or * if any file name is possible) is opened and then set the appropriate filetype there.
The autocmd can then set the ...