Skip to content

Add SessionEnd hook for terminal cleanup as defense-in-depth #677

@Trecek

Description

@Trecek

Summary

Add a Claude Code SessionEnd hook that emits terminal reset escape sequences when a session ends. This provides defense-in-depth alongside terminal_guard() — the hook fires from inside Claude Code's exit path, covering cases where terminal_guard() might not execute (SIGTERM, etc.).

Proposed Configuration

Add to ~/.claude/settings.json (user-level, applies to all Claude Code sessions):

{
  "hooks": {
    "SessionEnd": [
      {
        "type": "command",
        "command": "printf '\\e[?2004l\\e[?1l\\e[?25h\\e[=0u\\e[<99u\\e[?1000l\\e[?1003l\\e[?1006l\\e[J'"
      }
    ]
  }
}

Why Human Review

This is a user-level configuration change, not a code change:

  • Goes in ~/.claude/settings.json, not in the project codebase
  • Affects ALL Claude Code sessions (not just autoskillit cook/order)
  • Needs human decision on whether this should be:
    • Documented as a recommended setup step
    • Added to the autoskillit install flow
    • Added to the autoskillit doctor checks
    • Left as optional guidance in docs

Relationship to #676

Issue #676 implements the code-level fix in terminal_guard(). This issue adds a complementary layer that fires from inside Claude Code itself. The two are independent — each covers gaps the other can't reach. The escape sequences are idempotent, so double-emission is harmless.

Investigation Report

.autoskillit/temp/investigate/investigation_terminal-state-corruption-after-cook-exit_2026-04-08_183000.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs Human ReviewRequires human review before implementationenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions