

INFO

``WARNING
bash
curl -fsSL https://claude.ai/install.sh | bash
cd your-project
claude
bash
irm https://claude.ai/install.ps1 | iex
cd your-project
claudewindows CMD安装
bash
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd

``
``


INFO
``
INFO
plain
帮我修复创建任务接口。plain
POST /tasks 在 title 为空时没有返回 422。
请按工具调用闭环处理:
1. 先观察:读取 tests/api/test_tasks.py、src/my_api/api/tasks.py、src/my_api/schemas/task.py,不要改文件。
2. 再定位:用 grep 搜索项目里类似 TaskCreate / UserCreate 的 Pydantic 校验写法。
3. 给计划:说明最小修改点和你不会修改哪些文件。
4. 我确认后再修改。
5. 修改后运行:uv run pytest tests/api/test_tasks.py。
6. 如果测试失败,只根据失败日志定点修复,不要跳过测试或放宽断言。
7. 最终输出:修改文件、根因、验证命令、未验证风险。
如果需要改 ORM model、alembic migration、依赖或全局错误处理,先停止并问我。
plain
FAILED tests/api/test_tasks.py::test_create_task_rejects_empty_title
E AssertionError: assert 201 == 422plain
````# src/my_api/schemas/task.py
from pydantic import BaseModel, ConfigDict, Field
class TaskCreate(BaseModel):
title: str = Field(..., min_length=1, max_length=120)
description: str | None = Field(default=None, max_length=1000)
DANGER
``INFO

``plain
# CLAUDE.md
## Project
- Python 3.12
- FastAPI
- SQLAlchemy 2.0 async ORM
- Pydantic v2
- pytest + pytest-asyncio
- ruff + mypy
- uv is the package manager
## Commands
- Install dependencies: uv sync
- Run lint: uv run ruff check .
- Run type check: uv run mypy src/my_api
- Run all tests: uv run pytest
- Run API tests: uv run pytest tests/api
- Run a single test: uv run pytest tests/api/test_tasks.py -k "create_task"
## Architecture
- src/my_api/api/: FastAPI routers. Parse HTTP input and return response schemas.
- src/my_api/service/: business orchestration and transaction boundaries.
- src/my_api/repo/: SQLAlchemy queries. Repos do not commit transactions.
- src/my_api/schemas/: Pydantic request and response models.
- src/my_api/models/: SQLAlchemy ORM models.
- tests/api/: black-box API tests through httpx AsyncClient.
- tests/service/: service-level tests with mocked repos or test database.
## Coding Rules
- Routers must not import ORM models directly.
- Routers call services; services call repos.
- Repos must not call session.commit(); transaction ownership stays in service layer.
- Use Pydantic v2 APIs. Do not add v1-style validators unless existing code requires it.
- Do not add dependencies without user approval.
- Do not edit Alembic migrations unless the task explicitly asks for schema migration.
- Do not weaken tests to make them pass.
## Verification Policy
- For schema/API changes, run: uv run pytest tests/api
- For service changes, run the relevant service tests and API regression tests.
- Before final answer, show changed files, root cause, verification command, and remaining risk.
- If verification cannot be run, explain the exact blocker instead of claiming success.INFO
``````
````
plain
``---
paths:
- "src/my_api/api/**/*.py"
- "src/my_api/schemas/**/*.py"
---
# API Rules
- New endpoints must include request validation and response schema.
- Route handlers should stay thin: parse input, call service, map response.
- Do not import SQLAlchemy ORM models from router files.
- For request validation changes, add or update tests under tests/api/.plain
``---
paths:
- "tests/**/*.py"
---
# Testing Rules
- Prefer behavior assertions over implementation assertions.
- API tests should use httpx AsyncClient.
- Do not skip a failing test unless the user explicitly approves.
- When fixing flaky tests, identify whether the cause is time, order, network, database state, or async scheduling.DANGER
````
- ``
- ````
````
plain
````````---
name: python-api-review
description: Review FastAPI API changes for layering, validation, transactions, tests, and backward compatibility. Use when API routes, schemas, services, or repos changed.
allowed-tools: Read Grep Bash(git diff *) Bash(uv run ruff check *) Bash(uv run pytest tests/api*)
---
# Python API Review Skill
Use this skill to review API-related changes in this repository.
## Steps
1. Inspect the diff first:
- git diff -- src/my_api tests/api
2. Check routing boundaries:
- routers call service layer
- routers do not import ORM models directly
3. Check Pydantic v2 schemas:
- request models validate required fields
- response models do not leak internal ORM fields
4. Check transaction ownership:
- service owns commit/rollback
- repo only executes queries
5. Check tests:
- API behavior tests cover success and validation errors
- do not weaken existing assertions
6. Run or suggest verification:
- uv run ruff check .
- uv run pytest tests/api
7. Final report:
- changed files
- correctness risks
- missing tests
- commands run and results
``

plain
请不要全仓库泛读。按下面顺序收集上下文:
1. 读取根 CLAUDE.md,确认 Python 版本、分层规则、测试命令。
2. 读取匹配 src/my_api/api/**/*.py 和 tests/**/*.py 的 rules。
3. 用 grep 搜索:TaskCreate、create_task、TaskOut、类似 UserCreate 的校验写法。
4. 只读取这些文件:
- src/my_api/api/tasks.py
- src/my_api/schemas/task.py
- src/my_api/service/tasks.py
- tests/api/test_tasks.py
5. 输出调用链摘要和最小修改计划,不要立即改文件。
6. 如果需要读取更多文件,先说明为什么。
INFO

``````plain
``{
"$schema": "https://json.schemastore.org/claude-code-settings.json",
"permissions": {
"allow": [
"Bash(npm run lint)",
"Bash(npm run test *)"
],
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./secrets/**)",
"Bash(curl *)"
]
},
"env": {
"CLAUDE_CODE_ENABLE_TELEMETRY": "1",
"OTEL_METRICS_EXPORTER": "otlp"
}
}

``````

评论与讨论
如果这篇文章对你有帮助,或你对实现细节有不同判断,可以直接在这里继续讨论。