This file provides guidance to Claude Code (or any AI assistant) working on this codebase.
Before making ANY code changes, run codemap to understand the codebase structure:
codemap --deps --json .Or for specific file context:
codemap --deps --json . | jq '.files[] | select(.path | contains("FileName"))'This project is built around codemap integration - the LLM tools use it internally. You should too.
XcodeLLMToolchain is an open-source crash and memory analysis toolkit using Apple's Foundation Models (macOS 26+). It runs entirely on-device via the Neural Engine - no cloud, no API keys.
┌─────────────────────────────────────────────────────────────┐
│ XCODE LLM TOOLCHAIN │
├─────────────────────────────────────────────────────────────┤
│ LLDB Scripts (Python) CLI (Swift) │
│ ├── explain_here └── xcode-llm │
│ ├── crash_explain │ │
│ └── memory_explain ▼ │
│ │ ┌─────────────────────────────┐ │
│ └────────────► │ XcodeLLMCore │ │
│ │ @Generable types │ │
│ │ Tool calling (codemap) │ │
│ └────────────┬────────────────┘ │
│ ▼ │
│ ┌─────────────────────────────┐ │
│ │ Apple Foundation Models │ │
│ │ On-device • Private │ │
│ └─────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
| Path | Purpose |
|---|---|
Sources/XcodeLLMCore/XcodeLLMEngine.swift |
Core LLM engine with structured output |
Sources/XcodeLLMCore/CrashExplanation.swift |
@Generable types and Instructions |
Sources/XcodeLLMCore/Tools/CodeMapTool.swift |
Tool for LLM to query codemap |
Sources/XcodeLLMCore/Tools/ReadSourceTool.swift |
Tool for LLM to read source files |
Sources/XcodeLLM/Entry.swift |
CLI entry point |
lldb/plugin.py |
LLDB command registration |
lldb/capture_lib/commands.py |
crash_explain, memory_explain, explain_here |
lldb/capture_lib/analysis.py |
Crash data extraction from LLDB |
# Build everything
swift build
# Build release
swift build -c release
# Run tests
swift test
# Run CLI
.build/debug/xcode-llm --help
# Test with crash suite
.build/debug/swift-crash-suite force_unwrap- Foundation Models (macOS 26): Apple's on-device 3B LLM
- @Generable macro: Structured output - model must return valid types
- @Guide descriptions: Tell the model what each field means
- Tool calling: Model can invoke codemap and read source files
- Instructions: System prompts for consistent behavior
@Generable
public struct CrashExplanation {
@Guide(description: "Category of crash", .anyOf(["null_pointer", "force_unwrap_nil", ...]))
public var crashType: String
}public final class CodeMapTool: Tool {
public let name = "get_dependencies"
public let description = "Get dependency info for a file..."
@Generable
public struct Arguments {
@Guide(description: "Path to project root")
var projectPath: String
}
public func call(arguments: Arguments) async throws -> String { ... }
}let session = LanguageModelSession(
tools: [ReadSourceTool(), CodeMapTool()],
instructions: makeCrashInstructions()
)
let response = try await session.respond(
to: "Analyze crash...",
generating: CrashExplanation.self
)The Python scripts in lldb/ capture crash context and pipe JSON to the Swift CLI:
LLDB → capture crash data → JSON → xcode-llm CLI → Foundation Models → structured explanation
- Add to
CrashTypeenum inGeneratedCrash.swift - Add to
crashTypeanyOf list inCrashExplanation.swift - Add test case in
SwiftCrashSuite/main.swift
- Create
Sources/XcodeLLMCore/Tools/NewTool.swift - Implement
Toolprotocol with@GenerableArguments - Add to tools array in
XcodeLLMEngine.init()
- Add function in
lldb/capture_lib/commands.py - Register in
lldb/plugin.py__lldb_init_module
# Unit tests
swift test
# Manual testing with crash suite
lldb .build/debug/swift-crash-suite -- force_unwrap
(lldb) run
(lldb) crash_explain
# Battle mode (generate crash, then explain)
.build/debug/xcode-llm --battle- macOS 26 (Tahoe) or later
- Apple Silicon Mac
- Xcode 26+
- codemap (optional but recommended):
brew install jordancoin/tap/codemap
- Keep prompts minimal - let @Guide descriptions do the work
- One sentence per @Guide description
- Prefer structured output over free-form text
- Trim data to fit token limits (Foundation Models has ~32k context)
- User code frames are more valuable than system frames