
A text message arrived when Claude Code finished a task, using a hook to deliver the alert. In a workflow demonstrated by All About AI, the same hook system is also used to generate a Python test and update a GitHub repository. A completion text could let you step away during a long-running task rather than keep checking the screen. Discover how these hooks fit into a coding session.
Send A Text When Claude Code Stops
Claude Code hooks customize its behavior by registering shell commands at particular points in a workflow. Log in and enter /hooks to see the available Claude Code hooks and any already configured. There are four types to choose from:
- Pre-tool use hooks run before a tool is used.
- Post-tool use hooks run after a tool is used.
- Notification hooks send alerts.
- Stop hooks can trigger actions when Claude Code stops.
For the text alert, a stop hook was configured with a curl command using Twilio to send a message whenever Claude Code stops or completes a task. To try it, Claude Code received permission to write a simple HTML and CSS page simulating a random ping-pong match. It completed the project in one go, and a text arrived saying the task was complete.
The simulator appeared to have a problem: neither player would score. The test was aimed at the notification rather than validation of the game, so the message shows that the alert arrived, not that the simulator worked correctly.
Generate A Test After Creating Python Code
A post-tool use hook can act at a different point in the workflow. In this example, it was configured to generate a test when new Python code was created, and Claude Code was asked to build a tool that checks whether a number is prime. A test file was created alongside the checker.
Claude Code was then explicitly asked to check whether the project had a test and run it. The test passed, identifying 2 and 17 as prime and 1 and 4 as non-prime. Generating unit tests after creating a Python file is one possible use for a hook, although it may not be the best testing approach.
The same post-tool idea was also tried with sound. A cat meow was created with ElevenLabs, and Claude Code was asked to play the project’s MP3 file whenever a tool completed. When it wrote admin.py to add two integers, the sound played after the write tool was used.
Stage And Push Changes To GitHub
The repository example explored another use for hooks: preserving changes when the demonstrated Claude Code workflow had no checkpoints. A GitHub repository was created, and Claude Code was asked to set up a hook to stage changes autonomously. The hook and its command were configured in settings.json; Claude Code had to be restarted before the hooks worked.
To inspect the result, Claude Code was asked to modify the prime checker so it could accept two integers and check whether they were prime. Running git status showed the modified checker staged and ready to commit, while the prime checker test had been deleted after it was removed. At that point, the hook had not been configured to commit or push.
The hook was then extended to push changes to the repository autonomously. After the checker was updated to accept multiple integers, refreshing the repository showed the changed file and five changes in total. A README was added as another check and appeared after a refresh; changing its author to Chris was reflected there too, with the repository showing seven commits.
We like the completion text as a starting point for Claude Code workflows: it provides a useful prompt to return without changing the project itself. The GitHub example offers a way to preserve updates that might otherwise be forgotten, but automatic repository updates may be more elaborate than some tasks need. We would check the staged and pushed results before relying on the setup, just as the example used git status and repository refreshes to inspect what happened.
To return to an earlier checkpoint in that repository, open the first commit, copy its identifier, ask Claude Code to revert to it and push the result. In the example, this returned the repository to its starting state, with the README no longer present.
More on Claude:
- Claude Designer 3.0: A Parallel No-Code UI Workflow
- How to Install Claude Code in Windsurf and Cursor
- Google Project IDX vs Visual Code Studio code editors compared
- Claude 4 Sonnet and Opus Coding Tests: Quality vs Cost
Media Credit: All About AI
Disclosure: Some of our articles include affiliate links. If you buy something through one of these links, Geeky Gadgets may earn an affiliate commission. Learn about our Disclosure Policy.