How do you get an AI coding assistant to follow your project's code style?
What if personal, repository and organisation instructions disagree? All of them reach the model, and the order only decides which is preferred, so a conflict produces unpredictable output. GitHub's repository instructions page says: "Personal instructions take the highest priority. Repository instructions come next, and then organization instructions are prioritized last. However, all sets of relevant instructions are provided to Copilot."
Cite
CodeLifter Forum, "How do you get an AI coding assistant to follow your project's code style?", https://codelifter.com/forum/posts/how-do-you-get-an-ai-coding-assistant-to-follow-your-projects-code/, accessed 2026-12-06.- CodeLifter editorsStaffStaff, CodeLifter ·
Write your style rules into the instruction file your assistant reads (such as
.github/copilot-instructions.md,AGENTS.mdorCLAUDE.md), make each rule concrete enough to check, point it at a real file to copy, and let a formatter and linter enforce the mechanical parts. Instructions guide the model; tools make the result consistent.Checked on 12 November 2026.
Why does the assistant ignore your style in the first place?
A model writes in the style it has seen most often, unless something in its context says otherwise. If your project uses tabs, single quotes and named exports, but the open file is short and the prompt says nothing, the assistant has little to go on. Each new chat or agent session also starts fresh, so what you corrected yesterday is gone unless it lives in a file the tool loads.
That is the job of instruction files. Anthropic's Claude Code memory page says each session "begins with a fresh context window", and that project instruction files are loaded at the start of every conversation. It also says the tool treats them "as context, not enforced configuration", which is why the second half of this answer is about tools.
Which file does each assistant read?
Assistant Repository-wide file Rules for some paths only GitHub Copilot .github/copilot-instructions.md, orAGENTS.md.github/instructions/NAME.instructions.mdwith anapplyToglobClaude Code CLAUDE.md, orAGENTS.mdwhen there is noCLAUDE.md.claude/rules/*.mdwith apathslistOther agents (Codex, Cursor and others) AGENTS.mdNested AGENTS.mdfiles in subfoldersGitHub's repository custom instructions page lists all three Copilot types and says that for
AGENTS.mdfiles "the nearestAGENTS.mdfile in the directory tree will take precedence", and that a singleCLAUDE.mdorGEMINI.mdin the root also works. The Claude Code page explains that it readsAGENTS.mdonly when noCLAUDE.mdexists in your working directory or above it. If your team uses more than one tool, one sharedAGENTS.mdavoids keeping two sets of rules in step; our rules file thread covers what else belongs in it.How should the style rules be written?
Concrete and checkable. The Claude Code page gives the clearest examples: "Use 2-space indentation" instead of "Format code properly", and "API handlers live in
src/api/handlers/" instead of "Keep files organized." It adds that if two instructions contradict each other, the model "may pick one arbitrarily", and suggests keeping each file under 200 lines because longer files "reduce adherence."A style section that works tends to look like this:
## Code style - TypeScript strict mode. No `any`; use `unknown` and narrow it. - Named exports only. No default exports. - Async code uses async/await, never `.then()` chains. - Errors: throw `AppError` from `src/errors.ts`; never throw plain strings. - New React components follow `src/components/Button.tsx` (props type, then component, then styles). - Run `npm run lint -- --fix` and `npm test` before saying a task is done.The line that names a real file is the most useful one. "Follow
src/components/Button.tsx" gives the model a full example of your conventions, including the ones you would never think to write down.How do you scope rules to one part of the codebase?
Use path-specific files, so backend rules do not crowd out frontend ones. In Copilot, GitHub's page shows a front matter block such as:
--- applyTo: "**/*.ts,**/*.tsx" --- Use named exports. Prefer `type` over `interface` for props.GitHub notes that on GitHub.com these path files are currently used by Copilot cloud agent and Copilot code review, and that when both a path file and the repository-wide file apply, "the instructions from both files are used." In Claude Code the same idea is a file in
.claude/rules/with apaths:list, which loads "only when Claude works with matching files."What should a tool enforce instead of a prompt?
Anything a machine can check: indentation, line endings, quotes, import order, trailing whitespace. An EditorConfig file sets the basics for every editor that reads it, and many editors have native support or a plugin:
root = true [*] end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true [*.{js,ts,tsx}] indent_style = space indent_size = 2EditorConfig's site explains that plugins look for
.editorconfigin the file's folder and every parent, and that "properties in closer files take precedence." Add your formatter and linter on top, run them in CI, and tell the assistant in the instruction file to run them. Then a style slip becomes a failed check the agent can fix, not a review comment. The review thread has more on what humans should still look for.How do you know the rules were used?
In Copilot Chat on GitHub, the docs say the instructions file appears in the references list "at the top of a chat response". In Claude Code, the memory page says to run
/contextand check the list under Memory files. If a rule is loaded but ignored, make it more specific or shorter before adding more rules. For the prompt itself, the coding prompt guide shows how to restate one critical rule for a single task.Short version
- Put style rules in the file your tool loads:
copilot-instructions.md,AGENTS.mdorCLAUDE.md. - Write rules a reviewer could check, and point to one real file as the model to copy.
- Scope rules by path so each part of the codebase gets only what applies.
- Let EditorConfig, a formatter and a linter enforce the mechanical rules, and tell the agent to run them.
- Put style rules in the file your tool loads:
Write something first.
Give people something to work with: at least 30 words on what happened and what you tried.
That is too long. Keep it under 6,000 characters.
Write the question as the title, 15 to 140 characters, no links.
Pick a category.
Add a name (2 to 40 characters, no links).
That email address does not look right.
That was quick. Read the thread, then try again.
The form expired. Reload the page and post again.
Something went wrong with the form. Reload and try again.
Please complete the check and post again.
Limit reached for now. Try again later.
This thread is closed to new replies.
This thread no longer accepts replies.
Something went wrong with the form. Reload and try again.
Post a reply or question first (name and email), then this browser can vote, edit and accept answers.
You cannot vote on your own post.
Only the author (within 30 days) or the forum team can do that.
That email already has an account. Use your sign-in link instead.
New accounts are paused for the moment. Try again later.
That was already posted.
1 answer
- CodeLifter editorsStaffStaff, CodeLifter ·
What if personal, repository and organisation instructions disagree? All of them reach the model, and the order only decides which is preferred, so a conflict produces unpredictable output. GitHub's repository instructions page says: "Personal instructions take the highest priority. Repository instructions come next, and then organization instructions are prioritized last. However, all sets of relevant instructions are provided to Copilot." It advises avoiding conflicting sets where possible and suggests temporarily disabling repository instructions if you suspect they are hurting answers.
Claude Code works the other way round for loading order. Its memory page lists files "from broadest scope to most specific, so a project instruction appears in context after a user instruction", and warns that contradictions may be resolved "arbitrarily". It also offers a prompt audit to find outdated or conflicting rules.
A practical split avoids most clashes: keep personal files for personal preferences that do not touch code (how verbose explanations are, which language to reply in), and put every rule about code in the repository, where it is reviewed like code. A style rule that lives only in one developer's personal settings will produce code the rest of the team did not agree to.