Hi, thanks for publishing this library!
Here's a note from Claude. A patch from Claude did fix this issue for my setup.
Problem
HubApi.init() defaults downloadBase to ~/Documents/huggingface when no explicit path is provided:
// Sources/Hub/HubApi.swift:163-164
let documents = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
self.downloadBase = documents.appending(component: "huggingface")
On macOS Sequoia+, resolving .documentDirectory triggers a TCC consent prompt: "App would like to access files in your Documents folder."
This affects any app that links the Tokenizers module — even if the app never downloads from the Hub. The static let shared = HubApi() singleton is lazily initialized when Swift evaluates default parameters like hubApi: HubApi = .shared in AutoTokenizer.from(modelFolder:), which is enough to trigger the prompt.
Impact
- Apps that only use
Tokenizers for local model loading get an unexpected Documents folder permission prompt
- Users may deny the prompt, causing confusion
- The
downloadBase directory (~/Documents/huggingface) is never actually used in these cases
Suggested fix
Change the default downloadBase from .documentDirectory to a non-TCC-protected location. Options:
~/.cache/huggingface — matches Python huggingface_hub convention, matches swift-huggingface's CacheLocationProvider.defaultCacheDirectory() on non-sandboxed macOS
.applicationSupportDirectory — standard macOS app data location
.cachesDirectory (~/Library/Caches/) — simplest change but subject to system purging
Option 1 seems most consistent with the ecosystem. Any change would need migration consideration for existing users who have snapshots in ~/Documents/huggingface/.
Reproduction
- Create a macOS app that depends on
swift-transformers (Tokenizers product)
- Call
AutoTokenizer.from(modelFolder: someLocalPath) without passing hubApi:
- On macOS Sequoia+, the app shows a "Documents folder" TCC prompt on first run
Hi, thanks for publishing this library!
Here's a note from Claude. A patch from Claude did fix this issue for my setup.
Problem
HubApi.init()defaultsdownloadBaseto~/Documents/huggingfacewhen no explicit path is provided:On macOS Sequoia+, resolving
.documentDirectorytriggers a TCC consent prompt: "App would like to access files in your Documents folder."This affects any app that links the
Tokenizersmodule — even if the app never downloads from the Hub. Thestatic let shared = HubApi()singleton is lazily initialized when Swift evaluates default parameters likehubApi: HubApi = .sharedinAutoTokenizer.from(modelFolder:), which is enough to trigger the prompt.Impact
Tokenizersfor local model loading get an unexpected Documents folder permission promptdownloadBasedirectory (~/Documents/huggingface) is never actually used in these casesSuggested fix
Change the default
downloadBasefrom.documentDirectoryto a non-TCC-protected location. Options:~/.cache/huggingface— matches Pythonhuggingface_hubconvention, matchesswift-huggingface'sCacheLocationProvider.defaultCacheDirectory()on non-sandboxed macOS.applicationSupportDirectory— standard macOS app data location.cachesDirectory(~/Library/Caches/) — simplest change but subject to system purgingOption 1 seems most consistent with the ecosystem. Any change would need migration consideration for existing users who have snapshots in
~/Documents/huggingface/.Reproduction
swift-transformers(Tokenizers product)AutoTokenizer.from(modelFolder: someLocalPath)without passinghubApi: