Documentation
Hot Reload with AI
HotSwan works seamlessly with AI coding tools. When an AI assistant edits your Compose code, HotSwan detects the file change and pushes the update to your device instantly, giving you a live preview of every AI-generated change without rebuilding.
Overview
AI coding assistants like Claude Code and Cursor can modify your composable functions, tweak modifiers, update logic, and refactor code. With HotSwan running, every file save from these tools triggers a hot reload, so you see the result on your real device in real time. This turns AI-assisted development into a truly interactive feedback loop: you describe what you want, the AI writes the code, and your device shows the result within seconds.
Workflow
The workflow is simple: start HotSwan, open an AI tool, and let it edit your code. HotSwan handles the rest.
First, run your app with HotSwan enabled in Android Studio or IntelliJ. The plugin begins watching for file changes. Then use any AI coding tool to modify your Kotlin files. The tool saves the file, and HotSwan detects the change through periodic VFS (Virtual File System) refresh. HotSwan incrementally compiles only the changed classes, pushes them to your device, and triggers recomposition. The UI updates in seconds.
You do not need to configure anything special. HotSwan treats AI-generated file saves the same as manual saves. The only difference is that AI tools tend to save more frequently, which HotSwan handles through its built-in debouncing mechanism.
Supported tools
HotSwan works with any tool that edits and saves files on disk. It does not depend on IDE-specific APIs for change detection, so external tools are fully supported.
Claude Code is Anthropic's CLI tool that edits files directly on disk. HotSwan picks up every save via periodic file system refresh. Cursor's AI edits are saved through the editor, which triggers the IDE's file system events that HotSwan detects immediately. Any other AI tool that writes to your project files will also work: GitHub Copilot, Windsurf, Aider, or custom scripts. As long as the file is saved to disk, HotSwan will detect and reload the change.
What cannot be hot reloaded
Due to limitations of the Android Runtime, hot reload only works for changes within existing function bodies. The runtime can swap method implementations in place, but it cannot change a class's structure (its methods, fields, or inheritance hierarchy) at runtime.
This means the following types of AI-generated changes will not hot reload and will trigger a full incremental build instead:
- Adding or removing a composable function
- Adding new class properties or fields
- Changing a function's signature (parameters, return type)
- Adding or removing entire composable calls that generate new lambda classes
- Modifying class inheritance or interfaces
HotSwan detects these structural changes automatically and falls back to a full incremental build, so you never end up in a broken state. But the rebuild cycle is slower than a hot reload. To get the fastest feedback loop with AI tools, focus your prompts on modifying existing code rather than adding new structures. See Limitations for the complete list of unsupported changes.
Compatible prompt examples
The key to a fast AI + hot reload workflow is crafting prompts that produce changes within existing function bodies. Here are examples of prompts that are fully compatible with hot reload, along with the kind of code changes they produce.
Adjust modifier parameters
Prompts that ask the AI to tweak sizes, padding, colors, or other modifier values produce the ideal kind of change for hot reload: a simple value swap inside an existing function body.
@Composable
fun Header() {
Box(
modifier = Modifier
.padding(24.dp)
.background(Color(0xFF0D1117))
) {
// content
}
}Tune animation specs
Adjusting animation durations, easing curves, and spring parameters are all body-only changes that hot reload handles perfectly.
@Composable
fun FadeInContent(visible: Boolean) {
val alpha by animateFloatAsState(
targetValue = if (visible) 1f else 0f,
animationSpec = spring(dampingRatio = 0.3f)
)
Box(modifier = Modifier.alpha(alpha)) {
// content
}
}Change text and styling
Updating text content, font sizes, colors, and typography within existing composables is always hot-reloadable.
@Composable
fun TitleBar(title: String) {
Text(
text = title,
fontWeight = FontWeight.Bold,
fontSize = 28.sp,
color = Color.White
)
}Polish overall layout design
Asking the AI to polish visual details across a screen is a great fit for hot reload. Colors, background colors, font sizes, font weights, and other modifier-related properties can all be tweaked without changing the class structure.
@Composable
fun ProfileCard(user: User) {
Column(
modifier = Modifier
.background(Color(0xFF161B22), RoundedCornerShape(16.dp))
.padding(24.dp)
) {
Text(
text = user.name,
color = Color.White,
fontWeight = FontWeight.Bold
)
Text(
text = user.bio,
fontSize = 16.sp,
color = Color(0xFF8B949E)
)
}
}Update logic and conditions
Changing conditional logic, formatting functions, or business rules inside existing functions works seamlessly. This applies to both composable and non-composable functions.
fun formatPrice(amount: Double): String {
return "€${String.format("%.2f", amount)}"
}Best practices
When prompting an AI tool, be explicit about modifying existing code rather than creating new functions. For example, “change the padding in ProfileScreen” is better than “create a new ProfileHeader composable.” The former produces a body-only change that hot reloads instantly; the latter adds a new function that requires a full rebuild.
If the AI does add or remove functions (changing the class structure), HotSwan detects this automatically and triggers a full incremental build instead of a hot reload. No manual intervention is needed. The fallback is seamless.
The HotSwan Console tab in your IDE shows every reload event. When AI edits trigger rapid consecutive saves, you can see how HotSwan coalesces them into a single reload. This is useful for understanding when changes are being applied and confirming that the AI's edits are reaching the device.
Under the hood
AI tools often save files rapidly, 5 to 10 times in a few seconds. HotSwan is designed to handle this gracefully through several mechanisms.
When multiple saves arrive in quick succession, HotSwan coalesces them with a short debounce window. Instead of triggering separate reloads for each save, it waits for the burst to finish and compiles all changes together. This prevents cascading class reloads and keeps the device stable.
Unlike IDE keystrokes, external AI tools write directly to disk. HotSwan runs a periodic file system refresh to detect these external changes reliably without relying on IDE document listeners. This is why changes from CLI-based tools like Claude Code are picked up even though they operate outside the IDE.
Rapid AI edits can occasionally produce intermediate states that cause layout crashes. HotSwan installs a crash guard that catches these failures shortly after reload and automatically recovers by restarting the Activity. The deferred change queue is also cleared during recovery to prevent infinite crash loops.
AI tools sometimes make incremental saves that produce identical code, for example saving mid-edit before the change is complete. HotSwan detects when nothing has actually changed and skips the reload entirely, avoiding unnecessary recompositions on the device.