Skip to content

RicardoRobledo/Claude-Code-in-Action-course

Repository files navigation

Claude Code in Action — Course Notes

Personal notes from a Claude Code in Action course. Covers core features, MCPs, GitHub integration, Hooks, and the SDK.


Table of Contents


Quick Commands

Command Description
/init Deep search in project / initialize Claude in a repo
/compact Summarize the current conversation to save context
/clear Clear the entire conversation
/hooks Open the hooks configuration UI
/install-github-app Set up the official GitHub Actions integration

Claude Files

Claude reads context from these files automatically:

CLAUDE.md              # Project-level instructions (committed)
CLAUDE.local.md        # Local project instructions (not committed)
~/.claude/CLAUDE.md    # Global instructions for all projects

Writing to CLAUDE.md

Start a message with # and Claude will help you rewrite it as a reminder in CLAUDE.md:

# Only comment complex code.

Shortcuts

Shortcut Action
@filename Include a file in the conversation context
ESC Interrupt Claude to add more context or change direction
ESC ESC Remove irrelevant context — shows previous messages so you can go back

Example — Writing Tests with @

Write tests for the authentication logic in @src/lib/auth.ts

Custom Commands

Create reusable slash commands by adding markdown files inside a commands/ folder.

File: commands/audit.md

Your goal is to update any vulnerable dependencies.

Steps:
1. Run `npm audit` to find vulnerable packages
2. Run `npm audit fix` to apply updates
3. Run the tests to verify nothing broke

Usage:

/audit

Passing Arguments

Use $ARGUMENTS in your command file to accept dynamic input:

Audit only the module at: $ARGUMENTS
/audit src/lib/payments.ts

MCP Servers

MCP (Model Context Protocol) servers extend Claude Code with new tools and capabilities — browser control, databases, external APIs, and more.

Adding an MCP Server

Run this outside of Claude Code (in your terminal):

claude mcp add playwright npx @playwright/mcp@latest

Pre-approving Permissions

Avoid repeated permission prompts by editing .claude/settings.local.json:

{
  "permissions": {
    "allow": ["mcp__playwright"],
    "deny": []
  }
}

Note: Use double underscores mcp__playwright.

Playwright MCP — Example Use Case

Ask Claude to interact with your running app visually:

Navigate to localhost:3000, generate a test component, analyze the styling,
and update the generation prompt at @src/lib/prompts/generation.tsx
to produce better components going forward.

Claude can see the actual visual output — not just code — which leads to far better design decisions.


GitHub Integration

Claude Code can run inside GitHub Actions as an automated team member.

Setup

/install-github-app

This walks you through installing the Claude Code GitHub App, adding your API key, and auto-generating a PR with the workflow files.

Default Workflows

Mention Action — Mention @claude in any issue or PR:

  • Claude analyzes the request and creates a task plan
  • Executes the task with full codebase access
  • Responds directly in the issue or PR thread

Pull Request Action — Triggers automatically on every PR:

  • Reviews the proposed changes
  • Analyzes the impact
  • Posts a detailed report as a PR comment

Customizing Workflows

After merging the initial setup PR, you can enhance your .github/workflows files:

- name: Project Setup
  run: |
    npm run setup
    npm run dev:daemon
custom_instructions: |
  The server is running at localhost:3000. Logs are in logs.txt.
  Query the DB with the sqlite3 CLI if needed.
  Use mcp__playwright tools to interact with the browser.

mcp_config: |
  {
    "mcpServers": {
      "playwright": {
        "command": "npx",
        "args": ["@playwright/mcp@latest", "--allowed-origins", "localhost:3000"]
      }
    }
  }

⚠️ In GitHub Actions, every tool must be explicitly listed — there are no shortcut permissions like local dev.

allowed_tools: "Bash(npm:*),Bash(sqlite3:*),mcp__playwright__browser_snapshot,mcp__playwright__browser_click"

Hooks

Hooks let you intercept tool calls — before or after they execute — to run your own commands.

Hook Types

Type When it runs Can block?
PreToolUse Before a tool is called ✅ Yes
PostToolUse After a tool is called ❌ No
Notification When Claude needs permission or is idle 60s
Stop When Claude finishes responding
SubagentStop When a subagent (Task) finishes
PreCompact Before a compact operation
UserPromptSubmit When user submits a prompt
SessionStart When a session starts or resumes
SessionEnd When a session ends

Configuration Locations

~/.claude/settings.json          # Global (all projects)
.claude/settings.json            # Project (shared with team)
.claude/settings.local.json      # Project (personal, not committed)

PreToolUse Example

"PreToolUse": [
  {
    "matcher": "Read",
    "hooks": [
      {
        "type": "command",
        "command": "node /home/hooks/read_hook.ts"
      }
    ]
  }
]

PostToolUse Example

"PostToolUse": [
  {
    "matcher": "Write|Edit|MultiEdit",
    "hooks": [
      {
        "type": "command",
        "command": "node /home/hooks/edit_hook.ts"
      }
    ]
  }
]

Exit Codes

Code Meaning
0 Allow the tool call to proceed
2 Block the tool call (PreToolUse only) — stderr is sent back to Claude as feedback

Input Data Structure

Your hook command receives JSON via stdin:

{
  "session_id": "2d6a1e4d-6...",
  "transcript_path": "/Users/...",
  "hook_event_name": "PreToolUse",
  "tool_name": "Read",
  "tool_input": {
    "file_path": "/code/queries/.env"
  }
}

Debug Hook — Log stdin to a file

Useful for understanding what data a hook receives:

"PostToolUse": [
  {
    "matcher": "*",
    "hooks": [{ "type": "command", "command": "jq . > post-log.json" }]
  }
]

Absolute Paths & Portability

The docs recommend absolute paths in hook commands (prevents path interception attacks). To share configs across machines, use a settings.example.json with a $PWD placeholder and an init-claude.js script that replaces it at setup time.

Practical Hook Ideas

TypeScript Type Checking Hook
After every file edit, run tsc --noEmit and feed any errors back to Claude so it fixes them immediately — even across files it didn't touch.

Query Duplication Prevention Hook
When Claude edits files in ./queries/, launch a second Claude Code instance via the SDK to review the changes and flag if similar queries already exist. Claude will then remove the duplicate and reuse existing code.


Claude Code SDK

Run Claude Code programmatically from TypeScript, Python, or the CLI.

Basic Usage

import { query } from "@anthropic-ai/claude-code";

const prompt = "Look for duplicate queries in the ./src/queries dir";

for await (const message of query({ prompt })) {
  console.log(JSON.stringify(message, null, 2));
}

Enabling Write Permissions

By default the SDK is read-only. To allow edits:

for await (const message of query({
  prompt,
  options: {
    allowedTools: ["Edit"]
  }
})) {
  console.log(JSON.stringify(message, null, 2));
}

Or configure permissions in .claude/settings.json for project-wide access.

Use Cases

  • Git hooks — Auto-review code before commits
  • Build scripts — Analyze and optimize during builds
  • CI/CD pipelines — Code quality checks on every push
  • Custom CLI tools — Wrap Claude in your own commands
  • Automated docs — Generate documentation from source

Notes taken during a Claude Code course. For official docs visit https://docs.claude.com.

About

Notes of Claude Code in Action course

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors