From 91454e27d7533ec0b84f51b6dd4ad135fb8d2b2e Mon Sep 17 00:00:00 2001 From: Kevin Turcios Date: Fri, 6 Feb 2026 01:53:04 -0500 Subject: [PATCH 1/4] fix: add verification step to CI Claude workflow to prevent hallucinated fixes The PR review bot was claiming lint issues were fixed without actually fixing or committing them. Add a mandatory re-run of prek after fixes and explicit instructions to report unfixed issues honestly. --- .github/workflows/claude.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index 2c249bad7..bb0c8c17d 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -62,6 +62,7 @@ jobs: If there are prek issues: - For SAFE auto-fixable issues (formatting, import sorting, trailing whitespace, etc.), run `uv run prek run --from-ref origin/main` again to auto-fix them + - For issues that prek cannot auto-fix, do NOT attempt to fix them manually — report them as remaining issues in your summary If there are mypy issues: - Fix type annotation issues (missing return types, Optional/None unions, import errors for type hints, incorrect types) @@ -72,6 +73,11 @@ jobs: - Commit with message "style: auto-fix linting issues" or "fix: resolve mypy type errors" as appropriate - Push the changes with `git push` + IMPORTANT - Verification after fixing: + - After committing fixes, run `uv run prek run --from-ref origin/main` ONE MORE TIME to verify all issues are resolved + - If errors remain, either fix them or report them honestly as unfixed in your summary + - NEVER claim issues are fixed without verifying. If you cannot fix an issue, say so + Do NOT attempt to fix: - Type errors that require logic changes or refactoring - Complex generic type issues From ee5871d3d31cf681243fa2a5c524525a29ecaeda Mon Sep 17 00:00:00 2001 From: Kevin Turcios Date: Fri, 6 Feb 2026 02:12:27 -0500 Subject: [PATCH 2/4] feat: add modular Claude Code rules in .claude/rules/ Split monolithic CLAUDE.md instructions into focused, topic-specific rule files. Path-scoped rules for source code and tests only load when working with matching files. --- .claude/rules/architecture.md | 23 ++++++++++++++++ .claude/rules/code-style.md | 9 +++++++ .claude/rules/git.md | 6 +++++ .claude/rules/source-code.md | 11 ++++++++ .claude/rules/testing.md | 15 +++++++++++ .gitignore | 4 +++ CLAUDE.md | 49 ----------------------------------- 7 files changed, 68 insertions(+), 49 deletions(-) create mode 100644 .claude/rules/architecture.md create mode 100644 .claude/rules/code-style.md create mode 100644 .claude/rules/git.md create mode 100644 .claude/rules/source-code.md create mode 100644 .claude/rules/testing.md diff --git a/.claude/rules/architecture.md b/.claude/rules/architecture.md new file mode 100644 index 000000000..a12144452 --- /dev/null +++ b/.claude/rules/architecture.md @@ -0,0 +1,23 @@ +# Architecture + +``` +codeflash/ +├── main.py # CLI entry point +├── cli_cmds/ # Command handling, console output (Rich) +├── discovery/ # Find optimizable functions +├── context/ # Extract code dependencies and imports +├── optimization/ # Generate optimized code via AI +│ ├── optimizer.py # Main optimization orchestration +│ └── function_optimizer.py # Per-function optimization logic +├── verification/ # Run deterministic tests (pytest plugin) +├── benchmarking/ # Performance measurement +├── github/ # PR creation +├── api/ # AI service communication +├── code_utils/ # Code parsing, git utilities +├── models/ # Pydantic models and types +├── tracing/ # Function call tracing +├── lsp/ # IDE integration (Language Server Protocol) +├── telemetry/ # Sentry, PostHog +├── either.py # Functional Result type for error handling +└── result/ # Result types and handling +``` diff --git a/.claude/rules/code-style.md b/.claude/rules/code-style.md new file mode 100644 index 000000000..fcad0f253 --- /dev/null +++ b/.claude/rules/code-style.md @@ -0,0 +1,9 @@ +# Code Style + +- **Line length**: 120 characters +- **Python**: 3.9+ syntax +- **Tooling**: Ruff for linting/formatting, mypy strict mode, prek for pre-commit checks +- **Comments**: Minimal - only explain "why", not "what" +- **Docstrings**: Do not add unless explicitly requested +- **Naming**: NEVER use leading underscores (`_function_name`) - Python has no true private functions, use public names +- **Paths**: Always use absolute paths, handle encoding explicitly (UTF-8) diff --git a/.claude/rules/git.md b/.claude/rules/git.md new file mode 100644 index 000000000..058e8ca80 --- /dev/null +++ b/.claude/rules/git.md @@ -0,0 +1,6 @@ +# Git Commits & Pull Requests + +- Use conventional commit format: `fix:`, `feat:`, `refactor:`, `docs:`, `test:`, `chore:` +- Keep commits atomic - one logical change per commit +- Commit message body should be concise (1-2 sentences max) +- PR titles should also use conventional format diff --git a/.claude/rules/source-code.md b/.claude/rules/source-code.md new file mode 100644 index 000000000..be7c74059 --- /dev/null +++ b/.claude/rules/source-code.md @@ -0,0 +1,11 @@ +--- +paths: + - "codeflash/**/*.py" +--- + +# Source Code Rules + +- Use libcst, not ast - always use `libcst` for code parsing/modification to preserve formatting. +- NEVER use leading underscores for function names (e.g., `_helper`). Python has no true private functions. Always use public names. +- Any new feature or bug fix that can be tested automatically must have test cases. +- If changes affect existing test expectations, update the tests accordingly. Tests must always pass after changes. diff --git a/.claude/rules/testing.md b/.claude/rules/testing.md new file mode 100644 index 000000000..809a4ea91 --- /dev/null +++ b/.claude/rules/testing.md @@ -0,0 +1,15 @@ +--- +paths: + - "tests/**" + - "codeflash/**/*test*.py" +--- + +# Testing Conventions + +- Code context extraction and replacement tests must always assert for full string equality, no substring matching. +- Use pytest's `tmp_path` fixture for temp directories (it's a `Path` object). +- Write temp files inside `tmp_path`, never use `NamedTemporaryFile` (causes Windows file contention). +- Always call `.resolve()` on Path objects to ensure absolute paths and resolve symlinks. +- Use `.as_posix()` when converting resolved paths to strings (normalizes to forward slashes). +- Any new feature or bug fix that can be tested automatically must have test cases. +- If changes affect existing test expectations, update the tests accordingly. Tests must always pass after changes. diff --git a/.gitignore b/.gitignore index 99219de86..b80ab3816 100644 --- a/.gitignore +++ b/.gitignore @@ -258,6 +258,10 @@ WARP.MD .mcp.json .tessl/ tessl.json + +# Claude Code - track shared rules, ignore local config +.claude/* +!.claude/rules/ **/node_modules/** **/dist-nuitka/** **/.npmrc diff --git a/CLAUDE.md b/CLAUDE.md index 94ca7e6e0..fdc1b943b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -33,55 +33,6 @@ uv run codeflash init # Initialize in a project uv run codeflash --all # Optimize entire codebase ``` -## Architecture - -``` -codeflash/ -├── main.py # CLI entry point -├── cli_cmds/ # Command handling, console output (Rich) -├── discovery/ # Find optimizable functions -├── context/ # Extract code dependencies and imports -├── optimization/ # Generate optimized code via AI -│ ├── optimizer.py # Main optimization orchestration -│ └── function_optimizer.py # Per-function optimization logic -├── verification/ # Run deterministic tests (pytest plugin) -├── benchmarking/ # Performance measurement -├── github/ # PR creation -├── api/ # AI service communication -├── code_utils/ # Code parsing, git utilities -├── models/ # Pydantic models and types -├── tracing/ # Function call tracing -├── lsp/ # IDE integration (Language Server Protocol) -├── telemetry/ # Sentry, PostHog -├── either.py # Functional Result type for error handling -└── result/ # Result types and handling -``` - -### Key Rules to follow - -- Use libcst, not ast - For Python, always use `libcst` for code parsing/modification to preserve formatting. -- Code context extraction and replacement tests must always assert for full string equality, no substring matching. -- Any new feature or bug fix that can be tested automatically must have test cases. -- If changes affect existing test expectations, update the tests accordingly. Tests must always pass after changes. -- NEVER use leading underscores for function names (e.g., `_helper`). Python has no true private functions. Always use public names. - -## Code Style - -- **Line length**: 120 characters -- **Python**: 3.9+ syntax -- **Tooling**: Ruff for linting/formatting, mypy strict mode, prek for pre-commit checks -- **Comments**: Minimal - only explain "why", not "what" -- **Docstrings**: Do not add unless explicitly requested -- **Naming**: NEVER use leading underscores (`_function_name`) - Python has no true private functions, use public names -- **Paths**: Always use absolute paths, handle encoding explicitly (UTF-8) - -## Git Commits & Pull Requests - -- Use conventional commit format: `fix:`, `feat:`, `refactor:`, `docs:`, `test:`, `chore:` -- Keep commits atomic - one logical change per commit -- Commit message body should be concise (1-2 sentences max) -- PR titles should also use conventional format - # Agent Rules From 308507c7c874653ce03726c61b59a9916da7b843 Mon Sep 17 00:00:00 2001 From: Kevin Turcios Date: Fri, 6 Feb 2026 02:18:43 -0500 Subject: [PATCH 3/4] cleanup --- .claude/rules/architecture.md | 7 ++++++- .claude/rules/source-code.md | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.claude/rules/architecture.md b/.claude/rules/architecture.md index a12144452..cc53dac0f 100644 --- a/.claude/rules/architecture.md +++ b/.claude/rules/architecture.md @@ -15,9 +15,14 @@ codeflash/ ├── api/ # AI service communication ├── code_utils/ # Code parsing, git utilities ├── models/ # Pydantic models and types +├── languages/ # Multi-language support (Python, JavaScript/TypeScript) +├── setup/ # Config schema, auto-detection, first-run experience +├── picklepatch/ # Serialization/deserialization utilities ├── tracing/ # Function call tracing +├── tracer.py # Root-level tracer entry point for profiling ├── lsp/ # IDE integration (Language Server Protocol) ├── telemetry/ # Sentry, PostHog ├── either.py # Functional Result type for error handling -└── result/ # Result types and handling +├── result/ # Result types and handling +└── version.py # Version information ``` diff --git a/.claude/rules/source-code.md b/.claude/rules/source-code.md index be7c74059..27c939642 100644 --- a/.claude/rules/source-code.md +++ b/.claude/rules/source-code.md @@ -5,7 +5,7 @@ paths: # Source Code Rules -- Use libcst, not ast - always use `libcst` for code parsing/modification to preserve formatting. +- Use `libcst` for code modification/transformation to preserve formatting. `ast` is acceptable for read-only analysis and parsing. - NEVER use leading underscores for function names (e.g., `_helper`). Python has no true private functions. Always use public names. - Any new feature or bug fix that can be tested automatically must have test cases. - If changes affect existing test expectations, update the tests accordingly. Tests must always pass after changes. From 2847edc7194409898e92231fe76a8281b224be40 Mon Sep 17 00:00:00 2001 From: Kevin Turcios Date: Fri, 6 Feb 2026 02:28:02 -0500 Subject: [PATCH 4/4] feat: upgrade Claude GHA to Opus 4.6 --- .github/workflows/claude.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index bb0c8c17d..5c89e6ea7 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -173,7 +173,7 @@ jobs: 2. For each optimization PR: - Check if CI is passing: `gh pr checks ` - If all checks pass, merge it: `gh pr merge --squash --delete-branch` - claude_args: '--allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*),Bash(gh pr checks:*),Bash(gh pr merge:*),Bash(gh issue view:*),Bash(gh issue list:*),Bash(gh api:*),Bash(uv run prek *),Bash(uv run mypy *),Bash(uv run coverage *),Bash(uv run pytest *),Bash(git status*),Bash(git add *),Bash(git commit *),Bash(git push*),Bash(git diff *),Bash(git checkout *),Read,Glob,Grep,Edit"' + claude_args: '--model claude-opus-4-6 --allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*),Bash(gh pr checks:*),Bash(gh pr merge:*),Bash(gh issue view:*),Bash(gh issue list:*),Bash(gh api:*),Bash(uv run prek *),Bash(uv run mypy *),Bash(uv run coverage *),Bash(uv run pytest *),Bash(git status*),Bash(git add *),Bash(git commit *),Bash(git push*),Bash(git diff *),Bash(git checkout *),Read,Glob,Grep,Edit"' additional_permissions: | actions: read env: @@ -245,7 +245,7 @@ jobs: uses: anthropics/claude-code-action@v1 with: use_foundry: "true" - claude_args: '--allowedTools "Read,Edit,Write,Glob,Grep,Bash(git status*),Bash(git diff*),Bash(git add *),Bash(git commit *),Bash(git push*),Bash(git log*),Bash(git merge*),Bash(git fetch*),Bash(git checkout*),Bash(git branch*),Bash(uv run prek *),Bash(prek *),Bash(uv run ruff *),Bash(uv run pytest *),Bash(uv run mypy *),Bash(uv run coverage *),Bash(gh pr comment*),Bash(gh pr view*),Bash(gh pr diff*),Bash(gh pr merge*),Bash(gh pr close*)"' + claude_args: '--model claude-opus-4-6 --allowedTools "Read,Edit,Write,Glob,Grep,Bash(git status*),Bash(git diff*),Bash(git add *),Bash(git commit *),Bash(git push*),Bash(git log*),Bash(git merge*),Bash(git fetch*),Bash(git checkout*),Bash(git branch*),Bash(uv run prek *),Bash(prek *),Bash(uv run ruff *),Bash(uv run pytest *),Bash(uv run mypy *),Bash(uv run coverage *),Bash(gh pr comment*),Bash(gh pr view*),Bash(gh pr diff*),Bash(gh pr merge*),Bash(gh pr close*)"' additional_permissions: | actions: read env: