Skip to content

Commit 2c4989c

Browse files
authored
Merge pull request #1917 from codeflash-ai/cf-claude-code-hooks
feat: add Claude Code post-edit lint hook
2 parents 928cbfb + 2e9ce93 commit 2c4989c

9 files changed

Lines changed: 948 additions & 578 deletions

File tree

.claude/hooks/post-edit-lint.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
# Everyone is on macOS so this should be fine, we don't account for Windows
3+
set -euo pipefail
4+
5+
input=$(cat)
6+
file_path=$(echo "$input" | jq -r '.tool_input.file_path // empty')
7+
8+
if [[ -z "$file_path" || ! -f "$file_path" ]]; then
9+
exit 0
10+
fi
11+
12+
if [[ "$file_path" == *.py ]]; then
13+
uv run prek --files "$file_path" 2>/dev/null || true
14+
fi

.claude/rules/code-style.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,3 @@
1111
- **Paths**: Always use absolute paths
1212
- **Encoding**: Always pass `encoding="utf-8"` to `open()`, `read_text()`, `write_text()`, etc. in new or changed code — Windows defaults to `cp1252` which breaks on non-ASCII content. Don't flag pre-existing code that lacks it unless you're already modifying that line.
1313
- **Verification**: Use `uv run prek` to verify code — it handles ruff, ty, mypy in one pass. Don't run `ruff`, `mypy`, or `python -c "import ..."` separately; `prek` is the single verification command
14-
- **Pre-commit**: Run `uv run prek` before committing — fix any issues before creating the commit
15-
- **Pre-push**: Before pushing, run `uv run prek run --from-ref origin/<base>` to check all changed files against the PR base — this matches CI behavior and catches issues that per-commit prek misses. To detect the base branch: `gh pr view --json baseRefName -q .baseRefName 2>/dev/null || echo main`

.claude/rules/git.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
- Commit message body should be concise (1-2 sentences max)
1010
- Merge for simple syncs, rebase when branches have diverged significantly
1111
- When committing to an external/third-party repo, follow that repo's own conventions for versioning, changelog, and CI
12+
- Pre-commit: Run `uv run prek` before committing — fix any issues before creating the commit
13+
- Pre-push: Run `uv run prek run --from-ref origin/<base>` to check all changed files against the PR base — this matches CI behavior and catches issues that per-commit prek misses. To detect the base branch: `gh pr view --json baseRefName -q .baseRefName 2>/dev/null || echo main`
1214

1315
## Pull Requests
1416
- PR titles should use conventional format

.claude/rules/workflow.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Workflow
2+
3+
## Code Changes
4+
- Before making any changes, outline your approach in 3-5 numbered steps. Include which repo/branch you'll work in, what commands you'll run, and what success looks like. Wait for approval before starting
5+
6+
## Response Style
7+
- When listing items (PRs, functions, optimization targets), always provide the complete list ordered by priority on the first attempt. Do not give partial lists
8+
9+
## Commands
10+
- When running long-running commands (benchmarks, profiling, optimizers like codeflash), always run them in the foreground. Do not use background processes
11+
12+
## Debugging
13+
- When claiming something is a pre-existing issue (e.g., test failures on main), verify by checking out main and running the tests before making that claim

.claude/settings.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"hooks": {
3+
"PostToolUse": [
4+
{
5+
"matcher": "Edit|Write",
6+
"hooks": [
7+
{
8+
"type": "command",
9+
"command": ".claude/hooks/post-edit-lint.sh",
10+
"timeout": 30
11+
}
12+
]
13+
}
14+
]
15+
}
16+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ tessl.json
269269
# Claude Code - track shared rules, ignore local config
270270
.claude/*
271271
!.claude/rules/
272+
!.claude/settings.json
273+
!.claude/hooks/
272274
**/node_modules/**
273275
**/dist-nuitka/**
274276
**/.npmrc

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.15.0
3+
rev: v0.15.8
44
hooks:
55
# Run the linter.
66
- id: ruff-check

CLAUDE.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ CodeFlash is an AI-powered code optimizer that automatically improves performanc
1010
Discovery → Ranking → Context Extraction → Test Gen + Optimization → Baseline → Candidate Evaluation → PR
1111
```
1212

13-
1. **Discovery** (`discovery/`): Find optimizable functions across the codebase
14-
2. **Ranking** (`benchmarking/function_ranker.py`): Rank functions by addressable time using trace data
15-
3. **Context** (`languages/<lang>/context/`): Extract code dependencies (read-writable code + read-only imports)
16-
4. **Optimization** (`optimization/`, `api/`): Generate candidates via AI service, run in parallel with test generation
17-
5. **Verification** (`verification/`): Run candidates against tests, compare outputs via custom pytest plugin
18-
6. **Benchmarking** (`benchmarking/`): Measure performance, select best candidate by speedup
19-
7. **Result** (`result/`, `github/`): Create PR with winning optimization
13+
See `.claude/rules/architecture.md` for directory mapping and entry points.
2014

2115
# Instructions
2216
- **Bug fix workflow** — follow these steps in order, do not skip ahead:

uv.lock

Lines changed: 899 additions & 568 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)