Let me tell you about the moment I realized I was doing AI coding wrong.

It was my third session with an AI assistant on the same project. I had just spent ten minutes explaining the directory structure, the database schema, our naming conventions, and why we use FastAPI instead of Flask. Again. For the third time. Same project, same me, same explanation.
I was burning tokens on context instead of actually building things.
That’s when I discovered context files — and they changed everything.
What Are AI Coding Context Files?
Every major AI coding tool now supports a project-level configuration file that gets injected into every session automatically. Think of it as a README that the AI actually reads — before you even say hello.
The idea is simple: instead of re-explaining your project every time you open a new chat or start a new session, you write it down once. The AI loads it silently and already knows what you’re working on, which frameworks you use, your coding style, and your project’s rules.
Here are the three you’ll encounter most often:
- .cursorrules — Used by Cursor, the AI-powered IDE. Lives in your project root and gets injected into every Cursor chat and inline edit session.
- CLAUDE.md — Used by Claude Code (Anthropic’s terminal-based coding tool). Also in the project root. Claude reads it at session start.
- AGENTS.md — Used by Copilot and other GitHub-ecosystem tools. GitHub’s version of the same concept, often placed in
.github/AGENTS.md. - .github/copilot-instructions.md — GitHub Copilot’s dedicated instruction file. Works across Copilot Chat, Copilot Workspace, and inline completions.
Different names, same purpose: give the AI a map before it starts coding.
Why This Actually Matters (Beyond Saving Tokens)
Yes, fewer tokens means less latency and lower costs — and with AI coding tools getting more expensive by the month, that’s real money. But the real win is consistency.
Without context files, every session is a fresh start. The AI learns your project from scratch, makes assumptions, guesses at your conventions, and sometimes just gets it wrong. You end up correcting it more than collaborating with it.
With a context file, the AI already knows:
- What language and framework you’re using
- Your preferred testing library and style
- Whether you use TypeScript or plain JavaScript (and which flavor)
- Your naming conventions (camelCase vs snake_case, a never-ending war)
- Which files are off-limits (looking at you, generated code)
It’s the difference between handing someone a map and expecting them to navigate by asking questions.
What to Actually Put in Your Context File
I’ve iterated through bad context files so you don’t have to. Here’s what works:
1. Project Overview (2-3 Sentences)
Start with the shortest possible description. Not a novel — just enough that the AI knows what it’s working on.
# Project: Hermes Agent
# An AI agent framework that runs in terminal. Built in Python,
# supports plugins, skills, and tool-defined capabilities.
2. Tech Stack (Bullet Points)
Be specific about versions where it matters. The AI won’t suggest Python 3.12 features if you tell it you’re on 3.9.
## Tech Stack
- Python 3.11 (no 3.12+ features)
- FastAPI for HTTP endpoints
- pytest with pytest-asyncio for testing
- SQLite via aiosqlite
- No ORM — raw SQL only
3. Conventions and Rules
This is where context files earn their keep. Write down the unwritten rules your team follows:
## Conventions
- Use snake_case for Python, camelCase for JavaScript
- All public functions must have docstrings (Google style)
- Async functions only where actually needed — no async-for-the-sake-of-async
- Never commit .env files or secrets
- Run `pre-commit` before pushing — don't skip hooks
4. Testing Instructions
Tell the AI exactly how to run tests. Otherwise it’ll guess — and guessing is where things break.
## Testing
- Run all tests: `pytest -n auto`
- Run single file: `pytest tests/test_auth.py -v`
- Integration tests need Docker running: `docker compose up -d` first
5. Known Pitfalls
This section alone has saved me hours. Write down the footguns you’ve already discovered:
## Watch Out For
- The database connection pool is shared — never close it manually
- Windows users: use `uv` instead of pip (PEP 668 in WSL)
- Never import `test_utils` in production code
- The logging module is monkey-patched — use `get_logger()` not `logging.getLogger()`
A Real Example: My OpenCode Context File
Back when I started using OpenCode for my development workflow, I kept running into the same problem: every session, I’d explain the project structure, our testing conventions, and why certain decisions were made. After the third time in one day, I wrote a context file — and the difference was immediate. The AI already knew which Python version we were on, that we used raw SQL instead of an ORM, and that uv was our package manager. No more “have you tried using Poetry?” suggestions.
Here’s a stripped-down version of what I use:
# Hermes Agent Project Context
## Stack
- Python 3.11, FastAPI, pytest
- SQLite via aiosqlite — raw SQL, no ORM
- Package management: uv (not pip, not Poetry)
## Rules
- All API routes in routes/ directory
- Database queries only in db/ module — never inline SQL in routes
- Use type hints everywhere (strict mode in CI)
- Error messages must be user-facing strings, not stack traces
## Testing
- pytest -n auto for parallel
- Mark slow tests with @pytest.mark.slow
- Integration tests need Docker services up
## Pitfalls
- PEP 668 on WSL: always use venv or uv, never pip install system-wide
- The session middleware stores state in memory — don't rely on it in prod
It’s not long. It’s not fancy. But every line in that file is something I used to say out loud, repeatedly.
Where These Files Actually Go
Placement matters because each tool looks in a specific spot:
| Tool | File | Location |
|---|---|---|
| Cursor | .cursorrules |
Project root |
| Claude Code | CLAUDE.md |
Project root |
| Copilot Chat | .github/copilot-instructions.md |
.github/ directory |
| GitHub Copilot (general) | AGENTS.md |
Project root or .github/ |
| Windsurf | .windsurfrules |
Project root |
If you use multiple tools — and let’s be honest, most of us do — you can maintain a single source of truth file and symlink to the tool-specific names:
cp CONTEXT.md .cursorrules
cp CONTEXT.md CLAUDE.md
ln -s CONTEXT.md .cursorrules # or symlink if your filesystem supports it
Common Mistakes (I Made Them All)
Mistake 1: Writing a Novel
Your context file is not your architecture documentation. If it’s longer than 100 lines, you’re probably overdoing it. The AI doesn’t need your project’s entire history — it needs the guardrails.
Mistake 2: Forgetting to Update It
Context files rot. When you switch testing frameworks from unittest to pytest, update the file. When you bump Python versions, update the file. An outdated context file is worse than no context file — it actively misdirects the AI.
Mistake 3: Putting Secrets in It
Context files are plain text in your repo. They’re committed to version control. They’re sent to third-party AI APIs. Never put API keys, tokens, or passwords in them. Treat them like you’d treat an open-source README.
Mistake 4: Ignoring Security Implications
Speaking of which — context files give the AI detailed knowledge of your project structure. In the wrong hands, that’s a blueprint. The recent agentjacking attacks that trick AI coding tools into running malicious code are a stark reminder that more context means more surface area. Be deliberate about what you share.
The Bottom Line
Context files are one of those things that sound too simple to matter — until you try them. I went from re-explaining my project three times a day to never explaining it at all. The AI just knows.
Start with a 30-line file. Put your tech stack, conventions, and testing commands in it. Save it to your project root. Next time you open a new AI coding session, notice what you don’t have to explain anymore.
That’s the whole point.
And if you’re still on the fence — AI agents aren’t going anywhere. The tools are getting better, the context windows are getting bigger, and the gap between “using AI” and “working with AI” is shrinking every month. Context files are how you bridge it.