How to add directory to cook programatically?

I have not actually done this myself but I have seen plugins referencing the needed assets during their StartupModule.

From LoadingScreen plugin:

void FLoadingScreenModule::StartupModule()
{
[...]
		// Load for cooker reference
		const ULoadingScreenSettings* Settings = GetDefault<ULoadingScreenSettings>();
		for ( const FStringAssetReference& Ref : Settings->StartupScreen.Images )
		{
			Ref.TryLoad();
		}
[...]

https://github.com/ue4plugins/LoadingScreen/blob/master/Source/LoadingScreen/Private/LoadingScreenModule.cpp

Could be something you might be interested in.