· 6 min read
Shared CLAUDE.md Rules for iOS and Android AI Agents
How I give two Claude Code agents, one per native app, the same product rules with a shared CLAUDE.md file, and keep platform rules apart.
When one Claude Code agent works on the iOS app and another works on the Android app, each one reads its own CLAUDE.md. That is where the drift starts. The two files are written at different times, and they slowly stop agreeing on things that should be the same: how errors are worded, how analytics events are named, which words the product uses. A shared CLAUDE.md file fixes this. One file holds the product rules, both repos import it, and each repo keeps its own platform rules next to it.
This post shows the split I use, the two ways to share the file between repos, and a small check that tells me when the copies go out of sync.
Why two CLAUDE.md files drift
A CLAUDE.md file is the agent's standing memory for a repo. Claude Code loads it at the start of every session, so it shapes every change the agent makes.
In a two-app setup there are really two kinds of rules mixed in each file:
- Platform rules. "Use SwiftUI for new screens." "Use Hilt for DI." "Run
./gradlew testDebugUnitTestbefore you say done." These should differ. - Product rules. "Error messages are one short sentence and say what to do next." "Analytics events are
object_actionin snake_case." "Every interactive element gets an accessibility identifier from the spec." These should be identical.
When both kinds live in one file per repo, a product rule gets updated in one place and forgotten in the other. Nobody notices until the two apps ship the same feature with two different error texts. Then I spend review time on a difference that a single line of text would have prevented.
I wrote before about keeping one platform-neutral spec for both apps. The spec covers one feature. The shared rules file covers everything the spec does not repeat every time.
Split the rules in two layers
The fix is to stop treating CLAUDE.md as one file. All examples below are illustrative, not copied from a real codebase. Each repo ends up with this shape:
ios-app/
CLAUDE.md # short: platform rules + one import line
.claude/rules/
swiftui.md # path-scoped iOS rules
shared-rules/ # same content in both repos
product.md
naming.md
definition-of-done.md
The root CLAUDE.md stays short. It holds the platform rules and pulls in the shared files with Claude Code's @path import syntax:
iOS app
## Platform rules
- New screens use SwiftUI. Do not add new UIKit view controllers.
- Run the unit tests with `xcodebuild test` before you report done.
## Shared product rules
@shared-rules/product.md
@shared-rules/naming.md
@shared-rules/definition-of-done.md
The Android CLAUDE.md has its own platform section and the exact same three import lines. Relative import paths resolve from the file that contains them, not from the folder you start Claude in, so the lines work the same in every worktree. The Claude Code memory docs describe the full syntax.
A shared file is plain Markdown. Here is the kind of thing that goes into naming.md:
Naming rules, shared by iOS and Android.
## Analytics events
- Format: object_action, snake_case, past tense.
Good: invite_sent, settings_opened. Bad: SendInvite, unlockTap.
- Never put user data in an event name.
## Accessibility identifiers
- Format: screen_element[_state], snake_case.
- Use the IDs from the feature spec exactly. Do not invent new ones.
## Words we use in the UI
- "Sign in", never "Log in".
- Error text: one sentence, then what the user can do next.
The point is the type of rule: anything a user, a tester or an analyst would see on both platforms.
Two ways to share the file
The shared folder has to exist in both repos with the same content. I have looked at two options.
Option 1: a git submodule
Put the shared rules in a small repo of their own and add it as a submodule at shared-rules/ in both apps:
git submodule add git@github.com:your-org/agent-rules.git shared-rules
The files are inside the repo, so the imports are not external and there is no approval prompt. A rule change is one commit in the rules repo, then a submodule bump in each app. The bump shows up in the pull request, so a reviewer sees that the agent's rules changed.
The cost is the usual submodule friction. Every clone needs git submodule update --init, and CI needs the same. New worktrees also need it, which matters when you run parallel agents in worktrees.
Option 2: a symlink to a shared folder
Claude Code also supports symlinks inside .claude/rules/. You keep one folder on disk and link it into both repos:
ln -s ~/agent-rules .claude/rules/shared
This is faster to set up and there is nothing to bump. But the target is outside the repo, so Claude Code treats it as an external import and asks for approval the first time. The bigger problem for me: the rules are not versioned with the app. A teammate who clones the repo gets a broken link, and a CI agent gets nothing.
For a solo side project the symlink is fine. For two production apps I prefer the submodule, because the rules travel with the code and every change is reviewed.
Keep platform rules path-scoped
Once the shared rules move out, the platform file can get smaller too. Claude Code loads files in .claude/rules/ as extra rules, and a rule with a paths field in its front matter only loads when the agent touches matching files:
---
paths:
- "app/src/main/**/*.kt"
---
Compose screens:
- State goes into a ViewModel. Composables receive state and callbacks.
- Every clickable element gets Modifier.testTag with the ID from the spec.
- Set testTagsAsResourceId once at the screen root so Maestro can find tags.
This keeps the always-loaded context small. The docs suggest keeping each CLAUDE.md under about 200 lines, because longer files use more context and the agent follows them less reliably. Note that imports do not save context: an imported file loads in full at launch. Path-scoped rules are the tool that actually trims it.
Check that the copies match
With a submodule, the two apps can still point at different commits of the rules repo. That is fine for a day, not for a month. A short script in each app's CI compares its submodule commit with the latest one on the rules repo's main branch:
#!/usr/bin/env bash
set -euo pipefail
local_sha=$(git -C shared-rules rev-parse HEAD)
remote_sha=$(git ls-remote "$(git -C shared-rules remote get-url origin)" refs/heads/main | cut -f1)
if [ "$local_sha" != "$remote_sha" ]; then
echo "::warning::shared-rules is behind main. Bump the submodule."
fi
It warns and does not fail. A failing build because someone improved a wording rule would be annoying. A warning on every pull request is enough to get the bump done.
I also ask the agent to help keep the split clean. When I add a rule, I tell it: "Is this a product rule or a platform rule? If it is a product rule, add it to shared-rules/ and open the change in the rules repo." The agent is good at sorting rules this way. I still decide where the line goes.
Takeaways
- Split each app's
CLAUDE.mdinto platform rules and shared product rules. Only the second kind must match. - Import the shared files with
@shared-rules/...lines, so both agents read the same text. - Prefer a git submodule for production apps: the rules are versioned and reviewed. A symlink is fine for solo projects.
- Move platform details into path-scoped files in
.claude/rules/to keep the always-loaded context small. - Add a CI warning when an app's shared rules fall behind, and bump them in the same rhythm as dependencies.