Claude Code for Android projects

Claude Code for Android: how the agentic tool reads your Gradle repo, runs ./gradlew test, and edits Kotlin files via CLAUDE.md, skills, and hooks. About 25 minutes.

Why it matters

  • Claude Code runs ./gradlew test, ./gradlew lint, and ./gradlew assembleDebug in 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 var in ViewModel).
  • Hooks let you block the agent from touching keystore.jks, local.properties, or BuildConfig fields 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/ plus AGENTS.md files. 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:

LayerWhereWhen loadedTypical content
CLAUDE.mdrepo root or .claude/every session, alwaysbuild commands, architecture rules, forbidden patterns
Skill (.claude/skills/<name>/SKILL.md)project folderdescriptions at start; full skill on demand, when the task matches its description or you type /skill-namea focused procedure, e.g. 'add a Compose screen'
Hook (settings.json).claude/on lifecycle events: PreToolUse, PostToolUse, UserPromptSubmit, SessionStart, Stoprun ktlint, block edits to keystore.jks
MCP server (.mcp.json)project or userwhen the agent calls the serverJira, 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 (no var in ViewModel, always use rememberSaveable) here.
  • A skill lives in .claude/skills/<name>/SKILL.md. The YAML front-matter description field 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.json keyed to lifecycle events. PreToolUse runs before a tool call (edit, write, shell command); PostToolUse runs after it succeeds. A PreToolUse hook that exits with code 2 blocks the call, so use it to stop edits to keystore.jks or local.properties.
  • MCP servers in .mcp.json give 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 writing local.properties and 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 test after 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 PreToolUse hook in .claude/settings.json that exits with code 2 if the target path matches. CLAUDE.md is context, not enforced config.

In production

Agent rewrote a ViewModel and broke navigation
  • A developer asked Claude Code to 'add a retry button to the login screen.' The agent rewrote the entire LoginViewModel, replacing the StateFlow<LoginUiState> with a MutableStateFlow exposed 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 fix
  • The team added a PostToolUse hook that runs ./gradlew :feature:login:testDebugUnitTest after file edits, so the agent sees failures right away.
  • They added a hard rule to CLAUDE.md: 'No var in ViewModel; expose StateFlow / SharedFlow only.'
  • A new unit test asserted that the ViewModel exposes an immutable StateFlow, not a MutableStateFlow.
Signing key nearly committed
  • A developer ran Claude Code in a fresh clone and asked it to 'set up the release build.' The agent created a local.properties with 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.
The fix
  • They added a PreToolUse hook that blocks any write to local.properties, keystore.jks, and any file matching *secret*.
  • The team added a CLAUDE.md rule: '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 Stop hook that runs a secret scanner on git 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 test or ./gradlew lint listed, 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 PreToolUse hook should block access to local.properties and keystore.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, missing rememberSaveable). 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 assembleDebug after each.
  • No hard block on forbidden paths. Without a deny rule or PreToolUse hook, the agent can write to keystore.jks or BuildConfig if 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)

  1. Create CLAUDE.md at 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 (no var in ViewModel, use StateFlow, no hardcoded strings). Keep it under 150 lines.

  2. Create a skill. Make the folder .claude/skills/compose-screen/. Inside, create SKILL.md with 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.

  3. Add a hook. In .claude/settings.json, add a PreToolUse hook with matcher Edit|Write that runs .claude/hooks/block-signing.sh. The hook gets the tool input as JSON on stdin. The script reads tool_input.file_path (for example with jq), and if the path matches .jks, .keystore or local.properties it prints a reason to stderr and exits with code 2, which blocks the edit.

  4. Test the loop. Open Claude Code in your terminal. Give it a small task: 'Add a unit test for LoginViewModel that asserts the StateFlow emits Loading then Success.' Watch it create the test file, run ./gradlew :feature:login:testDebugUnitTest, read the output, and fix any failure.

  5. Review the diff. Read every line the agent wrote. Check that it used StateFlow, not MutableStateFlow, and that the test uses given_when_then naming. Run ./gradlew :app:lintDebug yourself.

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.

Next: CLAUDE.md, skills and hooks