A Swift Package Manager CLI that helps you interact with Xcode's IndexStoreDB. It provides two main features:
- Search: Locates every file in your Xcode DerivedData index referencing a chosen symbol
- RemoveUTI: Automatically removes unnecessary
@testable importstatements from your test files
It resolves the correct IndexStore path automatically, queries Apple's IndexStoreDB, and uses Swift concurrency to scan multiple files in parallel, keeping operations fast even for large workspaces.
When working with multiple modules and moving models between them, finding all references to add missing imports is tedious. Using this CLI to feed file lists to AI agents dramatically improves refactoring results. Just tell your AI agent to execute the script below and add missing import statements to all files
swiftfindrefs -p SomeProject -n SomeSymbolName -t SomeSymbolType | while read file; do
if ! grep -q "import SomeModule" "$file"; then
echo "$file"
fi
doneAfter refactoring code to make symbols public, you may have leftover @testable import statements in your test files that are no longer needed. This CLI can automatically detect and remove them, keeping your test files clean.
swiftfindrefs rmUTI -p SomeProjectbrew tap michaelversus/SwiftFindRefs https://github.com/michaelversus/SwiftFindRefs.git
brew install swiftfindrefs-p, --projectNamehelps the tool infer the right DerivedData folder when you do not passderivedDataPath.-d, --derivedDataPathpoints directly to a DerivedData (or IndexStoreDB) directory and skips discovery.-v, --verboseenables verbose output for diagnostic purposes (flag, no value required).
-n, --symbolNameis the symbol you want to inspect. This is required.-t, --symbolTypenarrows matches to a specific kind (e.g.class,function).
--excludeCompilationConditionalsexcludes@testable importstatements inside#if/#elseif/#else/#endifblocks from analysis (useful for multi-target apps).
swiftfindrefs \
--projectName MyApp \
--symbolName SelectionViewController \
--symbolType classSample output:
🔍 Searching for references to symbol 'SelectionViewController' of type 'class'
✅ Found 5 references:
/Users/me/MyApp/Sources/UI/SelectionViewController.swift
/Users/me/MyApp/Tests/SelectionViewControllerTests.swift
...
swiftfindrefs removeUnnecessaryTestableImports \
--projectName MyApp \
--verbose \
--excludeCompilationConditionalsOr use the shorter alias:
swiftfindrefs rmUTI \
--projectName MyApp \
--verbose \
--excludeCompilationConditionalsSample output:
DerivedData path: /Users/me/Library/Developer/Xcode/DerivedData/MyApp-...
IndexStoreDB path: /Users/me/Library/Developer/Xcode/DerivedData/MyApp-.../Index.noindex/DataStore/IndexStoreDB
Planning to remove unnecessary @testable imports from 3 files.
Removed unnecessary @testable imports from 3 files.
✅ Updated 3 files
Updated files:
/Users/me/MyApp/Tests/SomeTests.swift
/Users/me/MyApp/Tests/OtherTests.swift
...
- Derived data resolution –
DerivedDataLocatoruses the provided path or infers the newestProjectName-*folder under~/Library/Developer/Xcode/DerivedData. - Index routing –
DerivedDataPathsensures the path points intoIndex.noindex/DataStore/IndexStoreDBso we can open the index without extra setup. - Symbol querying – Queries IndexStoreDB for all occurrences of the specified symbol, filtering by type if provided.
- Output formatting – Paths are normalized, deduplicated, and printed once for easier scripting.
- Index analysis – Scans all units in the IndexStoreDB to identify files with
@testable importstatements. - Symbol analysis – For each
@testable import, checks if any referenced symbols from that module are actually public (and thus don't require@testable). - File rewriting – Removes unnecessary
@testableimports from files, preserving other imports and code structure. - Performance – Uses async/await and parallel processing to handle large codebases efficiently. Files are read lazily only when needed, and units are indexed by module to avoid O(n²) scans.
This repository includes an OpenSkills-compatible agent skill located in swiftfindrefs/.
It teaches AI coding agents to use IndexStore-based reference discovery via swiftfindrefs
instead of unreliable text search.
npm i -g openskillsopenskills install michaelversus/SwiftFindRefsopenskills syncUse the swiftfindrefs skill to find all references to SelectionViewController (class) and add
import UIComponents only where missing.
The package uses the Swift Testing framework (swift test) with mocks for filesystem and derived-data resolution. Tests cover locator edge cases, path building, and index error handling.
Issues and pull requests are welcome. Please run swift test before submitting and include coverage for new behaviors.
SwiftFindRefs relies on MobileNativeFoundation/swift-index-store for direct IndexStore access.
Swift, the Swift logo, and Xcode are trademarks of Apple Inc., registered in the U.S. and other countries.