Configure automatic API linting when working with AI coding assistants and git pre-commit hooks.
Hooks enable automatic API style checking in two contexts:
- AI Assistants - Auto-lint when you save OpenAPI files in Claude Code, Cursor, or Windsurf
- Git Pre-Commit - Block commits that contain API style violations
| Assistant | Config File | Events |
|---|---|---|
| Claude Code | .claude/settings.json |
16 events |
| Cursor | .cursor/hooks.json |
12 events |
| Windsurf | .windsurf/hooks.json |
9 events |
# Generate hooks for Claude Code
api-style hooks --format claude
# Generate for all assistants
api-style hooks --format all
# See supported formats
api-style hooks list
# Install git pre-commit hook
api-style hooks initAutomatically lint OpenAPI files when they're saved:
api-style hooks --format claude --auto-lintThis creates a hook that:
- Triggers when files are written (Edit/Write tools)
- Checks if the file matches OpenAPI patterns
- Runs
mcp-api-style lintif it matches - Returns violations to the assistant
Matched Patterns:
openapi.yaml,openapi.yml,openapi.jsonswagger.yaml,swagger.yml,swagger.json**/openapi.yaml,**/api.yaml, etc.
Inject API style guidelines before prompts:
api-style hooks --format claude --inject-contextThis adds context about the active style profile to help the AI assistant write better APIs.
| Option | Default | Description |
|---|---|---|
--format |
claude |
Target assistant |
--profile |
default |
Style profile for linting |
--auto-lint |
true |
Enable auto-lint on save |
--inject-context |
false |
Inject style context |
--output |
auto | Output file path |
.claude/settings.json:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "#!/bin/bash\nFILE=\"$CLAUDE_FILE_PATH\"\n...",
"timeout": 30
}
]
}
]
}
}.cursor/hooks.json:
{
"hooks": {
"after_file_write": [
{
"pattern": "Write|Edit",
"actions": [
{
"type": "shell",
"command": "mcp-api-style lint ...",
"timeout": 30000
}
]
}
]
}
}.windsurf/hooks.json:
{
"hooks": {
"onFileSave": [
{
"glob": "**/*.yaml",
"command": "mcp-api-style lint ..."
}
]
}
}For hooks to work, the mcp-api-style binary must be in your PATH:
go install github.com/plexusone/systemspec-apistyle/cmd/mcp-api-style@latestAdd to .claude/settings.json:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "mcp-api-style lint -f \"$CLAUDE_FILE_PATH\" -p default 2>&1 | head -50",
"timeout": 30
}
]
}
]
}
}For full integration, combine hooks with the MCP server:
- Configure MCP server in settings
- Generate hooks for auto-linting
- AI assistant can use both automatic checks and on-demand tools
-
Setup:
api-style hooks --format claude
-
Working with Claude:
- Ask Claude to create an OpenAPI spec
- When Claude writes the file, hooks run automatically
- Violations appear in the conversation
- Claude can fix issues immediately
-
On-Demand Tools:
- "Use the lint tool to check this against Azure guidelines"
- "Explain rule URI-001"
- "Run analyze for a GO/NO-GO decision"
- Verify the config file exists in the correct location
- Check that
mcp-api-styleis in PATH - Ensure the file matches OpenAPI patterns
Increase the timeout in the generated config:
{
"timeout": 60
}Ensure the profile name is valid:
mcp-api-style list-profilesInstall a git pre-commit hook that lints staged OpenAPI files before each commit:
api-style hooks init- When you run
git commit, the hook triggers - It finds staged files matching OpenAPI patterns (
openapi.yaml,swagger.json, etc.) - Each file is linted using
api-style lint - If errors are found, the commit is blocked
- Warnings are displayed but don't block commits
# Use Azure profile
api-style hooks init --profile azure
# Enforce silver conformance level
api-style hooks init --level silver
# Overwrite existing hook
api-style hooks init --forceFor emergency commits, bypass the hook with:
git commit --no-verifyRemove the hook manually:
rm .git/hooks/pre-commit- MCP Server - Full MCP integration
- CLI Reference - Command documentation