MyFamilyTracker
Real-time family location sharing — Firebase Realtime DB for sub-second propagation, WorkManager + ForegroundService for OS-compliant background collection, geofencing via Google Maps API.
Learn how to feed Claude the right context so it writes accurate Kotlin snippets, refactors UI components, and automates tests for your Android app.
On this page
When Claude asks, “Show me a Room DAO for a user table,” it can either spit out boilerplate or hand me a broken compile‑time error. The difference? Context. If I give Claude a brief snapshot of my project layout, naming conventions, and existing patterns, the assistant instantly writes code that compiles, follows my style, and fits into my CI pipeline. This post shows how to structure that context so Claude becomes a reliable pair‑programmer for my solo Android dev life.
As a solo Android developer with 13+ years in QA, I juggle 22 apps, each with a different architecture style, Gradle configuration, and test strategy. When I ask Claude to generate code, it often produces snippets that:
com.sudarshantechlabs.<app>BaseEntityThe root cause is that Claude sees only the raw prompt, not the surrounding codebase. By giving it a concise, structured “code context” file, I can avoid these pitfalls and harness its full potential.
Claude accepts a single text file or a zip of files as context. The file should be a curated snapshot that illustrates your architecture, naming, and coding standards. Below are the key components:
build.gradle.kts| Directory | Purpose | Key Files |
|-----------|---------|-----------|
| `app/` | Main app module | `MainActivity.kt`, `build.gradle.kts` |
| `app/src/main/java/com/sudarshantechlabs/<app>/di/` | Hilt modules | `AppModule.kt` |
| `app/src/main/java/com/sudarshantechlabs/<app>/data/` | Repository & DAO | `UserRepository.kt`, `UserDao.kt` |
| `app/src/main/java/com/sudarshantechlabs/<app>/ui/` | UI layers | `MainScreen.kt` |
| `shared/` | Shared code across apps | `BaseEntity.kt`, `Result.kt` |[!NOTE] The table gives Claude a high‑level map so it can resolve imports correctly.
plugins {
id("com.android.application")
kotlin("android")
id("dagger.hilt.android.plugin")
}
android {
namespace = "com.sudarshantechlabs.<app>"
compileSdk = 34
defaultConfig {
applicationId = "com.sudarshantechlabs.<app>"
minSdk = 21
targetSdk = 34
}
}
dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.compose.ui:ui:1.6.0")
implementation("com.google.dagger:hilt-android:2.48")
kapt("com.google.dagger:hilt-compiler:2.48")
implementation("androidx.room:room-runtime:2.6.1")
kapt("androidx.room:room-compiler:2.6.1")
}[!TIP] Keep this snippet minimal; Claude uses it to infer the Kotlin DSL and plugin usage.
package com.sudarshantechlabs.shared
import androidx.room.PrimaryKey
open class BaseEntity(
@PrimaryKey(autoGenerate = true) val id: Long = 0L
)[!IMPORTANT] Any custom annotations or base classes must be included so Claude can extend them correctly.
// File: app/src/main/java/com/sudarshantechlabs/<app>/data/UserEntity.kt
package com.sudarshantechlabs.<app>.data
import androidx.room.Entity
import androidx.room.ColumnInfo
import com.sudarshantechlabs.shared.BaseEntity
@Entity(tableName = "users")
data class UserEntity(
@ColumnInfo(name = "first_name") val firstName: String,
@ColumnInfo(name = "last_name") val lastName: String,
@ColumnInfo(name = "email") val email: String
) : BaseEntity()// File: app/src/main/java/com/sudarshantechlabs/<app>/data/UserDao.kt
package com.sudarshantechlabs.<app>.data
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
@Dao
interface UserDao {
@Insert
suspend fun insert(user: UserEntity)
@Query("SELECT * FROM users WHERE email = :email LIMIT 1")
suspend fun findByEmail(email: String): UserEntity?
}[!WARNING] Avoid including large generated files; they bloat the context and slow Claude’s response time.
Once the context file is ready, upload it to Claude and craft a prompt that references the context. For example:
“Using the provided context, create a
that uses Hilt for injection, exposes acodeUserRepositoryofcodeflow, and handles errors gracefully. The repository should be located incodeResult<List<UserEntity>>.”codeapp/src/main/java/com/sudarshantechlabs/<app>/data/
Claude will then generate code that:
UserDaoFlowResult<List<UserEntity>>package com.sudarshantechlabs.<app>.data
import com.sudarshantechlabs.shared.Result
import dagger.hilt.android.scopes.ActivityScoped
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flow
@ActivityScoped
class UserRepository @Inject constructor(
private val userDao: UserDao
) {
fun getAllUsers(): Flow<Result<List<UserEntity>>> = flow {
emit(Result.Loading)
val users = userDao.getAll()
emit(Result.Success(users))
}.catch { e ->
emit(Result.Error(e))
}
}[!NOTE] Notice the use of
from the shared package and thecodeResultannotation—exactly as per the context.codeActivityScoped
If your app has many modules, zip the
app/shared/If you need a different pattern (e.g., a Retrofit service instead of Room), include a short comment in the context indicating the pattern:
// TODO: Provide Retrofit Service pattern for network callsThen ask Claude to “Implement a network service using Retrofit, following the pattern above.”
Add a
CODE_STYLE.md## Naming
- Use PascalCase for classes.
- Use camelCase for functions and variables.
## Annotations
- All repository classes must be annotated with `@ActivityScoped`.
- Use `@Inject` for constructor injection.
## Error Handling
- Wrap all suspend functions in `try/catch` and emit `Result.Error` on failure.Claude will respect these rules when generating code.
Because the generated code is context‑aware, it usually passes lint and unit tests on the first run. However, I still run a quick sanity check:
./gradlew clean build -x testIf the build fails, the error messages point directly to missing imports or incorrect annotations—clue that the context was incomplete. I then update the context file and re‑prompt.
By following these steps, Claude becomes a reliable, context‑aware assistant that saves me countless hours of boilerplate and debugging, keeping my solo Android development focused on building great user experiences.
Sudarshan Chaudhari
AI Systems Builder / Product Engineer
Bangkok, Thailand
Solo Android developer with 13+ years in QA, building Android apps, AI automation systems, and developer tools at SudarshanTechLabs.
Related Posts
Related Apps
Real-time family location sharing — Firebase Realtime DB for sub-second propagation, WorkManager + ForegroundService for OS-compliant background collection, geofencing via Google Maps API.
Building something? Available for Android dev and QA consulting.
Work with meComments — powered by Giscus
Real-time family location sharing — Firebase Realtime DB for sub-second propagation, WorkManager + ForegroundService for OS-compliant background collection, geofencing via Google Maps API.
ReadPrivate dream journal — structured entry capture, pattern tagging, and optional Claude-powered insight generation. All data stays on-device by default.
ReadWorkout tracker — exercise logging with set/rep/weight history, goal progression, and local Room DB persistence. No account, no cloud sync required.
Read