◉CLAUDE LABJP
●CC 2.1.330 — Claude Code 2.1.330 fixes the multi-minute freeze right after compacting a long conversation●SONNET 4.5 — Sonnet 4.5 retires from the Claude API on 11/30, 8 days left. The suggested replacement is claude-sonnet-5-5●MCP 401 — Users report MCP servers that return 401 time out silently instead of showing an error●NEW — New: Desktop creates a worktree for every session? Three places to check●OPUS 4.5 — The 11/24 date for Opus 4.5 is a not-sooner-than floor, not a retirement notice●SCHEMA — Same schema, different shape: compare structured output from the Agent SDK and the Messages API●CC 2.1.330 — Claude Code 2.1.330 fixes the multi-minute freeze right after compacting a long conversation●SONNET 4.5 — Sonnet 4.5 retires from the Claude API on 11/30, 8 days left. The suggested replacement is claude-sonnet-5-5●MCP 401 — Users report MCP servers that return 401 time out silently instead of showing an error●NEW — New: Desktop creates a worktree for every session? Three places to check●OPUS 4.5 — The 11/24 date for Opus 4.5 is a not-sooner-than floor, not a retirement notice●SCHEMA — Same schema, different shape: compare structured output from the Agent SDK and the Messages API
Articles/Claude Code
⟐ Claude Code/2026-04-07Advanced

Claude Code × Python FastAPI in Production — Architecture, pytest, and Docker Deployment

Building production-ready Python FastAPI servers with Claude Code as an AI pair programmer — Pydantic v2, pytest automation, Docker, and CI/CD, with working code at each step.

Claude Code291Python32FastAPIpytestDocker5API DevelopmentBackend4Production23

✦ Premium Article

A week after adding Redis caching to one of my side-project APIs, the response-time graph looked exactly the same as before. No errors. Nothing unusual in the logs. The cache simply never hit once.

The cause was the cache key. The decorator built it from str(kwargs), and kwargs carried the injected database session — whose default repr contains a memory address. Every request produced a different key. Redis had become a write-only warehouse.

FastAPI is fast, type-safe, and pleasant to write async code in, and pairing it with Claude Code gets a production skeleton standing in remarkably little time. But code that looks like it works tends to settle in quiet places like that one.

What follows is the workflow for building a production FastAPI server with Claude Code, organized around implementation patterns — plus the defects this workflow tends to produce, each one run locally and measured rather than guessed at. As an indie developer shipping alone, I have found that generating faster and distrusting the output are not competing habits. They fund each other.

Written with one situation in mind: you know Python and FastAPI well enough, but stall just before production-grade architecture, testing, and deployment.


Prerequisites and Setup

Required Environment

  • Python 3.12+
  • Claude Code CLI (latest version)
  • Docker Desktop
  • Git

For Claude Code installation and initial setup, see the Claude Code Project Initialization Automation Guide.

Project Structure Overview

Here's the production project layout we'll build:

fastapi-app/
├── CLAUDE.md              # Design guidelines for Claude Code
├── app/
│   ├── main.py            # FastAPI application entry point
│   ├── api/
│   │   └── v1/
│   │       ├── router.py  # API v1 router
│   │       ├── users.py   # User endpoints
│   │       └── items.py   # Item endpoints
│   ├── core/
│   │   ├── config.py      # Environment and settings management
│   │   ├── security.py    # Auth and JWT
│   │   └── database.py    # SQLAlchemy async session management
│   ├── models/
│   │   ├── user.py        # SQLAlchemy models
│   │   └── item.py
│   └── schemas/
│       ├── user.py        # Pydantic v2 schemas
│       └── item.py
├── tests/
│   ├── conftest.py        # pytest fixtures
│   ├── unit/
│   └── integration/
├── Dockerfile
├── docker-compose.yml
└── .github/workflows/ci.yml

CLAUDE.md Design — Giving Your AI the Right Context

The quality of code Claude Code generates depends directly on how well it understands your project. CLAUDE.md is your technical specification document for Claude Code — the difference between getting generic boilerplate and production-quality code.

Writing an Effective CLAUDE.md

Place this file at the root of your project:

# FastAPI Production API — CLAUDE.md
 
## Technology Stack
- Python 3.12 / FastAPI 0.115+ / Uvicorn
- SQLAlchemy 2.0 (async) + asyncpg (PostgreSQL)
- Pydantic v2 (strict validation mode)
- JWT authentication (python-jose + passlib bcrypt)
- pytest-asyncio + httpx (async testing)
- Docker + docker-compose
 
## Coding Standards
- All functions and classes must have full type hints
- Use async/await consistently — never mix sync and async code
- All endpoint response models must be defined with Pydantic schemas
- Database sessions must be obtained via Depends() dependency injection
- HTTPExceptions are centralized in app/core/exceptions.py
 
## Testing Standards
- Write pytest tests alongside every new feature
- Unit tests: pure functions in app/core/
- Integration tests: use real DB (in-memory SQLite for tests)
- Coverage target: 80% minimum
 
## Prohibited Patterns
- Global mutable state
- print() debugging (use logging module)
- Hardcoded credentials (environment variables only)

With this context in place, Claude Code will automatically know to use async SQLAlchemy, write pytest-asyncio tests, and maintain type safety throughout — without needing to be reminded on every prompt.


✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦Learn the exact prompting strategies to use Claude Code for accelerating FastAPI project design, coding, and testing
✦Master the full production workflow — pytest, Docker, GitHub Actions CI/CD — with working code you can use immediately
✦Discover how to combine Claude Code's multi-agent and Hooks features to automatically maintain backend API quality
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

⟐ Claude Code2026-10-27
Counting How Often Claude Code Ships, Straight from npm's Publish History
How many Claude Code versions ship per week, and how many hours apart? A 37-line Python script reads npm's publish history to count weekly releases and the median gap, including the empty-week trap and why a Tuesday run makes this week look quiet.
⟐ Claude Code2026-10-15
The Hook That Was Meant to Guard My Japanese Folder Never Blocked Anything — Python Was Reading stdin as cp932
A PreToolUse hook guarding folders like 経理 or 議事録 silently lets edits through when Python's stdin defaults to cp932. How I reproduced it, the three-line fix, and one command to check your own hooks.
⟐ Claude Code2026-09-29
Two Default-Model Changes Haven't Reached Claude Code's Stable Channel Yet
This morning, Claude Code's stable channel sat 6 releases and 10 days behind latest. A small standard-library Python script that counts the gap in real, published releases instead of version arithmetic, and lists what hasn't arrived yet with a headline for each.