Skip to content

Back to the catalog

media.licdn.comcourse

Claude Code Complete Guide: Hooks, Agents, MCP Tools & Professional Development

A LinkedIn-hosted PDF guide to Claude Code hooks, subagents, MCP tools and custom slash commands. It covers the hook configuration in .claude/settings.json, the event payloads (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart), and exit code 2 as the way to block an action. It includes worked examples of safety hooks: a regex-based PreToolUse script that blocks rm -rf, curl piped to a shell, chmod 777 and privileged Docker containers. Other examples are audit logging, TDD enforcement and session context loading. Useful as a practical reference for putting deterministic guardrails around an AI coding agent, though the regex blocklists are easy to bypass.

TL;DR Claude Code hooks/agents/MCP guide with PreToolUse guardrail examples that block dangerous shell commands and add audit logging.
Also seen from another angle🧠 AI →
Document

What it is

A LinkedIn-hosted PDF, "Claude Code Complete Guide: Hooks, Agents, MCP Tools & Professional Development". The fetched text covers sections 1-8 and cuts off mid-table in the cheat sheet. The Security Considerations, MCP, sub-agent and slash-command chapters listed in the table of contents are not in the fetched text. Everything below comes from the visible part.

What to do

Configuration facts a reader would otherwise have to look up:

  • Project hooks live in .claude/settings.json. User-global hooks live in ~/.claude/settings.json.
  • Settings load at startup, so restart Claude Code after editing.
  • The guide recommends absolute script paths when a hook doesn't fire, and chmod +x .claude/hooks/*.py.
  • matcher takes regexes, for example Edit|MultiEdit|Write. An empty string matches all tools.
  • A hook command accepts "timeout": 5. Appending & runs non-critical hooks in the background.
  • Hooks run synchronously.
  • To see real payloads before writing logic, log them with this PreToolUse command:
jq '.' >> .claude/hooks/log.jsonl

The cheat sheet's blocking table:

EventCan block?
PreToolUseYes (exit 2)
SubagentStopYes (exit 2)
UserPromptSubmit, SessionStart, PostToolUse, Notification, Stop, PreCompactNo

Caveats

The guide undercuts its own safety examples in ways the summary doesn't mention. The first three points below are my reading of the code shown, not claims the page makes.

  • curl | bash slips through. The advanced blocklist pattern curl.*\|\s*sh needs sh right after the pipe. curl … | bash doesn't match. curl … | sudo sh also doesn't match, because sudo sits between the pipe and sh.
  • The rm patterns are inconsistent. The standalone script only catches combined flags like -rf or -fr, so rm -r -f and --recursive pass. The "advanced" pattern rm\s+-[^\s]*[rf] is too broad: it also blocks a plain rm -f file.
  • The error-handling advice fails open. The "Hook Blocking Unintentionally" section tells you to wrap hook logic in try/except and sys.exit(0) on any error. For a guardrail, that means a parser crash or malformed payload silently allows the command. Fail-open suits notifications, not blockers.
  • The cheat sheet disagrees with itself on blocking. It marks SubagentStop as blockable but Stop as not, and the page doesn't explain why. Check the current Claude Code docs before relying on either.
  • $CLAUDE_FILE_PATHS is unverified. The multi-tool formatter example reads this variable, but the page never shows it being set. The payload fields it documents are tool_name and tool_input. Verify the variable exists before depending on it.

Technologies named here

Techniques named here

  • Protecting sensitive files via hooks
  • Flagging risky commands