Give a coding assistant the right repository context
Point a coding assistant at the relevant files, types, examples and conventions and add scoped repository instructions it supports.
By Invicly Tech, , in Prompt Engineering and Vibe Coding. About 8 minutes to read.
In short
A coding assistant only knows what you show it. If it sees the wrong files it guesses, and guesses look like real code. Giving it the relevant files, data types, examples and project rules gets answers that fit your codebase.
Think of it like this: A new teammate writes better code on day one if you hand them the right files and the team rules, not the whole repository.
Explained simply
An AI coding assistant is not magic. It can only use what is in front of it: your message, the files you attach and any saved instructions. If a key file is missing, it fills the gap with a guess.
So choose context on purpose. Attach the two or three files the change touches. Add the type definitions that describe your data, and one real example of that data. Leave out everything else.
Tell it your habits in plain words. For example: we use TypeScript, styles are Tailwind classes, tests live next to the code. If you repeat the same rules in every prompt, save them once in a repository instructions file.
At the end, check the work. Ask the assistant which files and instructions it used. If it ignored a rule, the rule may be unclear or in the wrong place. Fix that and ask again.
Press Play on a diagram to walk through it one step at a time.
- 1Task and acceptance criteria
What to change and how to check it
- 2Relevant files
The few files the change touches
- 3Types and sample data
Shapes of inputs and outputs
- 4Conventions
Naming, style, tools in use
- 5Repository instructions
Saved rules read on every request
- Only the task sentence
- Assistant guesses types
- Style does not match
- Two or three key files
- Types and one example
- Short rules
- Whole repository
- Key details buried
- Slower and costlier
In depth
Choosing files and examples
More context is not better. Models read everything you give them, and unrelated files can distract them and raise the cost. A good starting set is the file you will change, the file that defines its data types, one similar file that shows your style, and one test. If the assistant needs more, it will usually ask, or you can add it in the next message. Always use fake or synthetic data in examples, never real customer records or secrets.
- The file to change
- Its type definitions
- One similar file as a style guide
- One test or sample input
- Synthetic data only
Repository instructions
Many tools let you store rules in a file that is read on every request. GitHub Copilot reads .github/copilot-instructions.md, and some tools also support path-specific files that apply to certain folders. Other assistants use their own file names, so check your tool's documentation. Keep the file short and concrete: the language and framework, how to run tests, naming rules, and things to avoid. Review it like code, because a wrong rule affects every answer.
- Short and specific
- Commands to run tests and lint
- Naming and folder rules
- List what not to do
- Review changes like code
- Step 1Instructions file
Stored in the repo
- Step 2You send a prompt
Plus attached files
- Step 3Tool combines them
Rules and your request
- Step 4Model answers
Following both
Checking what was used
Do not assume the assistant saw a file. Many tools show a list of references or attached files under the answer. If yours does, read it. If not, ask: which files and instructions did you use for this answer? If the list is wrong, attach the missing file explicitly. This habit catches the most common cause of off-target code: the assistant never saw the file that mattered.
- Read the references list
- Ask for files and rules used
- Attach missing files by name
Learn it in 5 short steps
About 30m each. Track them with a timer in your plan.
- 1Attach the files that matter~30m
- 2Share data types and examples~30m
- 3State project conventions~30m
- 4Add repository custom instructions~30m
- 5Check what context the assistant used~30m
Key points
- Attach the files that matter and leave out the rest. Extra files add noise and cost.
- Share type definitions and one or two real examples of the data.
- State conventions in plain words: the framework, the test tool, how files are named.
- Many assistants read a repository instructions file. GitHub Copilot uses .github/copilot-instructions.md. Check your tool's docs for its file name.
- Ask the assistant which files and instructions it used, and fix gaps if it missed one.
Key terms
Tap a card to flip it. 0/5 known
Examples
Task: add a Learn more link to the CourseCard component.
Files: src/components/CourseCard.tsx, src/types/course.ts
Sample data: { slug: "git-basics", level: "Beginner" }
Rules: TypeScript, Tailwind classes only, no new packages.
Link format: /courses/<slug>
Change only CourseCard.tsx.A prompt that names files, data and rules.
A focused prompt
You want a small change to a card component. The prompt names the file, shows the data shape and states the rules. The assistant has what it needs and no more, and it is told which file it may edit.
Add a Learn more link to CourseCard.
Files: src/components/CourseCard.tsx, src/types/course.ts
Example: { slug: "git-basics", level: "Beginner" }
Rules: TypeScript, Tailwind classes, no new packages.
Link: /courses/SLUG. Edit only CourseCard.tsx.A starter instructions file
This sample file stores rules once. The file name depends on your tool, so check its documentation. Replace the commands with your own.
# Project rules
- Language: TypeScript. Framework: Next.js App Router.
- Styles: Tailwind classes only.
- Run npm run lint and npm test before finishing.
- Test files sit next to the source file.
- Never add a dependency without asking.
- Use fake data in examples.Quick reference
- Attach only the files the change touches.
- Share type definitions and one example of the data.
- State conventions: language, styles, test tool.
- Save repeated rules in a repository instructions file.
- Copilot reads .github/copilot-instructions.md; other tools differ.
- Ask: which files and rules did you use?
- Use synthetic data, never real secrets.
Common mistakes
- Pasting the entire repository, which hides the important files in noise.
- Leaving conventions unwritten, then fixing the same style mistakes in every answer.
- Putting secrets or real customer data in repository instructions or attached files.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
List the four items you would attach to ask for a change to a Button component.
- Exercise 2medium
Write a five-line instructions file for a Python API project that uses pytest and FastAPI.
- Exercise 3hard
The assistant produced code using a library you do not use. Describe how you find the cause and fix it so it does not repeat.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- What is a context window?
- It is the amount of text a model can read at once. Your prompt, attached files and instructions must all fit inside it.
- Do all assistants read the same instructions file?
- No. File names and features differ by tool, so check the documentation of the one you use.
- Should I put API keys in the instructions file?
- Never. Use placeholders such as YOUR_API_KEY, and keep real secrets in environment variables outside the repository.