AGENTS.md templates / Flask

AGENTS.md template for Flask

A ready AGENTS.md for a Flask application. It covers the app factory, blueprints, the run and test commands, and the single-file habits agents fall back to.

Updated 3 December 2026 · 61 lines · 2.5 KB
AGENTS.md
# AGENTS.md

A Flask web application on Python 3.12, built with an application factory and blueprints, tested with pytest.

## Commands

- `uv sync`: install dependencies into the project environment
- `uv run flask --app app run --debug`: start the dev server on http://localhost:5000
- `uv run pytest`: run the tests
- `uv run ruff check .`: lint
- `uv run ruff format .`: format

## Project structure

- `app/__init__.py`: `create_app()` factory. Registers extensions and blueprints
- `app/<feature>/`: one blueprint per feature: routes and forms
- `app/models.py`: database models
- `app/templates/`: Jinja templates
- `tests/`: pytest tests using the app factory

## Rules for agents

- The app is created only in `create_app()`. Use `current_app` elsewhere, never a module-level `app`.
- New routes go in the blueprint for their feature. Create a new blueprint for a new feature.
- Validate request data before using it. Queries are parameterised.
- Never commit `debug=True`, and read `SECRET_KEY` and other secrets from the environment.

## Conventions

### Flask

- Application factory pattern (`create_app`) — no module-level `app = Flask(__name__)`.
- Blueprints per feature. Keep `app/__init__.py` boring.
- Use `Flask-Pydantic` or marshmallow for validation — never trust `request.json` raw.

### Python

- Python 3.11+ features are fair game (PEP 695 generics in 3.12, `Self`, `LiteralString`).
- Type hints on every function signature. Use `mypy --strict` or `pyright` in CI.
- f-strings for formatting. Never `%` or `.format()` in new code.
- Prefer `pathlib.Path` over `os.path`. Use `match/case` where it clarifies branching.
- Dependency management: match the repo's tool (`uv`, `poetry`, or `pip-tools`). Don't mix.

### Pytest

- Fixtures over setUp/tearDown. Scope them appropriately (`function`, `module`, `session`).
- Parametrize repetitive tests with `@pytest.mark.parametrize`.
- Mark slow / integration tests and keep them out of the default run.

## Avoid

- Bare `except:` clauses — always catch a specific exception.
- Mutable default arguments (`def f(x=[])`).

## Guardrails

- Never commit secrets, API keys, or credentials. If you spot one in a diff, stop and flag it.
- Do not invent dependencies. If a package is not already in the manifest, confirm before adding it.
- When a command fails, read the actual error. Do not retry blindly or bypass with `--force`.
- Prefer editing existing files over creating new ones.
- Run the tests and the linter before saying a task is done, and say what you ran.

The commands and folders are the common defaults for Flask. Change them to match your project before you commit the file: an agent will run exactly what is written here.

Make it yours in the generator Add your database, test runner and other tools, pick your coding style, and get matching CLAUDE.md, Cursor and Copilot files. Free, runs in your browser. Already have instruction files? Context Doctor scans your repo and shows which files each coding tool is silently not loading. $19.

How to use it

Save the file as AGENTS.md in the root of your repository and commit it. Then check each tool you use:

ToolWhat to do
Claude CodeReads AGENTS.md only when no CLAUDE.md exists in or above the folder. If you have a CLAUDE.md, put @AGENTS.md on its first line.
CursorReads AGENTS.md from the project root, in the desktop app and the terminal. In the app, rules in .cursor/rules must be .mdc files. The terminal reads only plain .md files there.
CodexReads AGENTS.md from the root down to the folder you are in, with a shared 32 KiB limit across all of them.
GitHub CopilotReads AGENTS.md on some surfaces only. Keep a .github/copilot-instructions.md as well if your team relies on Copilot.

Details and sources: the AGENTS.md compatibility matrix.

What agents get wrong in Flask projects

These are the reasons the “Rules for agents” section says what it says.

A global app object

Tutorials start with app = Flask(__name__) at module level, and agents copy that. It causes circular imports as soon as there are two files, and tests cannot get a clean app.

Everything in one file

An agent asked for a new feature appends routes to whichever file is open. The template sends each feature to its own blueprint.

Trusting request.json

Agents read keys straight off the request and get a 500 on the first malformed body. The template requires validation at the edge.

Debug mode and secrets in code

app.run(debug=True) and a hardcoded SECRET_KEY appear in generated code because the quickstart has them. Debug mode on a public server lets a visitor run code on it.

Questions

Where does AGENTS.md go in a Flask project?

In the root of the repository, next to your manifest file. Tools read it from the folder you start them in and, for most tools, from parent folders too.

Does Claude Code read AGENTS.md?

Only when there is no CLAUDE.md in or above the working folder. If you already have a CLAUDE.md, keep it and make its first line @AGENTS.md so both tools read the same rules.

How long should the file be?

Short enough that every line is something the agent would get wrong without it. Codex shares a 32 KiB budget across all the AGENTS.md files it loads, and long files get followed less closely by every tool.

Is this right for a small Flask script?

For a single-file tool, delete the factory and blueprint rules and keep the commands and the validation rule. The structure rules matter once the app has more than a handful of routes.

Templates for other stacks

Next.jsReactNode.js and TypeScriptExpressPythonFastAPIDjangoGoRuby on RailsLaravelVueSvelteKitAstroNestJSFastifyHonoRustElectronSupabase