Claude Code guide in three levels, Beginner to Advanced: hands-on lessons with checked exercises, every volatile fact cited to its source. Independent community guide.
JavaScript agent-skillsagentic-codingai-agentsanthropicanthropic-claudebest-practicesclaudeclaude-aiclaude-codeclaude-code-guideclaude-code-hooksclaude-code-pluginsclaude-code-skillsclaude-code-tutorialclaude-code-workflowsguidelearn-claude-codemcpsubagentstutorial
hooks: remove logging and spoken completion hooks (#46)
Wesam Abousaid735d4e12d5aa
diff --git a/.claude/hooks/notification.py b/.claude/hooks/notification.pyindex c68fe79..9f93243 100755--- a/.claude/hooks/notification.py+++ b/.claude/hooks/notification.py@@ -91,29 +91,7 @@ def main():# Read JSON input from stdininput_data = json.loads(sys.stdin.read())-- # Ensure log directory exists- log_dir = os.path.join(os.getcwd(), 'logs')- os.makedirs(log_dir, exist_ok=True)- log_file = os.path.join(log_dir, 'notification.json')-- # Read existing log data or initialize empty list- if os.path.exists(log_file):- with open(log_file, 'r') as f:- try:- log_data = json.load(f)- except (json.JSONDecodeError, ValueError):- log_data = []- else:- log_data = []-- # Append new data- log_data.append(input_data)-- # Write back to file with formatting- with open(log_file, 'w') as f:- json.dump(log_data, f, indent=2)-+# Announce notification via TTS only if --notify flag is set# Skip TTS for the generic "Claude is waiting for your input" messageif args.notify and input_data.get('message') != 'Claude is waiting for your input':diff --git a/.claude/hooks/post_tool_use.py b/.claude/hooks/post_tool_use.pydeleted file mode 100755index 81a6e82..0000000--- a/.claude/hooks/post_tool_use.py+++ /dev/null@@ -1,48 +0,0 @@-#!/usr/bin/env -S uv run --script-# /// script-# requires-python = ">=3.8"-# ///--import json-import os-import sys-from pathlib import Path--def main():- try:- # Read JSON input from stdin- input_data = json.load(sys.stdin)-- # Ensure log directory exists- log_dir = Path.cwd() / 'logs'- log_dir.mkdir(parents=True, exist_ok=True)- log_path = log_dir / 'post_tool_use.json'-- # Read existing log data or initialize empty list- if log_path.exists():- with open(log_path, 'r') as f:- try:- log_data = json.load(f)- except (json.JSONDecodeError, ValueError):- log_data = []- else:- log_data = []-- # Append new data- log_data.append(input_data)-- # Write back to file with formatting- with open(log_path, 'w') as f:- json.dump(log_data, f, indent=2)-- sys.exit(0)-- except json.JSONDecodeError:- # Handle JSON decode errors gracefully- sys.exit(0)- except Exception:- # Exit cleanly on any other error- sys.exit(0)--if __name__ == '__main__':- main()\ No newline at end of filediff --git a/.claude/hooks/stop.py b/.claude/hooks/stop.pydeleted file mode 100755index 61a5d21..0000000--- a/.claude/hooks/stop.py+++ /dev/null@@ -1,214 +0,0 @@-#!/usr/bin/env -S uv run --script-# /// script-# requires-python = ">=3.11"-# dependencies = [-# "python-dotenv",-# ]-# ///--import argparse-import json-import os-import sys-import random-import subprocess-from pathlib import Path-from datetime import datetime--try:- from dotenv import load_dotenv- load_dotenv()-except ImportError:- pass # dotenv is optional---def get_completion_messages():- """Return list of friendly completion messages."""- return [- "Work complete!",- "All done!",- "Task finished!",- "Job complete!",- "Ready for next task!"- ]---def get_tts_script_path():- """- Determine which TTS script to use based on available API keys.- Priority order: ElevenLabs > OpenAI > pyttsx3- """- # Get current script directory and construct utils/tts path- script_dir = Path(__file__).parent- tts_dir = script_dir / "utils" / "tts"-- # Check for ElevenLabs API key (highest priority)- if os.getenv('ELEVENLABS_API_KEY'):- elevenlabs_script = tts_dir / "elevenlabs_tts.py"- if elevenlabs_script.exists():- return str(elevenlabs_script)-- # Check for OpenAI API key (second priority)- if os.getenv('OPENAI_API_KEY'):- openai_script = tts_dir / "openai_tts.py"- if openai_script.exists():- return str(openai_script)-- # Fall back to pyttsx3 (no API key required)- pyttsx3_script = tts_dir / "pyttsx3_tts.py"- if pyttsx3_script.exists():- return str(pyttsx3_script)-- return None---def get_llm_completion_message():- """- Generate completion message using available LLM services.- Priority order: OpenAI > Anthropic > fallback to random message-- Returns:- str: Generated or fallback completion message- """- # Get current script directory and construct utils/llm path- script_dir = Path(__file__).parent- llm_dir = script_dir / "utils" / "llm"-- # Try OpenAI first (highest priority)- if os.getenv('OPENAI_API_KEY'):- oai_script = llm_dir / "oai.py"- if oai_script.exists():- try:- result = subprocess.run([- "uv", "run", str(oai_script), "--completion"- ],- capture_output=True,- text=True,- timeout=10- )- if result.returncode == 0 and result.stdout.strip():- return result.stdout.strip()- except (subprocess.TimeoutExpired, subprocess.SubprocessError):- pass-- # Try Anthropic second- if os.getenv('ANTHROPIC_API_KEY'):- anth_script = llm_dir / "anth.py"- if anth_script.exists():- try:- result = subprocess.run([- "uv", "run", str(anth_script), "--completion"- ],- capture_output=True,- text=True,- timeout=10- )- if result.returncode == 0 and result.stdout.strip():- return result.stdout.strip()- except (subprocess.TimeoutExpired, subprocess.SubprocessError):- pass-- # Fallback to random predefined message- messages = get_completion_messages()- return random.choice(messages)--def announce_completion():- """Announce completion using the best available TTS service."""- try:- tts_script = get_tts_script_path()- if not tts_script:- return # No TTS scripts available-- # Get completion message (LLM-generated or fallback)- completion_message = get_llm_completion_message()-- # Call the TTS script with the completion message- subprocess.run([- "uv", "run", tts_script, completion_message- ],- capture_output=True, # Suppress output- timeout=10 # 10-second timeout- )-- except (subprocess.TimeoutExpired, subprocess.SubprocessError, FileNotFoundError):- # Fail silently if TTS encounters issues- pass- except Exception:- # Fail silently for any other errors- pass---def main():- try:- # Parse command line arguments- parser = argparse.ArgumentParser()- parser.add_argument('--chat', action='store_true', help='Copy transcript to chat.json')- args = parser.parse_args()-- # Read JSON input from stdin- input_data = json.load(sys.stdin)-- # Extract required fields- session_id = input_data.get("session_id", "")- stop_hook_active = input_data.get("stop_hook_active", False)-- # Ensure log directory exists- log_dir = os.path.join(os.getcwd(), "logs")- os.makedirs(log_dir, exist_ok=True)- log_path = os.path.join(log_dir, "stop.json")-- # Read existing log data or initialize empty list- if os.path.exists(log_path):- with open(log_path, 'r') as f:- try:- log_data = json.load(f)- except (json.JSONDecodeError, ValueError):- log_data = []- else:- log_data = []-- # Append new data- log_data.append(input_data)-- # Write back to file with formatting- with open(log_path, 'w') as f:- json.dump(log_data, f, indent=2)-- # Handle --chat switch- if args.chat and 'transcript_path' in input_data:- transcript_path = input_data['transcript_path']- if os.path.exists(transcript_path):- # Read .jsonl file and convert to JSON array- chat_data = []- try:- with open(transcript_path, 'r') as f:- for line in f:- line = line.strip()- if line:- try:- chat_data.append(json.loads(line))- except json.JSONDecodeError:- pass # Skip invalid lines-- # Write to logs/chat.json- chat_file = os.path.join(log_dir, 'chat.json')- with open(chat_file, 'w') as f:- json.dump(chat_data, f, indent=2)- except Exception:- pass # Fail silently-- # Announce completion via TTS- announce_completion()-- sys.exit(0)-- except json.JSONDecodeError:- # Handle JSON decode errors gracefully- sys.exit(0)- except Exception:- # Handle any other errors gracefully- sys.exit(0)---if __name__ == "__main__":- main()diff --git a/.claude/hooks/subagent_stop.py b/.claude/hooks/subagent_stop.pydeleted file mode 100755index 4aa3e5a..0000000--- a/.claude/hooks/subagent_stop.py+++ /dev/null@@ -1,152 +0,0 @@-#!/usr/bin/env -S uv run --script-# /// script-# requires-python = ">=3.11"-# dependencies = [-# "python-dotenv",-# ]-# ///--import argparse-import json-import os-import sys-import subprocess-from pathlib import Path-from datetime import datetime--try:- from dotenv import load_dotenv- load_dotenv()-except ImportError:- pass # dotenv is optional---def get_tts_script_path():- """- Determine which TTS script to use based on available API keys.- Priority order: ElevenLabs > OpenAI > pyttsx3- """- # Get current script directory and construct utils/tts path- script_dir = Path(__file__).parent- tts_dir = script_dir / "utils" / "tts"-- # Check for ElevenLabs API key (highest priority)- if os.getenv('ELEVENLABS_API_KEY'):- elevenlabs_script = tts_dir / "elevenlabs_tts.py"- if elevenlabs_script.exists():- return str(elevenlabs_script)-- # Check for OpenAI API key (second priority)- if os.getenv('OPENAI_API_KEY'):- openai_script = tts_dir / "openai_tts.py"- if openai_script.exists():- return str(openai_script)-- # Fall back to pyttsx3 (no API key required)- pyttsx3_script = tts_dir / "pyttsx3_tts.py"- if pyttsx3_script.exists():- return str(pyttsx3_script)-- return None---def announce_subagent_completion():- """Announce subagent completion using the best available TTS service."""- try:- tts_script = get_tts_script_path()- if not tts_script:- return # No TTS scripts available-- # Use fixed message for subagent completion- completion_message = "Subagent Complete"-- # Call the TTS script with the completion message- subprocess.run([- "uv", "run", tts_script, completion_message- ],- capture_output=True, # Suppress output- timeout=10 # 10-second timeout- )-- except (subprocess.TimeoutExpired, subprocess.SubprocessError, FileNotFoundError):- # Fail silently if TTS encounters issues- pass- except Exception:- # Fail silently for any other errors- pass---def main():- try:- # Parse command line arguments- parser = argparse.ArgumentParser()- parser.add_argument('--chat', action='store_true', help='Copy transcript to chat.json')- args = parser.parse_args()-- # Read JSON input from stdin- input_data = json.load(sys.stdin)-- # Extract required fields- session_id = input_data.get("session_id", "")- stop_hook_active = input_data.get("stop_hook_active", False)-- # Ensure log directory exists- log_dir = os.path.join(os.getcwd(), "logs")- os.makedirs(log_dir, exist_ok=True)- log_path = os.path.join(log_dir, "subagent_stop.json")-- # Read existing log data or initialize empty list- if os.path.exists(log_path):- with open(log_path, 'r') as f:- try:- log_data = json.load(f)- except (json.JSONDecodeError, ValueError):- log_data = []- else:- log_data = []-- # Append new data- log_data.append(input_data)-- # Write back to file with formatting- with open(log_path, 'w') as f:- json.dump(log_data, f, indent=2)-- # Handle --chat switch (same as stop.py)- if args.chat and 'transcript_path' in input_data:- transcript_path = input_data['transcript_path']- if os.path.exists(transcript_path):- # Read .jsonl file and convert to JSON array- chat_data = []- try:- with open(transcript_path, 'r') as f:- for line in f:- line = line.strip()- if line:- try:- chat_data.append(json.loads(line))- except json.JSONDecodeError:- pass # Skip invalid lines-- # Write to logs/chat.json- chat_file = os.path.join(log_dir, 'chat.json')- with open(chat_file, 'w') as f:- json.dump(chat_data, f, indent=2)- except Exception:- pass # Fail silently-- # Announce subagent completion via TTS- announce_subagent_completion()-- sys.exit(0)-- except json.JSONDecodeError:- # Handle JSON decode errors gracefully- sys.exit(0)- except Exception:- # Handle any other errors gracefully- sys.exit(0)---if __name__ == "__main__":- main()\ No newline at end of filediff --git a/.claude/settings.json b/.claude/settings.jsonindex 3d32071..d7bb64b 100644--- a/.claude/settings.json+++ b/.claude/settings.json@@ -19,17 +19,6 @@"deny": []},"hooks": {- "PostToolUse": [- {- "matcher": "",- "hooks": [- {- "type": "command",- "command": "uv run \"$CLAUDE_PROJECT_DIR\"/.claude/hooks/post_tool_use.py"- }- ]- }- ],"Notification": [{"matcher": "",@@ -40,28 +29,6 @@}]}- ],- "Stop": [- {- "matcher": "",- "hooks": [- {- "type": "command",- "command": "uv run \"$CLAUDE_PROJECT_DIR\"/.claude/hooks/stop.py --chat"- }- ]- }- ],- "SubagentStop": [- {- "matcher": "",- "hooks": [- {- "type": "command",- "command": "uv run \"$CLAUDE_PROJECT_DIR\"/.claude/hooks/subagent_stop.py"- }- ]- }]}}\ No newline at end of filediff --git a/README.md b/README.mdindex 3f3ce53..38cea40 100644--- a/README.md+++ b/README.md@@ -157,7 +157,7 @@ This repo's [`.claude/`](.claude/) directory is a **working, runnable** Claude C| [`.claude/skills/`](.claude/skills) | An Agent Skill — `/claude-md-review` audits a `CLAUDE.md` for vagueness, dead paths, and bloat | You want a worked example of the [frontmatter contract](docs/skills.md#frontmatter-reference) || [`.claude/agents/`](.claude/agents) | 5 subagents, plus [10 more role prompts](#3-specialized-subagents--drop-in-role-prompts) in `specialized-agents/` | You want specialists without authoring role prompts — they double as [Agent Teams](#agent-teams-experimental) teammates || [`.claude/workflows/`](.claude/workflows) | A [dynamic workflow](#dynamic-workflows) — `/stale-docs-audit` fans agents across your docs, then refutes its own findings | You want a real script to read before writing your own |-| [`.claude/hooks/`](.claude/hooks) | Python hooks — `post_tool_use.py`, `notification.py`, `stop.py`, `subagent_stop.py` | You want [lifecycle automation](#hooks) (needs [`uv`](https://docs.astral.sh/uv/getting-started/installation/)) |+| [`.claude/hooks/`](.claude/hooks) | A Python hook — `notification.py` speaks an alert when Claude Code needs your input, such as a permission prompt | You want [lifecycle automation](#hooks) (needs [`uv`](https://docs.astral.sh/uv/getting-started/installation/)) || [`.claude/settings.json`](.claude/settings.json) | Permissions + hook wiring | You're copying the hooks (they call `uv run` with `$CLAUDE_PROJECT_DIR`, so `uv` just needs to be on your `PATH`) |```bash@@ -406,8 +406,7 @@ project-root/└── .claude/├── hooks/│ ├── notification.py- │ ├── post_tool_use.py- │ └── ...+ │ └── utils/└── settings.json```