Add Claude Code hooks and project documentation#6
Add Claude Code hooks and project documentation#63x3by3 wants to merge 3 commits intofrankiejun:mainfrom
Conversation
Adds a PreToolUse hook that prevents Claude from accidentally editing files containing .env, secrets, or .git/ paths. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds a PostToolUse hook that runs py_compile after any Edit or Write to a .py file, catching syntax errors immediately. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Documents commands, architecture, key classes, required secrets, and gotchas for the ClawCloud auto-login project. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello @3x3by3, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the project's development environment by integrating automated checks and comprehensive documentation. It introduces Claude Code hooks to enforce security policies by blocking edits to sensitive files and improves code quality by automatically linting Python files. Additionally, it provides detailed guidance on the ClawCloud Auto-Login system, making it easier for developers to understand and maintain. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces Claude Code hooks to automate certain development tasks and adds project documentation. The PreToolUse hook prevents edits to sensitive files, and the PostToolUse hook automatically lints Python files on save.
My review focuses on the implementation of these hooks in .claude/settings.json. I've identified a critical syntax error in the PostToolUse hook that will prevent it from running. I've also provided suggestions to improve the readability and maintainability of the hook commands by simplifying them and recommending they be moved to separate script files for easier management in the long run. The new documentation in CLAUDE.md is clear and provides a good overview of the project.
| "hooks": [ | ||
| { | ||
| "type": "command", | ||
| "command": "python -c \"import sys,json; d=json.load(sys.stdin); p=d.get('file_path',''); exec('import subprocess; r=subprocess.run([sys.executable,\\\"-m\\\",\\\"py_compile\\\",p],capture_output=True,text=True); print(r.stderr) if r.returncode else print(\\\"Syntax OK: \\\"+p)') if p.endswith('.py') else print('Skipped (not Python)')\"" |
There was a problem hiding this comment.
The python command for the PostToolUse hook has a syntax error and is unnecessarily complex. The exec(...) if ... else ... construct is not valid Python because exec is a statement, not an expression. This will cause the hook to fail with a SyntaxError.
Additionally, using exec here is a code smell and makes the command very difficult to read and maintain. The logic can be written directly without it.
I recommend simplifying the command and using a standard if/else structure. For better long-term maintainability, consider moving this logic into a separate script file.
| "command": "python -c \"import sys,json; d=json.load(sys.stdin); p=d.get('file_path',''); exec('import subprocess; r=subprocess.run([sys.executable,\\\"-m\\\",\\\"py_compile\\\",p],capture_output=True,text=True); print(r.stderr) if r.returncode else print(\\\"Syntax OK: \\\"+p)') if p.endswith('.py') else print('Skipped (not Python)')\"" | |
| "command": "python -c \"import sys, json, subprocess; d = json.load(sys.stdin); p = d.get('file_path', '');\nif p.endswith('.py'):\n r = subprocess.run([sys.executable, '-m', 'py_compile', p], capture_output=True, text=True)\n if r.returncode == 0:\n print(f'Syntax OK: {p}')\n else:\n print(r.stderr, file=sys.stderr)\nelse:\n print('Skipped (not Python)')\"" |
| "hooks": [ | ||
| { | ||
| "type": "intercept", | ||
| "command": "python -c \"import sys,json; d=json.load(sys.stdin); p=d.get('file_path',''); blocked=['.env','secrets','.git/']; sys.exit(1) if any(x in p for x in blocked) else sys.exit(0)\"" |
There was a problem hiding this comment.
Embedding Python logic directly in JSON strings makes it hard to read, test, and maintain. While this command is simple enough, it sets a precedent. For more complex logic, it's better to move it to a separate script file (e.g., scripts/pre-tool-use-check.py) and invoke that script from the hook. This improves readability and makes the hook's behavior easier to manage in the long term.
Summary
.env,secrets,.git/)py_compileon saveCLAUDE.mddocumenting commands, architecture, secrets, and gotchasTest plan
.env,secrets, or.git/in the pathpy_compileafter editing.pyfiles and reports syntax errorsCLAUDE.mdcontent matches current project structure🤖 Generated with Claude Code