Build a Claude Code Web Traffic Light
Build a local traffic light that shows Claude Code lifecycle status.
Introduction
30 Second Summary
When a coding assistant is working in another window, its status is easy to miss. You keep checking the screen just to learn whether it is busy, finished, or waiting for you.
In this project, you will build a browser traffic light that follows Claude Code as it works. Lifecycle hooks switch the display between red for active work, green for a finished response, or yellow when Claude is waiting for you.
What You'll Build
Your dark browser dashboard lights red during a Claude Code turn, green when the answer finishes, and yellow when Claude waits for your next prompt.
By the end of this project, you'll have:
- A browser traffic light where one large lamp glows at a time, making Claude Code's current state clear from across your desk.
- Direct control through local GET endpoints. Each request switches the light to red, yellow, or green in your browser.
- A private, fail-quiet integration that sends only a fixed colour signal and lets Claude Code continue silently when the local server is unavailable.
- Secret Mission: Record a clean one-take demo that shows the traffic light turning red, green, and yellow during a real Claude Code turn.
Are there any prerequisites?
No JavaScript experience is required. You need a supported Mac or 64-bit Windows computer, internet access, and an eligible account for Claude Code.
Before We Start
Before any setup begins, this step helps you commit to a local browser traffic light that makes Claude Code activity visible. Its signals are red for prompt submission, green for response completion, plus yellow for the idle_prompt notification.
Install the Tools and Open the Project
Your browser traffic light needs Node.js to run its local server. It needs Claude Code to emit the lifecycle events that change its colour.
This step creates a verified foundation on macOS or Windows. You will finish with an empty project folder open in two terminal windows.
In this step, get ready to:
- Install Node.js 26.13.1 LTS.
- Prepare Claude Code 2.1.322 or newer with an eligible signed-in account.
- Create the empty claude-traffic-light folder in two terminal windows.
Install and verify Node.js
Node.js provides the built-in HTTP tools that your traffic light uses later. Version 26.13.1 LTS gives this project a known runtime on both platforms.
- Open your operating system's app search.
- Search for Terminal on macOS or PowerShell on Windows.
- Select the matching app to open your first terminal window.
- Check the installed Node.js version by running this command:
node --version
What does this command do?
The node --version command asks the Node.js executable to print its installed version. The result reveals whether the required runtime is ready.
✔️ I see v26.13.1 or higher
Your installed Node.js version meets this project's requirement. The shared verification below confirms it from a fresh terminal.
ⓧ I see an older version
Your current Node.js version is below the project requirement. Install version 26.13.1 LTS for the same runtime used throughout this project.
macOS
- Visit the official Node.js release index.
- Download node-v26.13.1.pkg.
- Run node-v26.13.1.pkg from your Downloads folder.
- Follow the installer until it completes.
Windows
- Visit the official Node.js release index.
- Download node-v26.13.1-x64.msi.
- Run node-v26.13.1-x64.msi from your Downloads folder.
- Follow the installer until it completes.
ⓧ Command not found
Node.js is not installed yet. Use the official installer for your operating system.
macOS
- Visit the official Node.js release index.
- Download node-v26.13.1.pkg.
- Run node-v26.13.1.pkg from your Downloads folder.
- Follow the installer until it completes.
Windows
- Visit the official Node.js release index.
- Download node-v26.13.1-x64.msi.
- Run node-v26.13.1-x64.msi from your Downloads folder.
- Follow the installer until it completes.
- Close the terminal window used for the first check.
- Use your operating system's app search to open a fresh Terminal or PowerShell window.
- Verify the Node.js installation by running this command:
node --version
Why use a fresh terminal?
A fresh terminal reloads the command locations updated by the installer. This lets the shell find the newly installed Node.js executable.
You should see v26.13.1 or a later version number. Good progress. Your JavaScript runtime is now ready for the traffic-light server.
Still missing the Node.js version?
- Confirm that the Node.js installer reached its completion screen.
- Close every open terminal window before starting another version check.
- Download the installer again if the first installation stopped early.
Need a hand? Help me troubleshoot my Node.js 26.13.1 installation. You can also review the official Node.js download page.
Install and sign in to Claude Code
Claude Code supplies the prompt and response lifecycle that the traffic light represents. Version 2.1.322 or newer supports the hook configuration used later.
- Check the installed Claude Code version by running this command:
claude --version
What does this command check?
The claude --version command checks whether the Claude Code executable is available. It also prints the installed release number.
✔️ I see version 2.1.322 or higher
Your Claude Code release meets the project requirement. The next shared check confirms it from a fresh terminal.
ⓧ I see an older version
Your Claude Code release needs an update. The native installer replaces it with the current release.
macOS
The native installer may pause briefly while it downloads Claude Code. Leave the terminal open until the command finishes.
- Update Claude Code by running the official macOS installer command:
curl -fsSL https://claude.ai/install.sh | bash
What does this installer do?
This command downloads the official Claude Code installation script over HTTPS. It passes that script to Bash to install the native executable.
Windows
The native installer may pause briefly while it downloads Claude Code. Leave PowerShell open until the command finishes.
- Update Claude Code by running the official Windows PowerShell installer command:
irm https://claude.ai/install.ps1 | iex
What does this installer do?
This command downloads the official Claude Code PowerShell installation script. It passes that script to PowerShell for execution.
ⓧ Command not found
Claude Code is not installed yet. Use its official native installer for your operating system.
macOS
The native installer may pause briefly while it downloads Claude Code. Leave the terminal open until the command finishes.
- Install Claude Code by running the official macOS installer command:
curl -fsSL https://claude.ai/install.sh | bash
What does this installer do?
This command downloads the official Claude Code installation script over HTTPS. It passes that script to Bash to install the native executable.
Windows
The native installer may pause briefly while it downloads Claude Code. Leave PowerShell open until the command finishes.
- Install Claude Code by running the official Windows PowerShell installer command:
irm https://claude.ai/install.ps1 | iex
What does this installer do?
This command downloads the official Claude Code PowerShell installation script. It passes that script to PowerShell for execution.
- Close the terminal window used for the Claude Code installation.
- Use your operating system's app search to open a fresh Terminal or PowerShell window.
- Verify the Claude Code installation by running this command:
claude --version
Why check again?
This second check proves that a fresh terminal can locate the Claude Code executable. It also confirms that the installed release meets the minimum version.
You should see 2.1.322 (Claude Code) or a later version number followed by (Claude Code).
The sign-in flow happens in your browser. No credential belongs in the project folder.
- Start the Claude Code sign-in flow by running this command:
claude
What happens during sign-in?
Claude Code opens a browser authentication flow for an eligible paid plan or Console account. The terminal connects to that authenticated account after you finish the browser prompts.
- Follow the browser prompts to sign in with your eligible account.
- Return to the terminal after the authentication flow completes.
- Close this setup terminal after Claude Code confirms the signed-in session.
Your Claude Code installation is now authenticated. The next launch can begin directly inside the traffic-light folder.
Installation or sign-in stuck?
- Confirm that your internet connection is active.
- Open the browser window launched by Claude Code if it is waiting behind another window.
- Confirm that the account has eligible Claude Code access.
Need help? Help me troubleshoot my Claude Code installation or browser sign-in. You can also follow the official Claude Code setup guide.
Create the project folder and separate the terminals
The project needs one terminal for Claude Code. A second terminal keeps the future Node.js server running without blocking your Claude Code session.
- Use your operating system's app search to open a new Terminal or PowerShell window.
macOS
- Create ~/claude-traffic-light and enter it by running these commands:
mkdir ~/claude-traffic-light
cd ~/claude-traffic-light
What do these commands do?
- The first command creates the empty claude-traffic-light folder inside your home folder.
- The second command moves this terminal into that folder.
Your first terminal now points to ~/claude-traffic-light. Reserve this window for Claude Code.
- Use your operating system's app search to open a second Terminal window.
- Enter the same project folder in the second window by running this command:
cd ~/claude-traffic-light
Why enter the folder again?
Each terminal keeps its own current location. This command points the second terminal at the same empty project folder.
Reserve the second terminal for the Node.js server you build next.
Windows
- Create $env:USERPROFILE\claude-traffic-light and enter it by running these commands:
mkdir $env:USERPROFILE\claude-traffic-light
cd $env:USERPROFILE\claude-traffic-light
What do these commands do?
- The first command creates the empty claude-traffic-light folder inside your user profile.
- The second command moves this PowerShell window into that folder.
Your first PowerShell window now points to $env:USERPROFILE\claude-traffic-light. Reserve this window for Claude Code.
- Use your operating system's app search to open a second PowerShell window.
- Enter the same project folder in the second window by running this command:
cd $env:USERPROFILE\claude-traffic-light
Why enter the folder again?
Each PowerShell window keeps its own current location. This command points the second window at the same empty project folder.
Reserve the second PowerShell window for the Node.js server you build next.
Before you run the final check, which two version lines do you expect the fresh second terminal to print?
- Verify both installed tools from the second terminal by running these commands:
node --version
claude --version
What does this final check prove?
These commands confirm that both terminal windows can use the installed tools. They also prove that the environment is ready before any project file is created.
You should see v26.13.1 for Node.js. You should also see 2.1.322 (Claude Code) or a newer Claude Code release.
Different result in the second terminal?
- Confirm that the second terminal was opened after both installations completed.
- Close the second terminal if either command is missing.
- Open another fresh terminal before repeating the version check.
Still stuck? Help me diagnose why my fresh terminal cannot find Node.js or Claude Code.
Your tools are installed. Your account is authenticated. Next, you will ask Claude Code to build the first visible traffic-light server.
Build the Web Traffic Light
Your tools are ready. Your empty claude-traffic-light folder gives you a clean place to build the first visible part of the project.
The future hooks need a display they can control. In this step, you will use Claude Code to build a local HTTP server. You will prove each colour works through direct requests before adding automation.
In this step, get ready to:
- Generate server.js from a plain-English prompt.
- Run the local server in the reserved server terminal.
- Test every colour through its local endpoint.
Ask Claude Code to create the server
A detailed prompt can give Claude Code the page design plus the server behaviour in one request. The result lives in a single server.js file.
- Switch back to the project terminal reserved for Claude Code.
- Start a Claude Code session by running this command:
claude
What does this command do?
The claude command starts an interactive Claude Code session inside your existing claude-traffic-light folder. Files approved in this session are created inside that folder.
Claude Code did not start?
- Confirm you switched to the project terminal from the previous step.
- Confirm the terminal path ends with claude-traffic-light.
Still stuck? Help me start Claude Code inside my claude-traffic-light folder.
Claude Code asks for permission before creating server.js. This gives you a chance to review the requested file change.
- Paste this build prompt into Claude Code:
Build a beginner-friendly web traffic light in one file named server.js. Use only Node.js's built-in node:http module. Bind to 127.0.0.1 on port 3000. Serve a dark page at / with three large stacked circles labelled red, yellow, and green. Keep one current colour in memory, starting green. Add GET endpoints /red, /yellow, and /green that change the state and return JSON, plus /state that returns the current colour. Have the page poll /state every 500 ms and light only the matching circle. Print the local URL when the server starts. Do not install packages.
What are you asking Claude to build?
- The server uses the built-in node:http module.
- The page contains three stacked lamps.
- Four GET endpoints expose the current colour.
- Browser polling checks the current state every 500 milliseconds.
- Submit the prompt.
- Review Claude Code's proposed creation of server.js.
- Approve the file creation.
That is your first build complete. Claude Code has created the entire traffic-light server from your description.
Do not see server.js?
- Check that you approved the requested file creation.
- Check that the Claude Code session started inside claude-traffic-light.
Need a hand? Help me find why Claude Code did not create server.js.
- Compare your generated server.js with this checkpoint:
✔️ Awesome, I've got everything!
Your server.js is ready for its first run.
ⓧ I'd like to double check the full code
const http = require("node:http");
const hostname = "127.0.0.1";
const port = 3000;
const allowedColors = new Set(["red", "yellow", "green"]);
let currentColor = "green";
const page = `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Claude Code Traffic Light</title>
<style>
:root {
color-scheme: dark;
font-family: system-ui, sans-serif;
}
body {
min-height: 100vh;
margin: 0;
display: grid;
place-items: center;
background: #101216;
color: #f5f7fa;
}
main {
text-align: center;
}
.housing {
width: 190px;
margin: 24px auto;
padding: 24px;
display: grid;
gap: 20px;
border: 6px solid #4a4f58;
border-radius: 32px;
background: #20242b;
box-shadow: 0 22px 60px #000a;
}
.bulb {
width: 140px;
aspect-ratio: 1;
margin: 0 auto;
border-radius: 50%;
background: #343941;
border: 4px solid #111318;
transition: background 160ms ease, box-shadow 160ms ease;
}
#red.active {
background: #ff3b30;
box-shadow: 0 0 42px #ff3b30;
}
#yellow.active {
background: #ffd60a;
box-shadow: 0 0 42px #ffd60a;
}
#green.active {
background: #30d158;
box-shadow: 0 0 42px #30d158;
}
#status {
min-height: 1.5em;
color: #c7cbd1;
}
</style>
</head>
<body>
<main>
<h1>Claude Code Traffic Light</h1>
<div class="housing" aria-label="Traffic light status">
<div class="bulb" id="red" aria-label="Red"></div>
<div class="bulb" id="yellow" aria-label="Yellow"></div>
<div class="bulb" id="green" aria-label="Green"></div>
</div>
<p id="status">Connecting to the local server...</p>
</main>
<script>
const bulbs = document.querySelectorAll(".bulb");
const status = document.querySelector("#status");
async function refreshLight() {
try {
const response = await fetch("/state");
const state = await response.json();
bulbs.forEach((bulb) => {
bulb.classList.toggle("active", bulb.id === state.color);
});
status.textContent = state.color.toUpperCase() + " is on";
} catch {
status.textContent = "Local server unavailable";
}
}
refreshLight();
setInterval(refreshLight, 500);
</script>
</body>
</html>`;
function send(response, statusCode, contentType, body) {
response.writeHead(statusCode, {
"Content-Type": contentType,
"Cache-Control": "no-store"
});
response.end(body);
}
const server = http.createServer((request, response) => {
if (request.method !== "GET") {
send(response, 405, "text/plain; charset=utf-8", "Method not allowed");
return;
}
if (request.url === "/") {
send(response, 200, "text/html; charset=utf-8", page);
return;
}
if (request.url === "/state") {
send(
response,
200,
"application/json; charset=utf-8",
JSON.stringify({ color: currentColor })
);
return;
}
const requestedColor = request.url.slice(1);
if (allowedColors.has(requestedColor)) {
currentColor = requestedColor;
send(
response,
200,
"application/json; charset=utf-8",
JSON.stringify({ color: currentColor })
);
return;
}
send(response, 404, "text/plain; charset=utf-8", "Not found");
});
server.listen(port, hostname, () => {
console.log(`Traffic light running at http://${hostname}:${port}/`);
});
Start the local traffic light
The server stores one colour in memory. It also serves the dashboard that displays that colour.
The server process occupies its terminal until you stop it with Ctrl+C. The browser can reach it while that process remains active.
- Switch back to the server terminal from the previous step.
Before you start the server, what local address do you expect it to print?
- Start the traffic-light server by running this command:
node server.js
What does this command start?
- Node.js runs the code inside server.js.
- The server listens on 127.0.0.1 at port 3000.
- The terminal remains attached to the running server process.
You will see Traffic light running at http://127.0.0.1:3000/ in the server terminal.
macOS
- Press Cmd+Space to open Spotlight.
- Type Safari.
- Press Enter to open Safari.
- Click the browser address bar.
- Enter http://127.0.0.1:3000/.
- Press Enter to load the traffic light.
Windows
- Press the Windows key to open the Start menu.
- Type Microsoft Edge.
- Press Enter to open Microsoft Edge.
- Click the browser address bar.
- Enter http://127.0.0.1:3000/.
- Press Enter to load the traffic light.
Your first visible win is live. You will see a dark traffic-light housing with the green circle illuminated.
Do not see the green lamp?
- Check that the server terminal still shows the local traffic-light address.
- Check that the browser address is exactly http://127.0.0.1:3000/.
- Restart the server if the server terminal has returned to its command prompt.
Still no light? Help me troubleshoot my local Node.js traffic-light server.
Test every colour endpoint
Each colour has its own local path. A request changes currentColor. The browser reads the updated value from /state every 500 milliseconds.
Before you send the requests, what lamp sequence do you expect to see in the browser?
macOS
- Switch back to the Terminal app from earlier.
- Open a third Terminal window by pressing Cmd+N.
- Keep the browser visible beside the new terminal.
- Send each colour request one at a time by running these commands:
curl http://127.0.0.1:3000/red
curl http://127.0.0.1:3000/yellow
curl http://127.0.0.1:3000/green
What do these requests do?
- The first request sets currentColor to red.
- The second request sets currentColor to yellow.
- The third request sets currentColor to green.
Windows
- Press the Windows key to open the Start menu.
- Type Windows PowerShell.
- Press Enter to open a third terminal window.
- Keep the browser visible beside the new terminal.
- Send each colour request one at a time by running these commands:
curl.exe http://127.0.0.1:3000/red
curl.exe http://127.0.0.1:3000/yellow
curl.exe http://127.0.0.1:3000/green
What do these requests do?
- The first request sets currentColor to red.
- The second request sets currentColor to yellow.
- The third request sets currentColor to green.
After the first request, you will see the red circle illuminate. After the second request, you will see the yellow circle illuminate.
After the final request, you will see the green circle illuminate again. Each change proves the browser can read the current colour through /state.
Light did not change?
- Check that node server.js is still running in the server terminal.
- Check that each request uses port 3000.
- Use curl.exe in Windows PowerShell.
Need help? Help me find why my colour endpoints do not update the browser traffic light.
Your browser traffic light now responds to direct local requests. Next, you will connect those colours to Claude Code's lifecycle events.
Connect Claude Code Hooks
Your browser traffic light already responds to direct requests sent to the local HTTP server. Lifecycle hooks can now connect those colours to real activity inside Claude Code.
You will begin with the smallest possible hook sender. An availability test will show how that version behaves when the display cannot receive a request.
In this step, get ready to:
- Ask Claude Code to create the project-scoped hook files.
- Watch a real Claude Code turn drive the lifecycle colours.
- Test the hook while the local server is unavailable.
Create the project-scoped hooks
A project-scoped settings file applies only inside the claude-traffic-light folder. Each lifecycle event can run a command with one fixed colour argument.
Why use a command hook wrapper?
A command hook receives event data through standard input. This wrapper ignores that input completely.
The only request it sends is a fixed colour path such as /red. Prompts and code stay inside Claude Code.
Claude Code asks for permission before creating the hook files. You will approve the proposed changes after it shows you the file paths.
- Return to the Claude Code project terminal from earlier.
- Create the project-scoped hook files by submitting this prompt:
Add project-scoped Claude Code hooks. Create .claude/hooks/set-light.js as a deliberately simple first version that takes one colour argument and calls http://127.0.0.1:3000/<colour> with node:http. Do not read stdin. Create .claude/settings.json with minimumVersion 2.1.322 and command hooks that run node in exec form: UserPromptSubmit sends red, Stop sends green, and Notification with the idle_prompt matcher sends yellow. Use ${CLAUDE_PROJECT_DIR} for the script path. Do not add error handling yet.
What is Claude creating?
- The .claude/hooks/set-light.js file uses the built-in Node.js HTTP client to send one colour request.
- The .claude/settings.json file maps each Claude Code lifecycle event to its colour.
- The minimumVersion value requires Claude Code version 2.1.322 or newer.
- The ${CLAUDE_PROJECT_DIR} placeholder points to the folder where this Claude Code session started.
- Approve Claude Code's requested file changes.
Claude Code confirms that it created both hook files. The existing server.js file remains unchanged.
✔️ Awesome, I've got everything!
Your hook sender and project settings are ready. Keep the local server running in the server terminal.
ⓧ I'd like to double check the full code
.claude/hooks/set-light.js
- Compare .claude/hooks/set-light.js with this complete reference:
const http = require("node:http");
const color = process.argv[2];
http.get("http://127.0.0.1:3000/" + color);
.claude/settings.json
- Compare .claude/settings.json with this complete reference:
{
"minimumVersion": "2.1.322",
"hooks": {
"UserPromptSubmit": [
{
"hooks": [
{
"type": "command",
"command": "node",
"args": [
"${CLAUDE_PROJECT_DIR}/.claude/hooks/set-light.js",
"red"
]
}
]
}
],
"Notification": [
{
"matcher": "idle_prompt",
"hooks": [
{
"type": "command",
"command": "node",
"args": [
"${CLAUDE_PROJECT_DIR}/.claude/hooks/set-light.js",
"yellow"
]
}
]
}
],
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "node",
"args": [
"${CLAUDE_PROJECT_DIR}/.claude/hooks/set-light.js",
"green"
]
}
]
}
]
}
}
server.js
- Confirm that server.js still matches this complete reference:
const http = require("node:http");
const hostname = "127.0.0.1";
const port = 3000;
const allowedColors = new Set(["red", "yellow", "green"]);
let currentColor = "green";
const page = `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Claude Code Traffic Light</title>
<style>
:root {
color-scheme: dark;
font-family: system-ui, sans-serif;
}
body {
min-height: 100vh;
margin: 0;
display: grid;
place-items: center;
background: #101216;
color: #f5f7fa;
}
main {
text-align: center;
}
.housing {
width: 190px;
margin: 24px auto;
padding: 24px;
display: grid;
gap: 20px;
border: 6px solid #4a4f58;
border-radius: 32px;
background: #20242b;
box-shadow: 0 22px 60px #000a;
}
.bulb {
width: 140px;
aspect-ratio: 1;
margin: 0 auto;
border-radius: 50%;
background: #343941;
border: 4px solid #111318;
transition: background 160ms ease, box-shadow 160ms ease;
}
#red.active {
background: #ff3b30;
box-shadow: 0 0 42px #ff3b30;
}
#yellow.active {
background: #ffd60a;
box-shadow: 0 0 42px #ffd60a;
}
#green.active {
background: #30d158;
box-shadow: 0 0 42px #30d158;
}
#status {
min-height: 1.5em;
color: #c7cbd1;
}
</style>
</head>
<body>
<main>
<h1>Claude Code Traffic Light</h1>
<div class="housing" aria-label="Traffic light status">
<div class="bulb" id="red" aria-label="Red"></div>
<div class="bulb" id="yellow" aria-label="Yellow"></div>
<div class="bulb" id="green" aria-label="Green"></div>
</div>
<p id="status">Connecting to the local server...</p>
</main>
<script>
const bulbs = document.querySelectorAll(".bulb");
const status = document.querySelector("#status");
async function refreshLight() {
try {
const response = await fetch("/state");
const state = await response.json();
bulbs.forEach((bulb) => {
bulb.classList.toggle("active", bulb.id === state.color);
});
status.textContent = state.color.toUpperCase() + " is on";
} catch {
status.textContent = "Local server unavailable";
}
}
refreshLight();
setInterval(refreshLight, 500);
</script>
</body>
</html>`;
function send(response, statusCode, contentType, body) {
response.writeHead(statusCode, {
"Content-Type": contentType,
"Cache-Control": "no-store"
});
response.end(body);
}
const server = http.createServer((request, response) => {
if (request.method !== "GET") {
send(response, 405, "text/plain; charset=utf-8", "Method not allowed");
return;
}
if (request.url === "/") {
send(response, 200, "text/html; charset=utf-8", page);
return;
}
if (request.url === "/state") {
send(
response,
200,
"application/json; charset=utf-8",
JSON.stringify({ color: currentColor })
);
return;
}
const requestedColor = request.url.slice(1);
if (allowedColors.has(requestedColor)) {
currentColor = requestedColor;
send(
response,
200,
"application/json; charset=utf-8",
JSON.stringify({ color: currentColor })
);
return;
}
send(response, 404, "text/plain; charset=utf-8", "Not found");
});
server.listen(port, hostname, () => {
console.log(`Traffic light running at http://${hostname}:${port}/`);
});
Claude did not create both files?
- Check Claude Code's response for a pending file permission request.
- Confirm that the paths begin with .claude/ inside the current project.
- Submit the build prompt again if Claude only created one file.
Still missing a file? Help me check why Claude Code did not create both project-scoped hook files.
Verify the lifecycle mappings
Claude Code includes a hooks browser for checking the events loaded from your settings. This gives you a visible checkpoint before you test a real turn.
- Open the configured hooks browser by entering this slash command:
/hooks
What should appear?
You should see entries under UserPromptSubmit, Stop, and Notification. The Notification mapping uses the idle_prompt matcher.
These entries prove Claude Code loaded the project-scoped settings.
Now the browser can reveal whether the events fire in the intended order. Before you submit the next prompt, which colour do you expect to see first?
- Submit this prompt in Claude Code:
Reply with one short sentence about traffic lights.
How did the turn control the light?
- The UserPromptSubmit hook sends red before Claude processes the prompt.
- The Stop hook sends green after Claude finishes its response.
That is the first automatic cycle working. Your traffic light now follows the start and finish of a real Claude Code turn.
The yellow check takes about 60 seconds because idle_prompt waits for an inactive session. A quiet pause here means Claude Code is waiting for your next input.
- Avoid pressing any keys for about 60 seconds.
You will see the yellow lamp illuminate after the idle notification fires.
Did one of the colours stay off?
- Confirm that the server terminal still shows the local server running.
- Return to the hooks browser to confirm all three event mappings are loaded.
- Restart the Claude Code session if recent settings changes have not appeared.
Need help tracing the missing state? Help me identify which Claude Code hook is not changing my traffic light.
Test the hook with the server offline
The hook now works while its local destination is available. An availability test shows what the same sender does when that destination disappears.
- Return to the server terminal from earlier.
- Stop the local server by pressing Ctrl+C.
Before you submit another prompt, do you think the hook can contact the stopped server? Watch whether Claude still receives your prompt.
- Submit this prompt in Claude Code:
Reply with the word testing.
The connection failure is intentional
You will see a hook error because the sender cannot reach the stopped local server. Claude Code still receives the prompt and answers it.
This proves the hook failure is non-blocking. It also exposes the noise created by the deliberately simple sender.
You found the exact weakness this test was designed to reveal. The optional display can disappear without stopping the coding session.
Did the expected hook error stay hidden?
- Confirm that the server process stopped after you pressed Ctrl+C.
- Check the hooks browser for the UserPromptSubmit mapping.
- Compare the hook sender with the deliberately simple reference above.
Still seeing a different result? Help me reproduce the offline hook test without changing the naive sender.
Your lifecycle integration works, and its first failure boundary is now visible. Next, you will make the hook stay silent whenever the local display is unavailable.
Make the Hooks Fail Quietly
Your Claude Code lifecycle hooks now control the browser light. Stopping the local server exposed a noisy connection failure.
The traffic light is optional status infrastructure. In this step, you'll add a fail-quiet boundary so its absence never distracts from your coding session.
In this step, get ready to:
- Harden the colour sender with a fail-quiet boundary.
- Prove Claude Code stays quiet while the server is stopped.
- Restart the server to verify the red, green, and yellow lifecycle.
Harden the hook wrapper
The current wrapper assumes the local server is always available. A reliable wrapper limits accepted colours, consumes successful responses, and treats connection failures as silent no-ops.
The server remains stopped from the previous test. Claude Code may show one final hook error when this repair prompt invokes the old wrapper.
- Paste this repair prompt into the Claude Code project terminal from earlier:
Harden .claude/hooks/set-light.js so a missing or slow local server never interrupts Claude Code. Keep node:http and the fixed colour argument. Allow only red, yellow, and green. Consume successful responses with response.resume(). Add an error listener that prints nothing and a 1000 ms timeout that destroys the request. Ignore all stdin and exit successfully. Do not change the event mappings.
What does this repair change?
- The allowlist restricts requests to the three colour paths used by the project.
- Calling response.resume() consumes the successful HTTP response data.
- The silent error listener absorbs local connection failures.
- The timeout destroys a request that takes longer than 1000 ms.
- Ignoring stdin keeps the hook event data outside the local request.
- Approve the requested edit to .claude/hooks/set-light.js.
- Wait for Claude Code to finish updating the wrapper.
The target file is short enough to compare in one view. Use the matching tab to check the completed wrapper.
✔️ Awesome, I've got everything!
Your wrapper now has the allowlist, silent error handling, response consumption, and timeout protection it needs.
ⓧ I'd like to double check the full code
const http = require("node:http");
const allowedColors = new Set(["red", "yellow", "green"]);
const color = process.argv[2];
if (!allowedColors.has(color)) {
process.exit(0);
}
const request = http.get(
"http://127.0.0.1:3000/" + color,
(response) => {
response.resume();
}
);
request.on("error", () => {});
request.setTimeout(1000, () => {
request.destroy();
});
How does the final wrapper work?
- The allowedColors set accepts only the three project states.
- The http.get callback consumes a successful response with response.resume().
- The error listener produces no output when the server is unavailable.
- The timeout destroys a slow request after 1000 ms.
- The script never reads stdin.
Does your generated file look different?
- Check that Claude Code edited .claude/hooks/set-light.js inside your claude-traffic-light folder.
- Compare the allowlist, response callback, error listener, and timeout with the full-code tab.
Still seeing a mismatch? Help me compare my hook wrapper with the target code.
Prove the offline hook stays quiet
A fail-quiet hook translates local networking failures into successful no-ops. Claude Code remains focused on the prompt even when the display is unavailable.
Before you submit, consider whether Claude will answer cleanly while the server stays offline.
- Submit this short prompt in the Claude Code project terminal:
Reply with one short sentence about resilient automation.
What should you see?
Claude Code answers the prompt normally. No hook error appears before or after the response.
The wrapper receives fixed colour arguments during the turn. Failed local requests produce no output.
That is the reliability win: your coding session now continues cleanly without the optional display.
Still seeing a hook error?
- Check that request.on("error", () => {}); appears near the bottom of .claude/hooks/set-light.js.
- Check that the timeout calls request.destroy().
- Restart the current Claude Code session if the updated settings have not taken effect after a few seconds.
Need help tracing the failure? Help me find why my fail-quiet hook still reports an error.
The clean run also proves a privacy boundary. Command hooks receive event data through stdin, but this wrapper never reads it.
What leaves Claude Code?
Prompt text, code, and hook JSON stay outside the request. Only an allowlisted colour becomes part of the local endpoint path.
This data minimization keeps the integration limited to the status signal it needs.
Verify the full lifecycle
The failure boundary is working. Restarting the local server reconnects the same wrapper to the browser dashboard.
- Return to the server terminal from earlier and restart the traffic-light server by running:
node server.js
What should the terminal show?
The terminal prints Traffic light running at http://127.0.0.1:3000/. The process stays active so it can receive colour requests.
- Switch back to the browser dashboard from earlier.
- Refresh http://127.0.0.1:3000/.
- Place the browser beside the Claude Code project terminal.
You'll see the green circle illuminated because each server start resets the current colour to green.
Before you submit, consider which colour will appear first and which colour will follow when Claude finishes.
- Submit this final prompt in Claude Code:
Reply with one short sentence about reliable automation.
How does the lifecycle unfold?
- The UserPromptSubmit event sends red before Claude processes the prompt.
- The Stop event sends green when Claude finishes responding.
- The idle_prompt notification sends yellow after the idle delay.
You'll see red while Claude starts the turn. You'll see green when the response finishes.
The final yellow state takes about 60 seconds because Claude Code waits before sending the idle notification. The pause is expected.
- Avoid pressing any keys while Claude Code waits for the next prompt.
You'll see the yellow circle illuminate after the idle delay. This completes the red, green, and yellow lifecycle.
You have closed the failure boundary. The light now tracks Claude Code when available without creating noise when unavailable.
Missing one of the colours?
- Check that the server terminal still shows the running process.
- Confirm the browser dashboard is open at http://127.0.0.1:3000/.
- Leave Claude Code untouched for the full idle delay before checking for yellow.
Still missing a state? Help me trace which lifecycle hook is not changing the traffic light.
Secret mission
Record the Red-Yellow-Green Demo
Turn your working traffic light into a one-take proof. Record the browser beside Claude Code as a real prompt produces red, green, and yellow in sequence.
Clean Up Your Resources
Clean Up Your Resources
Your local server, browser tools, and screen recording add no usage charges, while Claude Code uses the limits or credits attached to your account. Decide whether to keep the project running, pause it for later, or delete its local resources.
Resources you used:
- The local server process running at http://127.0.0.1:3000/.
- The claude-traffic-light folder in your home directory. Its path is ~/claude-traffic-light on macOS or $env:USERPROFILE\claude-traffic-light on Windows. It contains server.js, .claude/settings.json, and .claude/hooks/set-light.js.
- The saved screen recording on the Desktop on macOS or under Videos\Captures on Windows.
Keep everything running
No action needed. Choose this if you want the traffic light to keep following your Claude Code session.
- Leave the server terminal running.
- Keep the browser dashboard open at http://127.0.0.1:3000/.
- Leave the Claude Code project terminal open.
- Keep the claude-traffic-light folder in your home directory.
- Keep the screen recording in its saved location.
Pause - I'll come back to this later
Shut down the local server to free the terminal while preserving every file. The fail-quiet hooks let Claude Code continue without a hook error while the server is off.
- Switch back to the server terminal from earlier.
- Press Ctrl+C to stop the server.
- Close the browser dashboard.
- Keep the claude-traffic-light folder in your home directory.
- Keep the screen recording in its saved location.
The server terminal returns to its prompt. Your project files remain ready for the next session.
Delete - I don't want to use this again
Deleting these files is permanent once they leave Trash or the Recycle Bin. Your global Claude Code settings stay untouched because this integration lives inside the project folder.
- Exit Claude Code in the project terminal.
- Switch back to the server terminal from earlier.
- Press Ctrl+C to stop the server.
- Locate ~/claude-traffic-light on macOS or $env:USERPROFILE\claude-traffic-light on Windows with your file manager.
- Move the claude-traffic-light folder to Trash on macOS or the Recycle Bin on Windows.
- Locate the saved recording on the Desktop on macOS or under Videos\Captures on Windows.
- Move the recording to Trash on macOS or the Recycle Bin on Windows.
The server terminal returns to its prompt after Ctrl+C. The project folder and recording disappear from their original locations.
Removing the project folder also removes its project-scoped hooks. No global Claude Code configuration changes are needed.
Nice Work!
Nice Work!
You did it! Your web traffic light now mirrors Claude Code lifecycle events in real time.
You've learned how to:
- Built a browser traffic light with Node.js. Its local HTTP endpoints control the three colour states.
- Mapped lifecycle hooks to the dashboard. UserPromptSubmit selects red. Stop selects green. The idle_prompt notification selects yellow.
- Built a fail-quiet hook wrapper that keeps Claude Code responsive when the local server is unavailable. It ignores hook stdin. It transmits only a fixed colour path.
- Completed the Secret Mission by recording a clean demo of the real prompt lifecycle. The recording shows red during submission. It shows green after completion. It shows yellow after the idle delay.
Ready to quiz yourself?