Build a Webcam Face-Touch Alarm

Build a local webcam alarm that catches face touches and sustained slouching.

Introduction

30 Second Summary

Face touching is easy to miss until your hand is already on your skin. Pratim Bhosale turned that hidden habit into a Mac app after dealing with facial acne.

In this project, you will use Claude Code to build a local webcam alarm that catches face touches. It plays a real warning recorded through your microphone while posture mode catches sustained slouching without saving webcam frames.

What You'll Build

With habit_alarm.py running, your mirrored webcam view turns red during a sustained face touch while TOUCHING appears and your recorded warning plays.

By the end of this project, you'll have:

  • A live face-touch tracker that follows one face plus two hands before showing TOUCHES: n as separate touches are counted.
  • A local voice alarm that records a real warning to lines/line1.wav before playing it once when a new touch is detected.
  • A posture and session record that shows SIT UP after sustained slouching before saving touch events to touches.csv for your final demo.
  • Secret Mission: record 3 to 5 consented warning lines before adding non-repeating playback and an escalation after three touches within one minute.

Are there any prerequisites?

You'll need a Claude Pro, Max, Ultra, Team, Enterprise, or Console account with access to Claude Code.

Use an Apple silicon Mac running macOS 13 or later or a Windows 10 or 11 PC because MediaPipe 1.3.0 has no Intel Mac wheel.

You'll also need a webcam, a microphone, speakers or headphones, and internet access for setup.

Before We Start

Before any hands-on work begins, commit to the habit you want this private webcam alarm to catch. Your webcam frames and voice recordings will remain on your computer.

Set Up Your Tools

A clean, pinned Python environment prevents package conflicts before Claude Code starts building.

Python 3.13.18 runs the local project inside a virtual environment. Claude Code checks the setup now and writes each script later.

In this step, get ready to:
  • Install the local development tools.
  • Create the pinned project environment.
  • Download the local model bundles.
Install Python and Claude Code

The pinned Python version keeps every package on a known combination. Claude Code then runs inside that environment for the rest of the project.

macOS

  • Choose the Python 3.13.18 installer for macOS.
  • Run the downloaded installer.

Windows

  • Choose the Python 3.13.18 installer for Windows.
  • Keep the installer option that makes the py command available.
  • Run the downloaded installer.

Use a shell to confirm which Python version your computer now runs.

macOS

  • Press Cmd+Space to open macOS search.
  • Type Terminal.
  • Press Enter to open Terminal.

Windows

  • Press the Windows key to open Windows search.
  • Type PowerShell.
  • Press Enter to open Windows PowerShell.
  • Check the installed Python version by running the command for your operating system:

macOS

python3 --version

What does this command do?

The --version option asks Python to print its installed version without starting the interpreter.

Windows

py --version

What does this command do?

The py launcher finds the installed Python interpreter. The --version option prints its version.

You should see Python 3.13.18 in the output.

✔️ I see version 3.13.18

Your Python runtime matches the project pin. That removes the first source of package conflicts.

ⓧ I see an older version

The shell is still finding an older Python installation.

  • Return to Python downloads.
  • Install Python 3.13.18 for your operating system.
  • Close the current shell window.
  • Repeat the version check in a fresh shell.

ⓧ Command not found

Your shell cannot find the Python command yet.

  • Return to Python downloads.
  • Install Python 3.13.18 for your operating system.
  • Keep the Windows installer option that makes the py command available if you use Windows.
  • Repeat the version check in a fresh shell.
  • Install Claude Code from the official setup page by running the command for your operating system:

macOS

curl -fsSL https://claude.ai/install.sh | bash

What does this command do?

This downloads the official Claude Code native installer. It passes the installer to your shell so the installation can run.

Windows

irm https://claude.ai/install.ps1 | iex

What does this command do?

This downloads the official Claude Code PowerShell installer. It passes the installer to PowerShell so the installation can run.

You should see installation output confirming that Claude Code is available.

The next command starts the account sign-in flow. Use an eligible account without pasting any credentials into the shell.

  • Start Claude Code by running this command:
claude

What does this command do?

The claude command starts Claude Code. A first-time session directs you through account sign-in.

  • Complete the browser sign-in with an eligible Pro, Max, Ultra, Team, Enterprise, or Console account.
  • Return to the account page that Claude Code opened.
  • Follow the account prompts until the shell reports that Claude Code is ready.

You should see an active Claude Code session in your shell.

  • Ask Claude Code to check both installed tools by pasting this prompt:
Check the installed Python and Claude Code versions. On Mac, run python3 --version and claude --version. On Windows, run py --version and claude --version. Do not install or change anything. Tell me whether Python 3.13.18 and Claude Code are ready.

What does this prompt check?

Claude Code runs the correct version checks for your operating system. It reports mismatches without changing the computer.

Claude should report Python 3.13.18 and a Claude Code version.

Claude command not found?

Close the current shell after the installer finishes. Start a fresh shell before running the claude command again.

Help me troubleshoot Claude Code after its native installer completed but the claude command was not found.

Create the pinned environment

The project folder keeps the models and future scripts together. Its isolated environment prevents these pinned packages from changing other Python projects.

  • Start a second shell window using the operating system search steps from earlier.
  • Create habit-alarm on your Desktop with an activated .venv by running the commands for your operating system:

macOS

cd ~/Desktop
mkdir habit-alarm
cd habit-alarm
python3 -m venv .venv
source .venv/bin/activate

What do these commands do?

  • The first three commands create habit-alarm on your Desktop and move the shell into it.
  • The fourth command creates the isolated .venv environment.
  • The last command activates that environment for the current shell.

Windows

cd ~/Desktop
mkdir habit-alarm
cd habit-alarm
py -m venv .venv
.venv\Scripts\activate

What do these commands do?

  • The first three commands create habit-alarm on your Desktop and move PowerShell into it.
  • The fourth command creates the isolated .venv environment.
  • The last command activates that environment for the current PowerShell session.

You should see (.venv) at the start of the shell prompt. That confirms commands now use the project environment.

The package download can take a few minutes while your computer collects each pinned wheel. Keep the shell open until the install command finishes.

  • Install the pinned packages inside the active environment by running the command for your operating system:

macOS

python3 -m pip install mediapipe==1.3.0 opencv-contrib-python==5.1.0.95 sounddevice==0.5.6 numpy==2.5.5

What does this command do?

The command installs each exact package version into .venv. Using opencv-contrib-python keeps one package responsible for the shared cv2 namespace.

Windows

py -m pip install mediapipe==1.3.0 opencv-contrib-python==5.1.0.95 sounddevice==0.5.6 numpy==2.5.5

What does this command do?

The command installs each exact package version into .venv. Using opencv-contrib-python keeps one package responsible for the shared cv2 namespace.

You should see the installation finish without a package error. The environment now contains MediaPipe 1.3.0, OpenCV 5.1.0.95 through opencv-contrib-python, sounddevice 0.5.6, and NumPy 2.5.5.

  • Start Claude Code from the activated environment by running this command:
claude

What does this command do?

Claude Code starts with habit-alarm as its current folder. Its checks now use the active .venv environment.

  • Ask Claude Code to inspect the environment by pasting this prompt:
Check this virtual environment without creating a script. Import mediapipe, cv2, sounddevice, and numpy, then print each installed version. Confirm that the current folder is named habit-alarm and that the active environment is .venv. Do not install opencv-python because mediapipe 1.3.0 uses opencv-contrib-python and both packages share the cv2 namespace.

What does this prompt check?

Claude imports every installed library before reading its version. A successful import proves the environment can load the packages the tracker needs.

Claude should report MediaPipe 1.3.0, OpenCV 5.1.0.95, sounddevice 0.5.6, NumPy 2.5.5, the habit-alarm folder, and the active .venv environment.

Download the model bundles

The two model bundles contain the data that the landmarkers load locally. Keeping them in habit-alarm gives the future tracker stable file paths.

  • Ask Claude Code to download both official model bundles by pasting this prompt:
Download the official MediaPipe model bundles named face_landmarker.task and hand_landmarker.task into the current habit-alarm folder. Use the model download links in these official guides:
https://ai.google.dev/edge/mediapipe/solutions/vision/face_landmarker/python
https://ai.google.dev/edge/mediapipe/solutions/vision/hand_landmarker/python
Do not rename the files. Do not upload any local file. When finished, list both filenames and their nonzero file sizes.

What does this prompt do?

Claude Code follows the official Face Landmarker and Hand Landmarker guides. It saves both bundles locally without renaming them.

The nonzero file-size check catches an empty or incomplete download before you build the tracker.

You should see face_landmarker.task and hand_landmarker.task listed in habit-alarm with nonzero file sizes.

Before the final check, do you expect Claude Code to find every pinned version and both model files from the current folder?

  • Verify the complete setup by pasting this prompt into the Claude Code session from habit-alarm:
Verify the current habit-alarm setup without creating or changing any files. Confirm the active environment is .venv. Print the installed versions of Python, mediapipe, cv2, sounddevice, and numpy. Confirm that face_landmarker.task and hand_landmarker.task are in the current folder and report each nonzero file size. Tell me whether the setup matches Python 3.13.18, MediaPipe 1.3.0, OpenCV 5.1.0.95, sounddevice 0.5.6, and NumPy 2.5.5.

What does this prompt verify?

This final check compares the active environment with every project pin. It also verifies that both local model bundles contain downloaded data.

Claude should report Python 3.13.18, MediaPipe 1.3.0, OpenCV 5.1.0.95, sounddevice 0.5.6, NumPy 2.5.5, and both .task files with nonzero sizes.

Your local toolchain is ready. Claude Code can now build against the pinned packages and local models.

✔️ Awesome, I've got everything!

Great. Keep Claude Code running from the activated .venv before moving on.

ⓧ I'd like to double check the full setup

.venv: Created and activated virtual environment in habit-alarm with MediaPipe 1.3.0, OpenCV 5.1.0.95 via opencv-contrib-python, sounddevice 0.5.6, and NumPy 2.5.5 installed.

face_landmarker.task: Downloaded official local MediaPipe face model bundle with a nonzero file size.

habit-alarm: Created local project folder with an activated .venv, face_landmarker.task, and hand_landmarker.task.

hand_landmarker.task: Downloaded official local MediaPipe hand model bundle with a nonzero file size.

Your environment and local models are ready. Next, Claude Code builds the live tracker that follows your face and hands.

See Your Face and Hands

Your pinned environment and two local model bundles are ready. Now you can turn that setup into a live tracker with Claude Code.

A visible tracker proves the webcam and both local models work. The final visual test reveals what the tracker still cannot recognize.

In this step, get ready to:
  • Create face_hands.py with local face and hand tracking.
  • Run the tracker with local camera access.
  • Test the face outline and hand landmarks with deliberate movements.
Create the tracker

The tracker combines the MediaPipe Tasks API, Face Landmarker, Hand Landmarker, and OpenCV in one local webcam loop. VIDEO mode keeps each frame in order through rising timestamps.

  • Ask Claude Code to create face_hands.py by pasting this prompt into the session from setup:
Write face_hands.py in the current folder. Open the default webcam with OpenCV and show a mirrored live window. Use only the MediaPipe Tasks API from mediapipe 1.3.0. Create mp.tasks.vision.FaceLandmarker and mp.tasks.vision.HandLandmarker with face_landmarker.task and hand_landmarker.task. Use VIDEO mode, detect_for_video, and strictly rising millisecond timestamps for every processed frame. Track one face and up to two hands. Draw the face outline in white and all 21 points on each detected hand in green. Show frames per second. Close cleanly when I press q. Never use mp.solutions, never save a webcam frame, and never upload video. Explain which file you created, but do not paste the full script into chat.

What does this prompt ask Claude Code to do?

  • The mp.tasks.vision.FaceLandmarker class reads the local face_landmarker.task model for one face.
  • The mp.tasks.vision.HandLandmarker class reads hand_landmarker.task for up to two hands.
  • The detect_for_video calls receive strictly rising timestamps so frames stay in order.
  • The script mirrors the webcam view and draws the tracking results without saving any frame.

That is the core tracker built. Claude Code creates face_hands.py and reports that both landmarkers use the Tasks API in VIDEO mode.

Run the tracker

The first run checks the whole webcam loop at once. Your video remains on your computer throughout the test.

  • Ask Claude Code for the correct command and camera-permission guidance by pasting:
Tell me the exact command to run face_hands.py on my operating system, then wait while I run it. If the webcam is blocked, help me check only the official camera permission for my operating system. Do not rewrite the script yet.

What does this prompt ask Claude Code to do?

Claude Code identifies the correct Python command for your operating system. It keeps the current script unchanged while you test camera access.

Claude Code gives the command for your operating system and waits for your result.

macOS

  • Run face_hands.py from the activated .venv by running this command:
python3 face_hands.py

What does this command do?

The command starts face_hands.py with the active Python environment. The script opens the default webcam and loads both local model bundles.

  • Grant the terminal app camera access if macOS requests it.
  • Open System Settings if you need to grant camera access manually.
  • Select Privacy & Security.
  • Select Camera.
  • Turn access on for the terminal app running face_hands.py.

You should see a mirrored webcam window with a white face outline, green hand points, and a visible frame rate.

Windows

  • Run face_hands.py from the activated .venv by running this command:
py face_hands.py

What does this command do?

The Windows Python launcher starts face_hands.py from the active environment. The script opens the default webcam and loads both local model bundles.

  • Turn on Camera access if the webcam window remains black.
  • Open Settings.
  • Select Privacy & security.
  • Select Camera.
  • Find Camera access.
  • Turn on Let desktop apps access your camera if the webcam window remains black.
  • Stay on the Camera page.
  • Find Let desktop apps access your camera.

You should see a mirrored webcam window with a white face outline, green hand points, and a visible frame rate.

The first run may print lines containing Failed to register engine: ALREADY_EXISTS while both models load. This tested model-loading noise is harmless when the webcam window and landmarks appear.

Is the webcam window black?

  • Ask Claude Code to check camera use and the official permission for your operating system by pasting:
The webcam window is black or says camera not found. Check whether another app is using the camera and guide me through the official camera permission for my operating system. Do not add a second camera library and do not save frames.

This keeps the diagnosis focused on camera availability and operating-system permissions. It preserves the local-only webcam design.

Help me diagnose a black webcam window without adding another camera library.

Test the tracking

Deliberate movements make each tracking layer easy to judge. The cheek test also exposes the current tracker's remaining limitation.

  • Ask Claude Code for the three-part visual test by pasting:
Do not change face_hands.py. Give me a three-part visual test: turn my head, wave both hands, and hold one hand beside my cheek. Remind me that white is the face outline, green is the hand points, and q quits. Ask me to report only what fails.

What does this prompt ask Claude Code to do?

Claude Code gives you a repeatable movement sequence without editing face_hands.py. Each movement isolates one visible part of the tracker.

Claude Code returns a head-turn test, a two-hand test, and a cheek test.

Before you start the visual check, do you expect the tracker to label a touch when your hand rests beside your cheek?

  • Turn your head slowly from side to side.

You should see the white outline remain on your face as your head turns.

  • Wave both hands inside the webcam view.

You should see green landmarks follow all 21 points on each detected hand.

  • Hold one hand beside your cheek.

You will still see the white face outline and green hand points. No touch label appears.

That shortfall is intentional. The tracker can locate your face and hands without deciding whether they are touching.

  • Close the tracker by pressing q.

The webcam window closes cleanly and returns control to your terminal. You now have a working local tracker that follows one face and up to two hands.

Your face and hand tracker is working locally. Next, you will turn those moving landmarks into a face-touch detector.

Catch a Face Touch

Your local MediaPipe Tasks API tracker now follows your face and both hands in real time. Those moving landmarks give you the raw positions needed for touch detection.

A hand passing near your face can look like a touch, so the detector needs sustained fingertip contact before it counts.

In this step, get ready to:
  • Create sustained face-touch detection.
  • Test one-touch counting with deliberate touches and a near-face wave.
  • Tune the detector using your observed results.
Create touch detection

Claude Code will use the working tracker in face_hands.py as the foundation for habit_alarm.py. The five fingertip landmarks provide the contact points for the new detector.

  • Create habit_alarm.py from the working tracker by pasting this prompt into Claude Code:
Create habit_alarm.py from the working face_hands.py. Keep the MediaPipe Tasks API, VIDEO mode, detect_for_video, and rising timestamps. Define a touch as any fingertip landmark 4, 8, 12, 16, or 20 staying inside the face outline for at least 5 consecutive frames. While touching, fill the face zone red and show the exact label TOUCHING. Show the exact counter format TOUCHES: n. Count each new continuous touch once, then require every fingertip to leave the face before another touch can count. Keep 5 frames as an easy-to-change starting value. Never save or upload webcam frames. Do not paste the full script into chat.

What does this prompt do?

  • Claude Code builds habit_alarm.py from the tracker that already opens the webcam and runs both landmarkers.
  • Fingertip landmarks 4, 8, 12, 16, and 20 become the five points checked against the face outline.
  • The 5-frame threshold filters quick overlaps before the detector shows TOUCHING and increases the counter.
  • The leave-before-recount rule prevents continuous contact from increasing TOUCHES: n on every frame.

Claude creates habit_alarm.py with the requested labels, red touch state, five-frame starting threshold, and one-count-per-contact rule.

Didn't create the detector file?

Confirm Claude Code is still running from the activated .venv inside habit-alarm. Then paste the creation prompt again.

Help me diagnose why Claude Code did not create habit_alarm.py.

Test the detector

A single overlapping frame can come from a quick pass near your face. The 5-frame starting threshold gives the detector time to distinguish sustained contact.

  • Ask Claude Code for the exact detector test by pasting this prompt:
Do not change habit_alarm.py. Give me this test sequence: touch my forehead three times, cheek three times, and chin three times, fully leaving the face between touches. Wave a hand near the face without touching. Then rest my chin on my hand and confirm that one continuous contact counts only once. Remind me to press q when finished.

What does this prompt do?

Claude Code keeps the script unchanged and turns the detector requirements into a repeatable visual test. The deliberate touches test counting while the wave and chin rest test false counts.

Claude Code returns the nine-touch sequence, the near-face wave check, the continuous-contact check, and the reminder to quit with q.

Before you run the detector, do you expect the near-face wave or the continuous chin rest to increase the counter more than once?

macOS

  • Run habit_alarm.py from the activated .venv by running this command:
python3 habit_alarm.py

What does this command do?

The command uses the active Python environment to run habit_alarm.py. The script opens the local mirrored webcam window and processes each frame through the two existing landmarkers.

Windows

  • Run habit_alarm.py from the activated .venv by running this command:
py habit_alarm.py

What does this command do?

The command uses the Windows Python launcher with the active environment to run habit_alarm.py. The script opens the local mirrored webcam window and processes each frame through the two existing landmarkers.

  • Touch your forehead three times while fully leaving the face between touches.
  • Touch your cheek three times while fully leaving the face between touches.
  • Touch your chin three times while fully leaving the face between touches.
  • Wave one hand near your face without touching it.
  • Rest your chin on your hand without breaking contact.
  • Press q to close the webcam window.

You should see TOUCHING only during sustained contact. The nine separate touches should reach TOUCHES: 9.

The near-face wave should add nothing. The continuous chin rest should count once until every fingertip leaves the face.

Tune the detector

Threshold tuning can feel fiddly because webcam position and face angle change the apparent distance between landmarks. The 5-frame value remains the documented starting point while a single small adjustment adapts the detector to your test.

  • Ask Claude Code to tune one detector value by pasting this prompt:
Help me tune habit_alarm.py from my observed test without changing the feature names. Ask me which happened: a near-face wave counted as a touch, deliberate touches were missed, or one continuous touch counted more than once. Change only the five-frame threshold or a small face-zone margin, explain the single change, and keep 5 frames as the documented starting value. Preserve TOUCHING, TOUCHES: n, q to quit, MediaPipe Tasks VIDEO mode, detect_for_video, rising timestamps, and the rule that webcam frames are never saved or uploaded. If the face disappears behind my hand, keep the last face outline for no more than half a second before giving up on it.

What does this prompt do?

Claude Code uses your observed failure to adjust either the touch threshold or the face-zone margin. It also limits the last known face outline to half a second when your hand hides the face.

Claude Code asks which of the three detector results matched your test.

  • Report the matching result to Claude Code by sending this message:
My observed result was: [[OBSERVED_RESULT="a near-face wave counted as a touch, deliberate touches were missed, or one continuous touch counted more than once"]]

What does this reply do?

Your observation tells Claude Code which single detector value needs attention. The focused reply keeps unrelated labels, keys, model settings, and privacy behavior unchanged.

Claude Code reports one threshold or margin adjustment. It preserves TOUCHING, TOUCHES: n, q, VIDEO mode, rising timestamps, and the half-second limit for a temporarily hidden face.

Before you rerun the detector, do you expect the adjusted value to improve the failed part without changing the successful parts?

macOS

  • Run the tuned habit_alarm.py by running this command:
python3 habit_alarm.py

What does this command do?

The command starts the tuned detector with the active Python environment. Running the same test again isolates the effect of the single adjustment.

Windows

  • Run the tuned habit_alarm.py by running this command:
py habit_alarm.py

What does this command do?

The command starts the tuned detector through the Windows Python launcher. Running the same test again isolates the effect of the single adjustment.

  • Touch your forehead three times while fully leaving the face between touches.
  • Touch your cheek three times while fully leaving the face between touches.
  • Touch your chin three times while fully leaving the face between touches.
  • Wave one hand near your face without touching it.
  • Rest your chin on your hand without breaking contact.
  • Press q to close the webcam window.

You should see TOUCHES: 9 after the nine deliberate touches. The near-face wave should add nothing.

The continuous chin rest should increase the counter once. You now have the key behavior that turns moving landmarks into stable face-touch events.

Your alarm now recognizes sustained face touches and counts each continuous contact once. Next, you will make each new touch produce an immediate local warning.

Make It Talk Back

Your alarm now recognizes sustained face touches. It counts each continuous touch once.

A visual warning is easy to miss, so this step uses Claude Code to add an immediate local beep before replacing it with a real microphone recording.

The warning stays on your computer. You control the voice that the alarm plays.

In this step, get ready to:
  • Add a local beep generated by NumPy through sounddevice with a three-second cooldown.
  • Record a local WAV warning through your microphone.
  • Use the saved line for touch warnings.
Add the local beep

Touch detection and warning playback solve separate problems. The cooldown limits the audio without changing how the touch counter works.

  • Update habit_alarm.py by pasting this prompt into the Claude Code session from earlier:
Update habit_alarm.py so every newly counted touch plays a short beep generated with NumPy and played with sounddevice. Add a 3-second audio cooldown so a new warning cannot play more often than once every 3 seconds. Keep TOUCHING, TOUCHES: n, q to quit, the five-frame touch starting value, and local-only webcam processing. Do not add pygame, playsound, simpleaudio, pydub, text-to-speech, or any paid voice service. Do not paste the full script into chat.

What does this prompt do?

  • The prompt keeps the existing touch detector intact.
  • It adds one generated beep for each newly counted touch.
  • The three-second cooldown limits warning playback without stopping the counter.

Claude Code updates habit_alarm.py with a generated beep. It preserves TOUCHING, TOUCHES: n, and q.

Before you test the change, do you expect touch counting to continue during the audio cooldown?

macOS

  • Test the updated alarm from the activated .venv by running this command:
python3 habit_alarm.py

What does this command do?

The python3 command runs habit_alarm.py with the packages from your active .venv.

Windows

  • Test the updated alarm from the activated .venv by running this command:
py habit_alarm.py

What does this command do?

The py command runs habit_alarm.py with the packages from your active .venv.

  • Make one deliberate face touch.

You'll hear a short beep when the touch is counted. The face zone turns red at the same time.

  • Move every fingertip away from your face.
  • Make another deliberate touch within 3 seconds of the first warning.

The counter can increase for the new touch. You should not hear another beep while the audio cooldown is active.

  • Press q to close the webcam window.

The webcam window closes cleanly. Your alarm now has an audible fallback warning.

Record a real line

A recorded warning gives the alarm a voice you recognize. The recording remains inside the habit-alarm folder.

  • Create record_line.py by pasting this prompt into the Claude Code session from earlier:
Write record_line.py. Create lines/ if it does not exist. Count down 3, 2, 1 in the terminal, record exactly 3 seconds from the default microphone with sounddevice, save uncompressed WAV audio to lines/line1.wav with Python's built-in wave module, then play the saved line back with sounddevice. Do not add any other audio library. Do not upload the recording. Explain which file was saved, but do not paste the full script into chat.

What does this prompt do?

  • The script creates lines/ when the folder is missing.
  • It records exactly three seconds from the default microphone.
  • It saves uncompressed audio through Python's built-in wave module.
  • It plays the saved file back through sounddevice.

Claude Code creates record_line.py in habit-alarm. It confirms that the script saves to lines/line1.wav.

Microphone permission can feel broad, so this script uses it only for the three-second local line you start.

  • Allow the terminal app to use your microphone if your operating system asks for permission.
  • Use the line Hands off your face. for this recording.

macOS

  • Record the warning from the activated .venv by running this command:
python3 record_line.py

What does this command do?

The command starts the recorder. The script counts down before capturing three seconds of microphone audio.

Windows

  • Record the warning from the activated .venv by running this command:
py record_line.py

What does this command do?

The command starts the recorder. The script counts down before capturing three seconds of microphone audio.

You'll hear lines/line1.wav play after the recording finishes. That's the local recording loop working from microphone to saved file to playback.

Recording silent?

On macOS:

  • Go to System Settings.
  • Select Privacy & Security.
  • Select Microphone.
  • Enable the terminal app.

On Windows:

  • Go to Settings.
  • Select Privacy & security.
  • Select Microphone.
  • Turn on Microphone access.
  • Turn on Let desktop apps access your microphone.
  • Ask Claude Code to identify the microphone used by record_line.py with this prompt:
lines/line1.wav is silent. Use sounddevice to list the available input devices, ask me which microphone I speak into, and update record_line.py to use that device. Keep the built-in wave module for saving and do not add another audio library.

This prompt keeps the existing audio tools. It helps Claude Code select the microphone you actually use.

Play the recording on each touch

The alarm now has two possible warning sources. A saved line takes priority while the generated beep remains available when no warning file exists.

  • Update habit_alarm.py by pasting this prompt into the Claude Code session from earlier:
Update habit_alarm.py so a newly counted touch chooses a WAV file from lines/ and plays it with sounddevice. Use the generated beep only when lines/ contains no WAV warning files. Keep the 3-second cooldown, TOUCHING, TOUCHES: n, q to quit, and local-only processing. Do not add voice cloning, text-to-speech, paid services, or another audio library. Do not paste the full script into chat.

What does this prompt do?

  • The alarm checks lines/ for local warning files after a new touch.
  • It plays a saved warning through sounddevice when one exists.
  • It falls back to the generated beep when no warning file exists.
  • It preserves the three-second audio cooldown.

Claude Code updates habit_alarm.py to use lines/line1.wav for touch warnings. The generated beep remains the fallback.

Before you run the alarm, do you expect the recorded line or the generated beep to play now that lines/line1.wav exists?

macOS

  • Run the completed local audio test from the activated .venv with this command:
python3 habit_alarm.py

What does this command do?

The command starts the updated webcam alarm. It can now read the warning file stored in lines/.

Windows

  • Run the completed local audio test from the activated .venv with this command:
py habit_alarm.py

What does this command do?

The command starts the updated webcam alarm. It can now read the warning file stored in lines/.

  • Make one deliberate face touch.

The face zone turns red. You'll see TOUCHING while lines/line1.wav plays once.

  • Move every fingertip away from your face.
  • Make a second deliberate touch within 3 seconds of the first warning.

The new touch can increase TOUCHES: n. The recorded warning stays quiet because the cooldown is still active.

  • Wait until at least 3 seconds have passed since the first warning.
  • Make one more deliberate face touch.

You'll hear lines/line1.wav again. This proves the recording and cooldown work together.

  • Press q to close the webcam window.

You have the full local feedback loop working: a detected touch now triggers your own recorded line without uploading webcam frames or audio.

✔️ Awesome, I've got everything!

Your recorder and alarm are saved. Double check that lines/line1.wav plays clearly before moving on.

ⓧ I'd like to double check the full code

Use these behavior checkpoints because Claude Code generated scripts can vary.

  • The .venv remains activated with the pinned project packages installed.
  • The face_landmarker.task and hand_landmarker.task model bundles remain in habit-alarm.
  • The unchanged face_hands.py remains your local live face and hand tracker.
  • The habit-alarm folder now contains .venv, both model bundles, face_hands.py, habit_alarm.py, record_line.py, and lines/.
  • The record_line.py script counts down before recording exactly three seconds through sounddevice.
  • The record_line.py script saves uncompressed audio through Python's built-in wave module.
  • The lines/ folder contains the locally recorded lines/line1.wav warning.
  • The habit_alarm.py script preserves the five-frame starting threshold, TOUCHING, TOUCHES: n, and q.
  • The habit_alarm.py script plays a warning WAV when one exists in lines/.
  • The habit_alarm.py script uses the generated beep when lines/ has no WAV warning file.
  • The three-second audio cooldown prevents warning playback from repeating too often.
  • Webcam frames and recorded audio remain local.

Your face-touch alarm can now answer with a real local voice. Next, you'll add a posture mode that reacts when your face drops or moves closer to the screen.

Add Posture Mode

Your face-touch alarm already notices sustained contact and answers with a local recording.

Gradual slouching or leaning closer can slip past the touch detector, so this step compares your live face position with an upright baseline.

In this step, get ready to:
  • Add calibrated posture mode to habit_alarm.py.
  • Record a local WAV posture warning.
  • Test and tune the posture warning thresholds.
Create posture mode

A saved baseline captures your face position while you sit upright. The alarm can then measure sustained movement away from that personal starting point.

  • Add posture mode in the Claude Code session from earlier by pasting this prompt:
Add posture mode to habit_alarm.py. Pressing the exact key c must calibrate and save the current face center and face size as good posture. Pressing the exact key m must toggle posture mode on and off. Starting values: if the face remains more than 10% lower or 15% bigger than the calibrated baseline for 5 seconds, show the exact orange label SIT UP and play lines/posture.wav. Do not warn before calibration. Keep q to quit, the face-touch alarm, the 3-second touch-audio cooldown, and local-only webcam processing. Treat 10%, 15%, and 5 seconds as easy-to-change starting values. Do not paste the full script into chat.

What does this prompt do?

  • The c key gives the app a personal baseline using your current face center and size.
  • The five-second delay keeps a brief movement from triggering SIT UP.
  • The m key lets you pause posture checks while keeping the face-touch alarm active.

That's the posture logic in place. Claude reports that c calibrates the baseline. It also reports that m toggles posture mode with the requested starting thresholds.

Record the posture line

The posture warning needs a dedicated recording. Keeping lines/posture.wav separate lets face-touch warnings continue using the other files in lines/.

  • Extend the recorder in the Claude Code session from earlier by pasting this prompt:
Update record_line.py so it accepts an optional output path while keeping lines/line1.wav as the default. Then tell me how to record exactly 3 seconds to lines/posture.wav. Keep sounddevice for recording and playback, keep Python's built-in wave module for saving, and do not add another audio library. Do not paste the full script into chat.

What does this prompt do?

The optional output path lets one recorder create both face-touch warnings and the posture warning. Leaving out the path still saves to lines/line1.wav.

The recording stays on your computer as an uncompressed WAV file. The script plays it back immediately so you can hear whether the microphone captured it clearly.

Claude reports that record_line.py now accepts an optional output path while preserving lines/line1.wav as the default.

  • Use Sit up straight. as the warning when the three-second recording starts.

macOS

  • Record the posture warning to lines/posture.wav by running this command:
python3 record_line.py lines/posture.wav

What does this command do?

The command runs record_line.py with lines/posture.wav as its output path. The recorder captures three seconds before saving and replaying the file.

Windows

  • Record the posture warning to lines/posture.wav by running this command:
py record_line.py lines/posture.wav

What does this command do?

The py launcher runs record_line.py with lines/posture.wav as its output path. The recorder captures three seconds before saving and replaying the file.

You should hear your three-second recording play back clearly. The file now exists at lines/posture.wav for the SIT UP warning.

Tune posture mode

Your real working position gives the most useful calibration. Testing both a downward slump and a move toward the camera checks each posture threshold separately.

  • Prepare the final posture test in the Claude Code session from earlier by pasting this prompt:
Do not change the documented posture starting values yet. Give me this test: press m to turn posture mode on, sit in my real working position and press c, slump down for at least 5 seconds, lean closer to the screen for at least 5 seconds, then sit upright. If it warns while I am upright, ask me to press c again from my real working position. If it still warns incorrectly, change only one of the 10% lower, 15% bigger, or 5-second values and explain why. Preserve SIT UP, c, m, q, and local-only processing.

What does this prompt do?

The test isolates the lower-face threshold from the larger-face threshold. Recalibrating from your normal working position gives both comparisons a realistic baseline.

Changing one starting value at a time keeps the result easy to judge. You can connect any improvement to the threshold that changed.

Claude responds with the requested test sequence while preserving the existing labels and controls.

Before you run the final test, which movements do you expect the saved baseline to flag?

macOS

  • Start the finished alarm by running this command:
python3 habit_alarm.py

What does this command do?

The command starts the local webcam alarm from the activated .venv. It keeps running until you press q.

Windows

  • Start the finished alarm by running this command:
py habit_alarm.py

What does this command do?

The py launcher starts the local webcam alarm from the activated .venv. It keeps running until you press q.

  • Press m to turn posture mode on.
  • Sit in your real working position.
  • Press c to save that position as good posture.
  • Slump down for at least 5 seconds.

You should see the orange SIT UP label after five seconds. You should also hear lines/posture.wav play.

  • Return to the upright position you calibrated.

The SIT UP warning should clear when your face returns to the saved baseline.

  • Lean closer to the screen for at least 5 seconds.

You should see SIT UP again after your face remains more than 15% bigger than the baseline for five seconds.

  • Return to your calibrated upright position.
  • Press q to close the app.

Your warning clears when you sit upright again. This proves the alarm reacts to sustained posture changes without staying active after you recover.

Warning while sitting upright?

  • Press c again while sitting in your real working position.
  • Repeat the same five-second slump test.

If the warning continues, help me tune the posture warning.

Your alarm now catches sustained posture changes with a separate local recording. Next, you'll turn its reactions into a local CSV session log.

Use It While You Work

Your touch alarm and posture mode already react in real time. With Claude Code still running, you can turn those reactions into a session record.

A live alarm becomes useful evidence when it records each touch locally, summarizes a session, and can be demonstrated on screen.

In this step, get ready to:
  • Add local touch logging and a session summary.
  • Run the alarm during a short work session.
  • Record a demonstration of the working app.
Add local session logging

Session evidence records one row when a new touch begins. A local CSV log keeps the timestamp and face area available after the webcam window closes.

  • In the Claude Code session from earlier, update habit_alarm.py by pasting this exact prompt:
Update habit_alarm.py to log each newly counted face touch to touches.csv with a timestamp and one face-part label: forehead, cheek, chin, or mouth. Use Python's built-in csv module. When I press q, print the exact summary format touches: n in m min, most: part. Keep TOUCHING, TOUCHES: n, SIT UP, c, m, q, all starting thresholds, sounddevice audio, and local-only processing. Never save or upload webcam frames. Do not paste the full script into chat.

What does this prompt do?

  • Claude Code updates habit_alarm.py to create touches.csv when the first newly counted touch occurs.
  • Each row stores a timestamp plus one label from forehead, cheek, chin, or mouth.
  • The quit path calculates the session duration and most frequent face-part label before printing the summary.
  • The existing labels, controls, audio behavior, thresholds, and local processing stay in place.

Claude reports that touches.csv is created locally on the first touch. Claude also confirms that pressing q prints touches: n in m min, most: part.

Run a short work session

A real session checks whether the alarm can stay useful beyond a staged touch. It also gives the logger genuine events to summarize.

  • Ask Claude Code for the short session checklist by pasting this exact prompt:
Do not change habit_alarm.py. Give me a short real-session checklist: start the app, press m if I want posture mode, press c while sitting upright, leave the window visible in a corner while I work or study, and press q when finished. Remind me that only voice WAV files and touches.csv are saved, never webcam frames.

What does this prompt do?

The prompt asks Claude Code to guide the session without editing habit_alarm.py. It keeps the webcam privacy rule visible while you test the finished behavior.

Claude returns a checklist covering startup, optional posture mode, calibration, the work period, and the local files saved by the app.

Before you run the session, which local evidence do you expect the app to leave after you press q?

macOS

  • Run habit_alarm.py from the activated .venv terminal by running this command:
python3 habit_alarm.py

What does this command do?

The command starts habit_alarm.py with the active Python environment and keeps the process running until you press q.

Windows

  • Run habit_alarm.py from the activated .venv PowerShell session by running this command:
py habit_alarm.py

What does this command do?

The command uses the Windows Python launcher to start habit_alarm.py. The app keeps running until you press q.

  • Press m if you want posture mode active during the session.
  • Press c while sitting upright to save your current good-posture baseline.
  • Leave the webcam window visible in a corner while you work or study.
  • Press q when the short session is finished.

The app stays active during the session. Each newly counted touch adds a local row to touches.csv.

After you press q, the webcam window closes. The terminal prints a summary using the format touches: n in m min, most: part.

Record the proof

A short recording captures the visual warning, local audio, posture behavior, and session evidence in one demonstration. The result is easier to verify than a still image.

  • Ask Claude Code for the demonstration sequence by pasting this exact prompt:
Do not change the code. Give me a 30-second demo sequence: start screen recording, show the live labels, deliberately touch my face once so the zone turns red and a line plays, briefly demonstrate posture mode if calibrated, press q, and show the printed session summary plus touches.csv. Remind me not to share the recording if it contains anything private.

What does this prompt do?

The prompt asks for a timed demonstration without changing any code. It keeps the recording focused on the alarm reaction, posture mode, and local session evidence.

Your recording may contain private screen content. You control the file locally, so review it before sharing.

macOS

  • Start a screen recording with macOS Screenshot.
  • Press Shift-Command-5 to open the Screenshot controls.
  • Choose a screen-recording control.
  • Start the recording.

Your screen is now being recorded locally.

Windows

  • Start a screen recording with Xbox Game Bar.
  • Press Windows-Alt-R to start recording.

Your screen is now being recorded locally.

Before you start the app, what should one deliberate face touch add to the recording and the local session evidence?

macOS

  • Start the recorded demonstration by running this command from the activated .venv terminal:
python3 habit_alarm.py

What does this command do?

The command starts the finished local alarm so the recording can capture its labels, audio, and session summary.

Windows

  • Start the recorded demonstration by running this command from the activated .venv PowerShell session:
py habit_alarm.py

What does this command do?

The command starts the finished local alarm so the recording can capture its labels, audio, and session summary.

  • Keep the live labels visible in the recording.
  • Touch your face once so the face zone turns red and the local warning line plays.
  • Press m if posture mode is off.
  • Press c while sitting upright if posture mode needs calibration.
  • Slump for five seconds to demonstrate SIT UP if posture mode is calibrated.
  • Press q to close the app and print the session summary.
  • Show the printed session summary plus touches.csv by following Claude Code's demonstration sequence.

macOS

  • Stop the macOS Screenshot recording after the session summary and touches.csv are visible.
  • Use the recording control shown while recording to stop the capture.

Windows

  • Stop the Xbox Game Bar recording after the session summary and touches.csv are visible.
  • Press Windows-Alt-R to stop recording.

You should have a screen recording that shows a deliberate touch turning the face zone red, displaying TOUCHING, increasing TOUCHES: n, and playing the local warning line.

That is the proof captured. Your app now leaves a local touch log, prints a session summary, and demonstrates its response without saving webcam frames.

Secret mission

Build a Consented Voice-Line Set

Record three to five consented warnings that stay on your computer. Then update the alarm to avoid immediate repeats and escalate after three touches in one rolling minute.

Clean Up Your Resources

Clean Up Your Resources

Everything you created is stored locally, so keeping the habit-alarm folder does not add a usage charge.

Choose whether to keep your resources running, pause them for another session, or delete them entirely.

Cost warning

Keeping the local files does not create a usage charge.

Claude Code requires an eligible paid plan or Console account. Your plan's usage limits apply when you use Claude Code.

Resources you used:

  • The local habit-alarm folder containing .venv, the two MediaPipe model bundles, three Python scripts, lines/, the local WAV recordings, and touches.csv.
  • The Claude Code session running from the activated .venv inside habit-alarm.
  • The screen recording saved during your final demonstration.

Keep everything running

No action needed. Choose this if you want to keep testing the alarm or adjusting its local recordings.

  • Your habit-alarm folder remains intact with its environment, scripts, models, recordings, and touch log.
  • Your Claude Code session remains available from the activated .venv.
  • Your screen recording remains in its saved location.

Pause - I'll come back to this later

Stop the active processes to release the webcam and microphone. Keep every local file so you can continue from the same state later.

  • Return to the Claude Code session running from habit-alarm.
  • Press q in the webcam window if habit_alarm.py is running.
  • Close the Claude Code session.
  • Close the terminal window after Claude Code stops.
  • Return to the habit-alarm folder when you are ready to resume.
  • Reactivate .venv using the command from Step 1.
  • Start Claude Code from the activated environment.

The webcam and microphone stop once habit_alarm.py is closed. Your scripts, recordings, models, log, and screen recording remain available.

Delete - I don't want to use this again

Deleting the project folder permanently removes its scripts, models, environment, recordings, and touch log. Pause here if you want to keep any of those files.

  • Return to the Claude Code session running from habit-alarm.
  • Press q in the webcam window if habit_alarm.py is running.
  • Close the Claude Code session.
  • Delete the habit-alarm folder from its parent folder by running the commands for your operating system:

macOS

cd ..
rm -rf habit-alarm
What do these commands do?

The first command moves the terminal to the folder containing habit-alarm.

The second command permanently removes habit-alarm and everything stored inside it.

You should no longer see habit-alarm in its parent folder.

Windows

cd ..
rmdir /s /q habit-alarm
What do these commands do?

The first command moves the terminal to the folder containing habit-alarm.

The second command permanently removes habit-alarm and everything stored inside it.

You should no longer see habit-alarm in its parent folder.

  • Delete the screen recording from its saved location using the file manager for your operating system:

macOS

  • Go to the screen recording's saved location in Finder.
  • Delete the screen recording.
  • Confirm the recording no longer appears in that location.

Windows

  • Go to the screen recording's saved location in File Explorer.
  • Delete the screen recording.
  • Confirm the recording no longer appears in that location.

The habit-alarm folder and the screen recording are now removed from your computer.

Nice Work!

Nice Work!

You completed a private webcam habit alarm that catches sustained face touches. It also warns about slouching while keeping every webcam frame off disk.

You've learned how to:

  • Build a live face and hand tracker with the MediaPipe Tasks API in VIDEO mode. The Face Landmarker follows a 478-point face surface. The Hand Landmarker follows 21 points on each detected hand.
  • Turn landmark positions into a debounced face-touch alarm with a five-frame starting threshold. Show TOUCHING during sustained contact. Increase TOUCHES: n once per continuous touch. Play a local warning through sounddevice with a three-second cooldown.
  • Calibrate posture mode with c. Toggle it with m. Show SIT UP after sustained slouching. Save each new touch to touches.csv. Print touches: n in m min, most: part when q ends the session. Capture the working alarm in a screen-recorded demo.
  • Secret Mission: Add a consented voice-line set with three to five local warnings. Prevent the same line from playing twice in a row. Escalate to the highest-numbered line after three newly counted touches within one rolling minute.

Ready to quiz yourself?