Skip to content

hooks: drop Electron port-file discovery - #8

Open
ninedter wants to merge 1 commit into
mainfrom
claude/hook-drop-electron-portfile
Open

ninedter wants to merge 1 commit into
mainfrom
claude/hook-drop-electron-portfile

Conversation

@ninedter

Copy link
Copy Markdown
Owner

Follow-up to #7, which retired the Electron shell but left hooks/ alone.

What changed

  • hooks/agent-monitor-hook.py: removed the server-port file probe, its 0.75s budget, the delete-on-ConnectionRefused stale-file cleanup, and the comments about SIGKILLed Electron and unclean exits. read_candidate_ports() now returns [DOCKER_MONITOR_PORT or 3789, 3000] with duplicates removed.
  • hooks/claude-hooks-config.json: _comment no longer mentions the Electron port file.
  • README.md: dropped the troubleshooting tip about deleting the leftover port file. The hook no longer reads it, so the tip doesn't apply.

Unchanged

  • Local discovery of :3789 (Docker, DOCKER_MONITOR_PORT) and :3000, posting to every listening instance with the same 3s timeout.
  • The MONITOR_URL override path (HTTP/HTTPS, bounded post).
  • The edge shipper (hooks/edge-hook.sh, edge/), not touched.

Testing

Run against the Docker hub on :3789 (/api/live → 200; nothing on :3000; no port file present):

$ bash hooks/test-hook.sh
PreToolUse: exit=0 374ms
PostToolUse: exit=0 97ms
Stop: exit=0 96ms
SubagentStop: exit=0 88ms
SessionStart: exit=0 92ms
SessionEnd: exit=0 87ms
Notification: exit=0 103ms

All 7 events show up in GET /api/monitor/events under hook-smoke-test. A MONITOR_URL=http://127.0.0.1:3789 Stop event also arrived. grep -rni electron hooks/ comes back empty.

🤖 Generated with Claude Code

The Electron shell is gone (#7), so nothing writes
~/Library/Application Support/llm-usage-tracker/server-port anymore. Remove
the hook's port-file probe, its short-timeout/stale-file cleanup branch, and
the Electron comments. Local discovery is now :3789 (DOCKER_MONITOR_PORT)
then :3000, each with the same 3s budget as before; MONITOR_URL and the edge
shipper are untouched. Also drop the README tip about deleting the leftover
port file, which no longer affects the hook.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T06:45:08.356014Z c9bc0a5 PR opened
🔒 Security Review ✅ Completed 2026-10-20T06:45:39.524508Z c9bc0a5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c9bc0a5fa0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 12 to +15
def read_candidate_ports():
"""Yield (port, from_file) pairs. from_file marks the server-port entry:
it is the least trustworthy candidate — Electron killed with SIGKILL used
to leave it pointing at an orphaned server that accepts TCP but never
answers HTTP, so it gets a shorter timeout and stale-file cleanup below."""
ports = []
try:
with open(PORT_FILE) as f:
ports.append((int(f.read().strip()), True))
except (OSError, ValueError):
pass
ports.append((int(os.environ.get("DOCKER_MONITOR_PORT", "3789")), False))
ports.append((3000, False))
seen, out = set(), []
for p, from_file in ports:
if p not in seen:
seen.add(p)
out.append((p, from_file))
return out
"""Local tracker ports to try: the Docker hub, then a `next dev` server."""
ports = [int(os.environ.get("DOCKER_MONITOR_PORT", "3789")), 3000]
return list(dict.fromkeys(ports))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove the remaining port-file discovery claim

After this change the hook only tries DOCKER_MONITOR_PORT and port 3000, but the primary hook-setup documentation in README.md:163 still says it also discovers a leftover legacy port file. Users following that section may expect an Electron/legacy instance on a dynamic port to receive events when it no longer can, so update that remaining description alongside the other documentation changes.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant