Native macOS CLI tool for Swift codebase intelligence β find critical files, generate dependency graphs, learning paths, and detailed reports.
Built 100% in Swift using Apple-native technologies. Fully offline. No network required. No telemetry. No accounts.
AI-powered features (natural-language Q&A) are available as a separate opt-in β see AI Integration (Opt-In).
cd SwiftCodeContext # Projects under 200K lines β just run directly swift run codecontext analyze ~/path/to/your/project --open # Large projects (200K+ lines) β release build is 5β10Γ faster swift build -c release .build/release/codecontext analyze ~/path/to/your/project --open--open opens the HTML report in Safari.
Every core feature runs entirely on your machine:
- Source parsing β Apple's native SwiftSyntax, no external services
- Dependency graphs & PageRank β computed locally
- Git history analysis β reads your local
.gitdirectory - HTML report generation β self-contained, no CDN links, no external assets
- Caching β actor-based file cache stored on disk
Your code never leaves your machine unless you explicitly enable the optional AI integration and send a query.
cd SwiftCodeContext # Build swift build # Analyze a Swift project swift run codecontext analyze /path/to/your/swift/project # See all commands swift run codecontext --helpcd SwiftCodeContext # Debug build (fast compilation) swift build # Run directly swift run codecontext analyze ~/Projects/MyApp # Release build (optimized, ~3Γ faster runtime) swift build -c release # The binary is at: .build/release/codecontextswift build -c release sudo cp .build/release/codecontext /usr/local/bin/ # Now use from anywhere: codecontext analyze ~/Projects/MyApp codecontext evolution --months 12swift build -c release && sudo cp .build/release/codecontext /usr/local/bin/ && echo "β
installed"open Package.swiftIn Xcode:
- Select the
codecontextscheme - Edit Scheme β Run β Arguments β add:
analyze /path/to/your/project - βR to build and run
# Analyze current directory codecontext analyze # Analyze specific path codecontext analyze ~/Projects/MyApp # With options codecontext analyze ~/Projects/MyApp --no-cache --verbose --open# Default: 6 months back, 30-day intervals codecontext evolution # Custom range codecontext evolution --months 12 --interval 7codecontext init # Creates .codecontext.json with sensible defaultsThe generated HTML report is a single self-contained file β open it anywhere, share it, archive it. No internet connection needed to view it.
-
Summary β total files, lines of code, declarations by type (structs, classes, enums, protocols, actors), and package count
-
Team Contribution Map β developer activity tracking with files modified, commit counts, and first/last change dates
-
Dependencies & Imports β comprehensive classification into Apple frameworks, external dependencies, and local Swift packages with interactive tag clouds
-
Assets β media resource analysis showing total size, file count by type, and top 3 heaviest files with their individual sizes
-
Hot Zones β files with the highest PageRank scores, identifying the most connected and architecturally significant code. Each entry includes clickable module badges and inline documentation previews
-
Module Insights β package penetration analysis showing which modules are imported by the most other packages (foundational dependencies), plus quality metrics including TODO/FIXME density and technical debt indicators
-
Longest Functions β ranked list of functions by line count, with clickable module badges and quick navigation to potential refactoring candidates
-
Packages & Modules β detailed breakdown of each local Swift package:
- Complete file inventory sorted by lines of code
- Declaration statistics by type (classes, structs, enums, protocols, actors, extensions)
- Interactive force-directed dependency graph per package, colored by declaration type (π΅ classes, π’ structs, π‘ enums, π΄ actors)
- File-level annotations with inline documentation previews
- Precise line counts and declaration tags for every file
- Package-level metrics including total files, lines, and declaration distribution
Create .codecontext.json in your project root (or run codecontext init):
{ "excludePaths": [".git", ".build", "DerivedData", "Pods", "Carthage"], "maxFilesAnalyze": 5000, "gitCommitLimit": 1000, "enableCache": true, "enableParallel": true, "hotspotCount": 15, "fileExtensions": ["swift"] }All options above are offline. No network configuration needed.
This is entirely optional. Every feature described above works without it.
If you want to ask natural-language questions about your codebase, you can enable the AI module. This sends a context summary to an external LLM provider, so review your provider's data policies before enabling.
Add an ai block to your .codecontext.json:
{ "ai": { "enabled": false, "provider": "anthropic", "apiKey": "", "model": "claude-sonnet-4-20250514" } }| Provider | provider | Model examples |
|---|---|---|
| Anthropic Claude | "anthropic" | claude-sonnet-4-20250514 |
| Google Gemini | "gemini" | gemini-2.5-flash |
codecontext ask "Where is the authentication logic?" codecontext ask "What would break if I refactored UserService?"When you run ask, a summary of your project structure and relevant code context is sent to the configured provider. Raw source files are not uploaded in full β the tool assembles a focused context window. No data is sent for any other command (analyze, evolution, init).
SwiftCodeContext/ βββ Package.swift βββ Sources/CodeContext/ β βββ CLI/ β β βββ CodeContextCLI.swift # @main entry point β β βββ AnalyzeCommand.swift # Main analysis command β β βββ AskCommand.swift # AI Q&A command (opt-in) β β βββ EvolutionCommand.swift # Temporal analysis β β βββ InitCommand.swift # Config initialization β βββ Core/ β β βββ AnalysisPipeline.swift # Shared pipeline logic β β βββ Config/ β β β βββ CodeContextConfig.swift # Config models + loader β β βββ Cache/ β β β βββ CacheManager.swift # Actor-based file cache β β βββ Parser/ β β β βββ ParsedFile.swift # Models + protocol β β β βββ SwiftParser.swift # Swift source parser β β β βββ ObjCParser.swift # ObjC header parser β β β βββ ParserFactory.swift # Parser dispatch β β β βββ ParallelParser.swift # Concurrent parsing β β βββ Scanner/ β β β βββ RepositoryScanner.swift # Directory walker β β β βββ GitAnalyzer.swift # Git history via Process β β βββ Graph/ β β β βββ DependencyGraph.swift # Graph + PageRank β β βββ Generator/ β β β βββ LearningPathGenerator.swift β β βββ Temporal/ β β β βββ TemporalAnalyzer.swift # Evolution tracking β β βββ AI/ β β β βββ AICodeAnalyzer.swift # URLSession-based AI (opt-in) β β βββ Exceptions/ β β βββ CodeContextError.swift β βββ Output/ β βββ ReportGenerator.swift # HTML report βββ Tests/CodeContextTests/ βββ CodeContextTests.swift swift test- macOS 13+ (Ventura or later)
- Xcode 15+ / Swift 5.9+
- git (comes with Xcode Command Line Tools)
- No internet connection required for core features
