-
Notifications
You must be signed in to change notification settings - Fork 928
Add Claude Code hooks and project documentation #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,26 @@ | ||||||
| { | ||||||
| "hooks": { | ||||||
| "PreToolUse": [ | ||||||
| { | ||||||
| "matcher": "Edit|Write", | ||||||
| "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)\"" | ||||||
| } | ||||||
| ] | ||||||
| } | ||||||
| ], | ||||||
| "PostToolUse": [ | ||||||
| { | ||||||
| "matcher": "Edit|Write", | ||||||
| "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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The python command for the Additionally, using I recommend simplifying the command and using a standard
Suggested change
|
||||||
| } | ||||||
| ] | ||||||
| } | ||||||
| ] | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # ClawCloud Auto-Login | ||
|
|
||
| Automated ClawCloud keep-alive via GitHub Actions + Playwright. | ||
|
|
||
| ## Commands | ||
|
|
||
| ```bash | ||
| # Install dependencies | ||
| pip install playwright requests pynacl | ||
| playwright install chromium | ||
| playwright install-deps | ||
|
|
||
| # Run locally | ||
| python scripts/auto_login.py | ||
| ``` | ||
|
|
||
| ## Architecture | ||
|
|
||
| - `scripts/auto_login.py` — Single-file automation script (Playwright browser automation) | ||
| - `.github/workflows/keep-alive.yml` — Cron job (every 5 days, UTC 01:00) | ||
| - `.claude/settings.json` — Claude Code hooks | ||
|
|
||
| ## Key Classes (auto_login.py) | ||
|
|
||
| - `Telegram` — Bot notifications and 2FA code retrieval via `/code` command | ||
| - `SecretUpdater` — Auto-updates GitHub Secrets via API (requires PyNaCl) | ||
| - `AutoLogin` — Main login flow: ClawCloud → GitHub OAuth → region detection → keepalive | ||
|
|
||
| ## Required Secrets | ||
|
|
||
| `GH_USERNAME`, `GH_PASSWORD`, `GH_SESSION`, `TG_BOT_TOKEN`, `TG_CHAT_ID`, `REPO_TOKEN` | ||
|
|
||
| ## Gotchas | ||
|
|
||
| - All credentials come from GitHub Actions secrets / environment variables — never hardcode | ||
| - The script uses anti-detection measures (custom user agent, webdriver override) | ||
| - `GH_SESSION` cookie auto-updates on successful login if `REPO_TOKEN` is set | ||
| - Region is auto-detected from redirect URL after OAuth (e.g. `ap-southeast-1.console.claw.cloud`) | ||
| - 2FA supports both GitHub Mobile approval and TOTP via Telegram `/code 123456` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.