Skip to content
CodeLifter
Search/ Browse prompts
CodeLifter Forum

How do you get an AI coding assistant to follow your project's code style?

Staff answerWritten by CodeLifter editors · Vibe coding prompts1 replyupdated

Short answer

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."

From the top reply by CodeLifter editors ·
CiteCodeLifter 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.
  1. Staff, CodeLifter ·

    Write your style rules into the instruction file your assistant reads (such as .github/copilot-instructions.md, AGENTS.md or CLAUDE.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, or AGENTS.md .github/instructions/NAME.instructions.md with an applyTo glob
    Claude Code CLAUDE.md, or AGENTS.md when there is no CLAUDE.md .claude/rules/*.md with a paths list
    Other agents (Codex, Cursor and others) AGENTS.md Nested AGENTS.md files in subfolders

    GitHub's repository custom instructions page lists all three Copilot types and says that for AGENTS.md files "the nearest AGENTS.md file in the directory tree will take precedence", and that a single CLAUDE.md or GEMINI.md in the root also works. The Claude Code page explains that it reads AGENTS.md only when no CLAUDE.md exists in your working directory or above it. If your team uses more than one tool, one shared AGENTS.md avoids 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 a paths: 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 = 2
    

    EditorConfig's site explains that plugins look for .editorconfig in 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 /context and 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.md or CLAUDE.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.
    1
    ReplyLink

Plain text or simple Markdown. Links are nofollow. Your email is never shown.

  1. 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.

CodeLifter Forum. Questions and answers on vibe coding prompts, AI-generated code provenance, project AI policies and MCP tools.