Back to catalogue
ValidationPostToolUse· Write|EditPostToolUseAfter tool execution · non-blocking· non-blocking
Pyright type checking
Runs pyright via uv on the modified .py file and reports type errors to the agent so they are fixed within the same loop.
Use cases
- Strict typing in Python projects with pyright
- Catch type mismatches immediately after an edit
- Pair with ruff for a complete Python quality pipeline
Providers & tags
Claude Code
#validation#pyright#typecheck#python#quality
settings.json fragment
{
"hooks": {
"PostToolUse": [
{
"hooks": [
{
"command": "node $CLAUDE_PROJECT_DIR/.claude/hooks/pyright-check.mjs",
"type": "command"
}
],
"matcher": "Write|Edit"
}
]
}
}Script · .claude/hooks/pyright-check.mjs
#!/usr/bin/env node
import { readFileSync } from 'fs';
import { execSync } from 'child_process';
const input = JSON.parse(readFileSync(0, 'utf8'));
const filePath = input.tool_input?.file_path ?? input.tool_input?.path ?? '';
if (!filePath.endsWith('.py')) process.exit(0);
try {
execSync(`uv run pyright "${filePath}"`, {
encoding: 'utf8',
timeout: 30_000,
stdio: 'pipe',
});
} catch (e) {
if (e.stdout) process.stderr.write(`[pyright] ${e.stdout}\n`);
}