Skip to content

Sabbir Mohammad Sami web developer

ResumeDownload Resume

All notes

(AI)5 min read

Claude Code Hooks: Auto-Format, Guard Files and Run Checks, Step by Step

Hooks are shell commands Claude Code runs at fixed moments: before a tool runs, after a file is edited, when you send a prompt, when a session starts. Unlike an instruction in a prompt, a hook always runs. This guide sets up two you will keep — Prettier on every edited file, and a guard that blocks edits to .env files.

Cover: “HOOKS” in heavy capitals beside a panel showing the event order — PreToolUse, Edit, PostToolUse, StopCover: “HOOKS” in heavy capitals beside a panel showing the event order — PreToolUse, Edit, PostToolUse, Stop

( Before you start )

Why hooks instead of instructions

You can write “always run Prettier” in CLAUDE.md, and Claude will usually do it. A hook makes it certain: Claude Code runs the command itself, every time, whatever the model decides. Use instructions for judgement and hooks for rules.

If you have set up Husky and lint-staged, the idea is the same. Only the trigger changes: an AI tool call instead of a Git commit.

Where hooks live

FileApplies toCommit it?
~/.claude/settings.jsonAll your projectsNo
.claude/settings.jsonThis project, for everyoneYes
.claude/settings.local.jsonThis project, only youNo

Plugins can ship hooks in hooks/hooks.json, and skills can declare their own in their frontmatter.

How a hook is shaped

JSON
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [{ "type": "command", "command": "..." }]
      }
    ]
  }
}
  • Event — when it runs: PreToolUse before a tool call, PostToolUse after one succeeds, UserPromptSubmit when you send a prompt, Stop when Claude finishes replying, SessionStart when a session begins.
  • matcher — which tools it applies to, by name: Bash, Edit|Write, or a pattern such as mcp__github__.*. Leave it out to match every tool.
  • command — the shell command to run. It receives a JSON description of the event on standard input, and times out after ten minutes by default.

What the hook receives

Every hook gets JSON on standard input. For the file tools, the field you usually want is tool_input.file_path — always an absolute path. A trimmed example:

JSON
{
  "session_id": "abc123",
  "cwd": "/Users/you/project",
  "hook_event_name": "PostToolUse",
  "tool_name": "Edit",
  "tool_input": {
    "file_path": "/Users/you/project/app/page.tsx"
  }
}

The examples below read it with jq. Install it first if you need to: brew install jq on macOS, sudo apt install jq on Ubuntu.

( Step by step )

Format every file Claude edits

Add this to .claude/settings.json in your project:

JSON
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": "jq -r '.tool_input.file_path' | xargs npx prettier --write --ignore-unknown"
          }
        ]
      }
    ]
  }
}

After every write or edit, the hook pipes the file’s path into Prettier. --ignore-unknown skips files Prettier has no parser for, so editing a .env or an image never fails the hook. Paths that contain spaces need more care than xargs gives them.

Block edits to .env files

Add a PreToolUse entry next to it, in the same hooks object:

JSON
"PreToolUse": [
  {
    "matcher": "Write|Edit",
    "hooks": [
      {
        "type": "command",
        "command": "f=$(jq -r '.tool_input.file_path'); case \"$f\" in *.env|*.env.*) echo 'Blocked: .env files are protected' >&2; exit 2;; esac"
      }
    ]
  }
]

Exit code 2 is what blocks. Claude Code cancels the edit and hands your message on standard error back to Claude, which explains it to you and carries on. The pattern catches .env and .env.local and leaves a file such as config.envrc alone.

Exit codes in one table

Exit codeMeaningWhat happens
0SuccessCarry on. A single JSON object printed to standard output can return a decision.
2BlockIn PreToolUse the tool call is cancelled and standard error is the reason Claude sees. In PostToolUse the tool has already run, so standard error is passed to Claude.
Anything elseNon-blocking errorReported as an error; the action continues.

Test it

Test a hook by hand before trusting it. Feed the command a fake payload and check the exit code:

Bash
echo '{"tool_input":{"file_path":"/repo/.env"}}' \
  | sh -c 'f=$(jq -r ".tool_input.file_path"); case "$f" in *.env|*.env.*) echo "Blocked" >&2; exit 2;; esac'
echo $?   # prints 2
  1. Save the settings and start a new Claude Code session in the project.
  2. Ask Claude to add a variable to .env — the edit should be refused with your message.
  3. Ask it to change a component — the file should come back formatted.

( Going further )

More hooks worth having

  • Run eslint --fix on edited TypeScript files, after Prettier.
  • Block git push --force with a PreToolUse hook on Bash that checks tool_input.command.
  • Send a desktop notification when Claude finishes, from a Stop hook.
  • Print the current branch and open issues at SessionStart, so every session starts with context.

Hooks FAQ

Do hooks slow Claude Code down?
A hook runs as part of the event it is attached to, so keep it fast: format the one file that changed, not the whole project.
Can a hook stop Claude from running a shell command?
Yes. Use a PreToolUse hook with a Bash matcher, read tool_input.command, and exit with code 2 to block it.
Are hooks safe to share?
They run with your user permissions, so read every hook before you commit or install it — the same rule as for any script.
Hook or CLAUDE.md rule?
If it must happen every time, a hook. If it needs judgement, a rule in CLAUDE.md.

Reference: Claude Code docs — Hooks guide and Hooks reference.

Topic
AI
Published
Reading
5 min · 790 words
Sections
10
Tags
  • Claude Code
  • Hooks
  • Automation
  • Prettier
  • Developer tools

Experience

( 03 roles — 2+ years )

Full-stack developer in Dhaka, Bangladesh. Building for clients in Germany and Bangladesh since 2022.

  1. (01)

    August 2025 — Present

    Full-Stack Developer

    Susko GmbH · Full Time · Remote

    • Developed and enhanced an AI-powered SaaS and social media automation platform — AI content, image and video generation, automated scheduling and publishing, multi-account and content-team management, Meta, Instagram and Google integrations, WhatsApp-based content generation and scheduling, admin controls and subscription management.
    • Built a full-stack Padel court management and automation system that connects physical court hardware to a real-time web dashboard — court and player management, game control and live scores over WebSocket — and worked on the sensor electronics, PCB design, footprint verification, Gerber validation and JLCPCB manufacturing.
    • Built and maintained automation workflows with n8n, webhooks, APIs and external service integrations that take manual steps out of business processes.
    • Delivered 40+ production websites and full-stack applications for German clients across industries in React, Next.js and TypeScript — shop management, review management and automation, fundraising platforms, menu management, QR code generation and other custom business tools.
    • Optimized backend performance across production applications — database queries, API paths, data processing and Redis-based workflows — for faster, more responsive apps.

    Next.js · React · TypeScript · Node.js · Python · Prisma · Redis · WebSocket · n8n · OpenAI

  2. (02)

    March 2024 — May 2025

    Software Developer

    Bangladesh Associate of IT Solutions · Full Time · On-site

    • Developed a full-stack inventory management system tracking products, sales, payments, returns, waste products, customer ledgers and SMS notifications, in React, TypeScript, Express and MySQL.
    • Scaled an accounting management platform from a single-client application into a multi-user system, with financial dashboards, journal entries, transaction management, reporting and data visualization.
    • Deployed and maintained web applications on cPanel and VPS servers — production deployments, domain configuration, server setup and troubleshooting.
    • Delivered websites for schools, madrasas and other organizations, turning client requirements into responsive, production-ready web applications.
    • Developed and redesigned production and company portfolio websites in React, Next.js and TypeScript, with a focus on responsive design and user experience.

    React · Next.js · TypeScript · Express · MySQL · Tailwind CSS · cPanel · VPS

  3. (03)

    November 2023 — April 2024

    Full-Stack Developer

    Diginie IT · Internship · Remote

    • Completed a remote internship as a full-stack developer, building and maintaining client web applications in Next.js, TypeScript and Tailwind CSS.
    • Turned designs into responsive pages that held together on every screen size, and kept existing client sites running.

    Next.js · TypeScript · Tailwind CSS · GitHub

About

( Dhaka, Bangladesh )

Sabbir Mohammad Sami — full-stack web & app developer at Susko GmbH, building for the web since 2022.

Sabbir Mohammad Sami, smiling and looking off to the side, seated on a white block in a black sweater — black-and-white studio portrait

I’m a full-stack developer from Dhaka who cares about the part people actually touch — unusual layouts, careful CSS, motion that means something — and about the code underneath being just as clean.

( Story )

I grew up in Dhaka and studied arts and humanities at Kabi Nazrul Government College. Alongside my studies I joined a web development course, and that is where the real growth started — surprise. Alongside work, I am now in my third year of Honours in Economics at National University.

My first website was a tourism site about the place I most wanted to visit. I built it in class 10.

Today I build AI products, automation and client platforms at Susko GmbH, after two years of shipping inventory, accounting and client sites at BAITS. What I am after has not changed: interfaces that look good and back-ends that run smoothly, from the same pair of hands.

Honest, down to earth, and fond of hard work. My inbox is always open — for a project, or just to say hi.

  1. ( Education )

    1. Kabi Nazrul Government College

      • Arts and humanities
      • Dhaka, Bangladesh
    2. National University, Bangladesh

      Session 2023–2024 · Now

      • Honours in Economics — 3rd year
      • Department of Economics
  2. ( Co-curricular )

    —

    Bangladesh National Cadet Corps (BNCC)

    • 1 No Battalion, Ramna Regiment
    • Rank: Cadet Corporal
  3. ( Languages )

    Bangla, English, Hindi

    • Bangla — native
    • English — comfortable
    • Hindi — fluent

( Skills )

Expertise
React · Next.js · JavaScript · TypeScript · MongoDB · Bootstrap · Tailwind CSS · shadcn/ui · GitHub · Figma
Comfortable
Flutter · Dart · MySQL · Mongoose · Express · TanStack Query · Firebase · React Router · Photoshop
Familiar
Zod · Framer Motion · GSAP · JWT · Axios · CORS · Stripe · Vercel

( Questions )

Who is Sabbir Mohammad Sami?

Sabbir Mohammad Sami (S M Sami) is a full-stack web and app developer from Dhaka, Bangladesh. Since August 2025 Sami has worked as a Full-Stack Developer at Susko GmbH in Germany, after building inventory and accounting platforms at Bangladesh Associate of IT Solutions (BAITS). Sami has been building for the web since 2022.

What does Sabbir Mohammad Sami build?

Sami builds websites, web apps, mobile apps and AI products end to end: company and restaurant websites, booking and management platforms, an AI social media platform (Kocial), an AI review manager (ReviewSync) and a Flutter money app (Sompi). That includes 40+ production websites for clients in Germany and Bangladesh.

Which technologies does Sami work with?

Sami works across the MERN stack — MongoDB, Express, React and Node.js — and with Next.js, TypeScript, Tailwind CSS, MySQL, PostgreSQL, Prisma and Redis. Mobile apps are built in Flutter and Dart. AI features use the OpenAI API, n8n automations and webhooks, and motion uses GSAP.

Does Sami build mobile apps with Flutter?

Yes. Sami builds cross-platform apps in Flutter and Dart. Sompi, Sami’s own money tracker, runs on Android, iOS, the web and the desktop from one Flutter codebase, with Riverpod for state and an encrypted SQLite store, so every account and transaction stays on the device.

Does Sami build AI products?

Yes. At Susko GmbH Sami builds AI SaaS: Kocial writes captions, generates images and publishes to Facebook and Instagram for agencies, and ReviewSync answers Google reviews in a business’s own voice. Sami also builds n8n workflows that connect AI models to business tools.

How can I hire Sami as a web or app developer in Dhaka?

Email smsami.dev@gmail.com or use the contact form on this site with a short note about the project. Sami works with clients in Dhaka, across Bangladesh and abroad — remotely for companies in Germany — and replies in English or Bangla.

( Contact )

Contact

( Available for projects )

Based in Dhaka, Bangladesh (GMT+6). Happy to talk in English, Bangla or Hindi.

Let’s work together.

Have an exciting project you need help with? Send me an email, give me a call, or write below — a project, a question, or just to say hi.

( Write to me )

* Required