CLAUDE LABJP
2.1.278 — The auto mode classifier now runs server-side by default on the Claude API, Enterprise, Bedrock, Vertex and Foundry. You are not billed for the classifier, and /status gained an Auto mode server lineTASKOUT — The TaskOutput tool is gone. taskOutputMaxChars and TASK_MAX_OUTPUT_LENGTH no longer do anything, and background output is read with Read instead10/07 — The old management-configuration key spellings are accepted until noon PT on October 7, seventeen days from now. After that, entries that still use them stop working until you rewrite themBUNPANIC — Reports are coming in of the newest build crashing on launch alone. Earlier builds still run on the same machine, which points at the release rather than the environmentNEW — Deciding what belongs in Cowork and what belongs in Claude Code, using the approval boundary as the lineSONNET4.5 — A date in a deprecation table is a floor, not an end date. Sonnet 4.5 is still active and no deprecation notice has been posted2.1.278 — The auto mode classifier now runs server-side by default on the Claude API, Enterprise, Bedrock, Vertex and Foundry. You are not billed for the classifier, and /status gained an Auto mode server lineTASKOUT — The TaskOutput tool is gone. taskOutputMaxChars and TASK_MAX_OUTPUT_LENGTH no longer do anything, and background output is read with Read instead10/07 — The old management-configuration key spellings are accepted until noon PT on October 7, seventeen days from now. After that, entries that still use them stop working until you rewrite themBUNPANIC — Reports are coming in of the newest build crashing on launch alone. Earlier builds still run on the same machine, which points at the release rather than the environmentNEW — Deciding what belongs in Cowork and what belongs in Claude Code, using the approval boundary as the lineSONNET4.5 — A date in a deprecation table is a floor, not an end date. Sonnet 4.5 is still active and no deprecation notice has been posted
Articles/Claude Code
Claude Code/2026-06-18Advanced

Moving Cleanup and Logging into a SessionEnd Hook

How to use Claude Code's new post-session hook to automate temp-file cleanup and log writing after a session ends, with real examples from a pipeline that processes several repositories in sequence.

Claude Code255hooks19SessionEndautomation110CI/CD19

Premium Article

A few times a month, my nightly publishing job would finish without removing the .next build artifact or appending its log entry — even though generation and the push itself ran fine every time. Only the final cleanup went missing. The cause was always the same: I had written cleanup as "the tail end of the main work," so whenever the run took a different branch, it never reached the last steps.

The June 18, 2026 update added a post-session hook (SessionEnd) to Claude Code — a hook that always runs after a session ends. It turned out to be exactly the structural guarantee I needed for the work I kept losing because it lived at the bottom of the main flow. As an indie developer running several sites in sequence, here is what I actually moved into it and where I tripped.

Why cleanup at the tail of the flow gets dropped

The body of a session branches on errors, early returns, and conditionals. Cleanup placed at the very end only runs when you take the happy path. What I wanted was the same protection a shell trap or a language-level finally gives you, but applied to a Claude Code session — and that is precisely the niche SessionEnd fills.

In my case, three things kept getting dropped: removing the temporary build output (.next), appending that day's update log, and checking free disk space for next time. None of them affect article quality, but left alone they fill the disk until the next session cannot even start.

The basic shape of a SessionEnd hook

You register hooks under hooks in settings.json, keyed by event name. SessionEnd fires right before the session closes.

{
  "hooks": {
    "SessionEnd": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/on-session-end.sh"
          }
        ]
      }
    ]
  }
}

One thing worth remembering: a SessionEnd hook's exit code and stdout do not change the outcome of a session that is already wrapping up. Unlike a Stop hook, it is not meant to block and resume work — it is for the "one reliable chore after the fact." I confused it with a Stop hook at first and tried to call further work back from inside the cleanup script, which failed. Treat SessionEnd as a point of no return and the design becomes clear.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
A working SessionEnd hook config and why its exit code does not change the session outcome
Concrete scripts for moving temp-file removal and log appends into the hook
A real failure from putting teardown in the hook, and how to avoid it
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $15 for lifetime access
View Membership →

Related Articles

Claude Code2026-09-02
Two hooks that record every model switch and stop the ones you never agreed to
Build a PostModelSwitch hook that logs every model change and a PreModelSwitch hook that blocks unapproved switches during unattended runs. Complete scripts, measured timings, and the reason the two jobs must stay separate.
Claude Code2026-08-28
Don't let your verification script's full output flow back through a hook
The check was working the whole time. The conversation was what ran out of room. Measured side by side: 58 bytes from one scan of 833 files, 42KB from another. Which paths actually reach the model, and how to enforce a budget on them.
Claude Code2026-07-10
Carrying Decisions Across Compaction with PreCompact and SessionEnd Hooks
Auto-compaction does not delete your conversation. It deletes the reasons behind it. Here is a working PreCompact / SessionEnd / SessionStart hook pipeline that rescues decisions to disk and hands them to the next session, with real code and measurements.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links