Claude Code for Android projects
Why it matters
- Claude Code runs
./gradlew test,./gradlew lint, and./gradlew assembleDebugin your terminal, so it can verify its own edits against your actual build instead of guessing. This changes how you write tickets: you give the agent a failing test and a one-line spec, not a 200-line prompt. - Interviewers at product companies now ask how you integrate an agentic tool into a Kotlin/Compose codebase without breaking CI. Knowing CLAUDE.md, skills, and hooks shows you can make the tool respect project conventions (ktlint rules, Compose state hoisting, no
varin ViewModel). - Hooks let you block the agent from touching
keystore.jks,local.properties, orBuildConfigfields that hold secrets. Without that guardrail, a single careless prompt can leak a signing key into a commit. - Google publishes official Android skills (installable with the Android CLI:
android skills add <skill-name>), and the agent in Android Studio reads skills from.agents/skills/or.android-studio/skills/plusAGENTS.mdfiles. Both use the same open skill format, so you can move between tools without rewriting everything.
The simple explanation
- CLAUDE.md is the sticky note on your monitor: always visible, always in context.
- A skill in
.claude/skills/is a folder in your desk drawer: you open it only when the task matches its label. - A hook is the office security guard: it checks every file the agent tries to open or save and can say 'no'.
- An MCP server is a phone line to an external system (Jira, Figma, a design-token API) so the agent does not need you to paste data by hand.
- A subagent is a junior dev you hand a single ticket; it works in isolation and reports back a diff.
Claude Code is an agentic coding tool from Anthropic. It runs in your terminal, in IDE extensions (VS Code, JetBrains IDEs including Android Studio), a desktop app, or the web. It reads your repository, runs shell commands, and edits files, asking your permission first unless your permission settings already allow the action. It is not a chat window; it is a loop: read context → plan → act → verify → repeat.
Context layers. The tool loads context in tiers:
| Layer | Where | When loaded | Typical content |
|---|---|---|---|
CLAUDE.md | repo root or .claude/ | every session, always | build commands, architecture rules, forbidden patterns |
Skill (.claude/skills/<name>/SKILL.md) | project folder | descriptions at start; full skill on demand, when the task matches its description or you type /skill-name | a focused procedure, e.g. 'add a Compose screen' |
Hook (settings.json) | .claude/ | on lifecycle events: PreToolUse, PostToolUse, UserPromptSubmit, SessionStart, Stop | run ktlint, block edits to keystore.jks |
MCP server (.mcp.json) | project or user | when the agent calls the server | Jira, Figma, a design-token API |
Skills follow the open Agent Skills standard: a folder with a SKILL.md file whose YAML front-matter has name and description, plus optional scripts and reference files. Google publishes Android-specific skills at github.com/android/skills; list them with android skills list and install one with android skills add <skill-name>. The agent in Android Studio uses the same format from .agents/skills/ or .android-studio/skills/, plus AGENTS.md files.
The loop matters. Because Claude Code can run ./gradlew test and read the output, you give it a failing test and a one-line spec. It edits the Kotlin file, runs the test, reads the failure, and retries. You review the diff. This is the same workflow as reviewing a junior colleague's pull request, except the 'colleague' works in minutes.
Safety. Keep keystore.jks, local.properties, and any API key out of the agent's reach. Permission deny rules in .claude/settings.json or a PreToolUse hook can block access to those paths. Never paste a secret into a prompt; it lands in the session log. API keys belong on a server, not in BuildConfig or app code.
Notes
- CLAUDE.md at the repo root (or
.claude/CLAUDE.md) is always loaded into every session. Put build commands (./gradlew assembleDebug,./gradlew test), the module layout, and hard rules (novarinViewModel, always userememberSaveable) here. - A skill lives in
.claude/skills/<name>/SKILL.md. The YAML front-matterdescriptionfield is what the agent matches against the user's task. Keep it specific: 'Generate a Jetpack Compose screen with state hoisting' beats 'UI stuff'. - Hooks are shell commands in
.claude/settings.jsonkeyed to lifecycle events.PreToolUseruns before a tool call (edit, write, shell command);PostToolUseruns after it succeeds. APreToolUsehook that exits with code 2 blocks the call, so use it to stop edits tokeystore.jksorlocal.properties. - MCP servers in
.mcp.jsongive the agent access to external tools (Jira, Figma, a design-token API). The agent calls them like a function; you do not paste data by hand. - Subagents run an isolated task in their own context window. Use them for a single, well-scoped job (e.g. 'migrate this one screen to Compose') so the main thread stays focused.
- Plugins bundle skills, hooks, subagents, and MCP servers into one installable unit, so a team shares one setup instead of copying files.
- Good practice: give the agent a way to verify its work (a failing test, a lint rule, a build command). Without verification the agent guesses. With it, the loop converges.
- Review every diff the agent produces. Treat AI-written Kotlin code like a junior colleague's PR: check nullability, lifecycle handling, Compose recomposition, and ProGuard rules.
- Never put an API key in app code,
BuildConfig, or a prompt. It must stay on a server. Deny rules or a hook can block the agent from reading or writinglocal.propertiesand keystores. - Check the current docs for supported models and devices; model names and device lists change every few months.
Code example
This is a production-ready CLAUDE.md for a multi-module Kotlin/Compose Android app. It tells Claude Code how to build, test, and lint, and lists the hard rules the agent must respect when editing source files.
# CLAUDE.md — MyAndroidApp
## Build & verify
- Build: `./gradlew assembleDebug`
- Unit tests: `./gradlew :app:testDebugUnitTest`
- Instrumented: `./gradlew :app:connectedDebugAndroidTest`
- Lint: `./gradlew :app:lintDebug`
- Format: `./gradlew spotlessApply`
## Architecture
- Kotlin, Jetpack Compose, MVVM with `ViewModel` + `StateFlow`.
- Modules: `:app`, `:core:network`, `:core:design`, `:feature:login`, `:feature:home`.
- Dependency injection via Hilt. No manual singletons.
## Hard rules (do not violate)
- No `var` in `ViewModel`; expose `StateFlow` / `SharedFlow` only.
- Compose: hoist state, use `rememberSaveable` for UI state that must survive rotation.
- No `TODO()` or `println` in committed code.
- All network calls go through `:core:network`; feature modules never call Retrofit directly.
- Resource strings in `strings.xml`; no hardcoded user-facing text.
## Forbidden paths (hook will block)
- `keystore.jks`, `local.properties`, `*.keystore`
- `BuildConfig` fields that hold secrets
## Conventions
- KtLint with 4-space indent, 120-char max line.
- Test naming: `given_when_then` in `*Test.kt`.
- Commit messages: conventional commits (`feat:`, `fix:`, `refactor:`).- The Build & verify section gives the agent the exact Gradle commands so it can run
./gradlew testafter every edit and read the output instead of guessing. - Hard rules are phrased as imperatives the agent treats as constraints; vague guidance like 'follow best practices' is ignored.
- Forbidden paths are a reminder for the human reviewer; the actual enforcement is a deny rule or a
PreToolUsehook in.claude/settings.jsonthat exits with code 2 if the target path matches. CLAUDE.md is context, not enforced config.
In production
- A developer asked Claude Code to 'add a retry button to the login screen.' The agent rewrote the entire
LoginViewModel, replacing theStateFlow<LoginUiState>with aMutableStateFlowexposed publicly. - The Compose screen began writing to that public state directly, skipping the ViewModel's validation. An empty password reached the server.
- CI passed because the unit test only checked the happy path through the ViewModel.
- The team added a
PostToolUsehook that runs./gradlew :feature:login:testDebugUnitTestafter file edits, so the agent sees failures right away. - They added a hard rule to
CLAUDE.md: 'NovarinViewModel; exposeStateFlow/SharedFlowonly.' - A new unit test asserted that the
ViewModelexposes an immutableStateFlow, not aMutableStateFlow.
- A developer ran Claude Code in a fresh clone and asked it to 'set up the release build.' The agent created a
local.propertieswith a placeholder and then, in a follow-up prompt, pasted a real API key into the chat to 'configure the network module.' - The key appeared in the session log. The team's secret-scanning bot flagged it, but the damage was done: the key was in the agent's context and could have been written to a file.
- They added a
PreToolUsehook that blocks any write tolocal.properties,keystore.jks, and any file matching*secret*. - The team added a
CLAUDE.mdrule: 'Never accept or write API keys. Keys live on the server. If the user pastes one, refuse and tell them to use the server-side config.' - They rotated the exposed key and added a
Stophook that runs a secret scanner ongit diff; exit code 2 stops Claude from finishing until the problem is fixed.
Common mistakes
- Putting a 2000-line architecture doc in CLAUDE.md. CLAUDE.md is loaded into every session's context window. A huge file burns tokens on every turn and pushes out the actual code the agent needs to read. The docs suggest under about 200 lines; move detail into skills that load on demand.
- No verification command in CLAUDE.md. Without
./gradlew testor./gradlew lintlisted, the agent cannot confirm its edit compiles. It will produce plausible-looking Kotlin that fails the build. Always give the agent a way to check its own work. - Pasting an API key or keystore password into the prompt. The key lands in the session log and the agent's context. It can be written to a file in a later turn. Keys must stay on a server. Deny rules or a
PreToolUsehook should block access tolocal.propertiesandkeystore.jks. - Trusting the diff without reading it. The agent can produce Kotlin that compiles but violates your architecture (exposing
MutableStateFlow, calling Retrofit from a feature module, missingrememberSaveable). Review every diff like a junior colleague's PR. - One giant task instead of small steps. A prompt like 'migrate the whole app to Compose' gives the agent too much surface area. It will make inconsistent choices across screens. Break it into one screen per task, verify with
./gradlew assembleDebugafter each. - No hard block on forbidden paths. Without a deny rule or
PreToolUsehook, the agent can write tokeystore.jksorBuildConfigif the prompt asks it to. Deny rules and hooks are hard guardrails; a rule in CLAUDE.md is context the agent can still ignore.
Interview questions
Answer out loud first. Then reveal the answer and compare it at each depth.
“How does Claude Code differ from a chat-based AI assistant when working on an Android project?”
“What is the difference between CLAUDE.md and a skill, and when would you use each?”
“How do hooks work, and what is a practical use case for an Android project?”
“What is your process for reviewing AI-written code in a production Android app?”
Quiz
What is loaded into every Claude Code session automatically?
Which hook event runs before the agent writes a file?
A skill in .claude/skills/ is triggered when…
What is the correct place for an API key in an Android project?
0 of 4 answered
Mini task
Set up Claude Code for your Android project (15 min)
-
Create
CLAUDE.mdat the repo root. Add the build commands your team uses:./gradlew assembleDebug,./gradlew :app:testDebugUnitTest,./gradlew :app:lintDebug. List the module names and the hard rules (novarinViewModel, useStateFlow, no hardcoded strings). Keep it under 150 lines. -
Create a skill. Make the folder
.claude/skills/compose-screen/. Inside, createSKILL.mdwith YAML front-matter:name: compose-screen,description: Generate a Jetpack Compose screen with hoisted state and rememberSaveable. In the body, write the step-by-step procedure your team follows when adding a new screen. -
Add a hook. In
.claude/settings.json, add aPreToolUsehook with matcherEdit|Writethat runs.claude/hooks/block-signing.sh. The hook gets the tool input as JSON on stdin. The script readstool_input.file_path(for example withjq), and if the path matches.jks,.keystoreorlocal.propertiesit prints a reason to stderr and exits with code 2, which blocks the edit. -
Test the loop. Open Claude Code in your terminal. Give it a small task: 'Add a unit test for
LoginViewModelthat asserts theStateFlowemitsLoadingthenSuccess.' Watch it create the test file, run./gradlew :feature:login:testDebugUnitTest, read the output, and fix any failure. -
Review the diff. Read every line the agent wrote. Check that it used
StateFlow, notMutableStateFlow, and that the test usesgiven_when_thennaming. Run./gradlew :app:lintDebugyourself.
Done when: CLAUDE.md exists with build commands and rules, the skill loads when you ask for a Compose screen, the hook blocks a write to keystore.jks, and the agent's test passes ./gradlew :feature:login:testDebugUnitTest.