CLAUDE LABJP
DESIGN — Claude Design gets a major update: design-system imports, direct canvas editing, and more export formatsCODE — Claude Design can start from your local codebase and hand a design off to Claude Code to implementFABLE — Fable 5, a Mythos-class model made safe for general use, is now available in Claude Code v2.1.170FIX — Mid-stream connection drops now preserve partial responses instead of showing a raw errorSCROLL — A new wheelScrollAccelerationEnabled setting disables mouse-wheel scroll acceleration in fullscreenTIER — The Claude Design beta is available to Pro, Max, Team, and Enterprise customersDESIGN — Claude Design gets a major update: design-system imports, direct canvas editing, and more export formatsCODE — Claude Design can start from your local codebase and hand a design off to Claude Code to implementFABLE — Fable 5, a Mythos-class model made safe for general use, is now available in Claude Code v2.1.170FIX — Mid-stream connection drops now preserve partial responses instead of showing a raw errorSCROLL — A new wheelScrollAccelerationEnabled setting disables mouse-wheel scroll acceleration in fullscreenTIER — The Claude Design beta is available to Pro, Max, Team, and Enterprise customers
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 Code158hooks12SessionEndautomation69CI/CD16

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 $10 for lifetime access
View Membership →

Related Articles

Claude Code2026-05-04
Build a Pipeline Where Docs Update Automatically Every Time Your Code Changes
Build a CI/CD pipeline that auto-generates README, CHANGELOG, and API docs whenever code changes. Use Claude Haiku 4.5 for cost-efficient classification and Sonnet 4.6 for quality output — cutting API costs by up to 70% while keeping documentation accurate.
Claude Code2026-05-04
Setting Up Claude Code's GitHub PR Trigger for Automated Code Review
A step-by-step guide to configuring Claude Code's GitHub PR trigger, writing effective CLAUDE.md review policies, and what two weeks of real usage taught me about keeping the signal-to-noise ratio high.
Claude Code2026-04-01
Claude Code HTTP Hooks × GitHub Actions Integration Guide — Production Patterns for Automated Code Review, Testing, and Deployment
A deep dive into integrating Claude Code HTTP Hooks with GitHub Actions to build production-grade pipelines for automated code review, quality checks, and deployment — with detailed code examples throughout.
📚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
See all →