Skip to content

feat: add hook env vars (folder, branch) and fix dtach cleanup#56

Merged
neumie merged 3 commits intomainfrom
neumie/hook-env-vars-and-dtach-fix
Mar 25, 2026
Merged

feat: add hook env vars (folder, branch) and fix dtach cleanup#56
neumie merged 3 commits intomainfrom
neumie/hook-env-vars-and-dtach-fix

Conversation

@neumie
Copy link
Copy Markdown
Contributor

@neumie neumie commented Mar 23, 2026

Summary

  • Add OKENA_FOLDER_ID and OKENA_FOLDER_NAME environment variables to all hook types, with parent-folder fallback for worktree projects
  • Add OKENA_BRANCH to terminal hooks (on_create, shell_wrapper, on_close) for worktree projects
  • Fix orphaned dtach daemons by calling kill_session() on natural PTY exit and cleaning up stale sockets on startup

Changes

Hook environment variables

  • project_env() now accepts optional folder_id/folder_name and sets OKENA_FOLDER_ID/OKENA_FOLDER_NAME
  • All fire_* functions propagated with folder params
  • folder_for_project_or_parent() helper falls back to parent project's folder for worktrees
  • terminal_hook_env() includes OKENA_BRANCH for worktree projects
  • on_worktree_close hook now correctly receives the branch name resolved before worktree deletion

dtach cleanup

  • pty_manager.kill() called on natural PTY exit (prevents orphaned dtach daemons)
  • Stale dtach sockets cleaned up on startup via PtyManager::cleanup_stale_sockets()

Documentation

  • docs/hooks.md updated with new FOLDER_* variables in base vars table and availability matrix

Test plan

  • Set terminal.on_create hook that echoes $OKENA_FOLDER_ID $OKENA_FOLDER_NAME — verify populated for projects in folders
  • Verify folder vars are empty for top-level projects (not in any folder)
  • Verify worktree projects inherit parent's folder vars
  • Verify OKENA_BRANCH is set in terminal hooks for worktree projects
  • Verify no orphaned dtach processes after closing terminals
  • cargo test — all tests pass

neumie and others added 3 commits March 24, 2026 18:25
Terminal hooks (on_create, shell_wrapper) previously received zero
environment variables. Now they export OKENA_PROJECT_ID, OKENA_PROJECT_NAME,
OKENA_PROJECT_PATH, and OKENA_BRANCH (for worktree projects) into the
shell session so they persist after the hook command runs.

Also adds OKENA_TERMINAL_NAME and OKENA_BRANCH to terminal.on_close,
and fixes on_worktree_close being the only worktree hook missing
OKENA_BRANCH.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
After a crash or ungraceful exit, dtach socket files in /tmp/okena-<uid>/
were left behind indefinitely. Add a startup cleanup that scans the socket
directory, checks each .sock file with lsof, and removes any that have no
active process — preventing unbounded accumulation of orphaned sockets.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Folder context was missing from hook environment variables. Add folder_id
and folder_name to project_env() and propagate through all fire_* functions.
For worktree projects, falls back to the parent project's folder.

Also includes the missing pty_manager.kill() call on natural terminal exit
to prevent orphaned dtach daemons.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@neumie neumie force-pushed the neumie/hook-env-vars-and-dtach-fix branch from 8a1e19c to 81baa50 Compare March 25, 2026 09:12
@neumie neumie merged commit 47f1306 into main Mar 25, 2026
8 checks passed
@neumie neumie deleted the neumie/hook-env-vars-and-dtach-fix branch March 25, 2026 18:33
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