Agents & Workflows — Delegate at Scale
An agent is Claude working autonomously toward a goal — reading files, making decisions, writing code, and calling tools — without you watching every step. This module teaches you how to launch agents, wire up hooks, schedule recurring tasks, and coordinate multiple agents working in parallel.
🤖 What Are Agents — and How Are They Different?
In every module so far, you've been in a back-and-forth conversation with Claude: you prompt, it responds, you prompt again. An agent breaks that pattern. You give it a goal, it works autonomously until the goal is done.
- You prompt → Claude responds → repeat
- You're present and directing each step
- Good for creative, exploratory work
- Ends when you close the session
- You give a goal → Claude executes it fully
- Reads files, makes decisions, takes actions
- Good for defined, repeatable tasks
- Can run in background or on a schedule
The key insight: agents are best for tasks you could write down as a checklist. If you can describe the steps clearly, an agent can execute them — faster, and while you do something else.
⚡ Three Agent Types
Claude Code has three distinct ways to run agentic tasks. Each one fits a different situation.
Interactive Agent
You're present, but Claude drives the multi-step work. You give a complex goal and watch it execute — stepping in only if it needs guidance. This is what you've been doing since Module 01.
Background Agent
Runs in the background while you do other things. You launch it, it works, you get a notification when it's done. Uses claude --print or non-interactive mode.
Scheduled Agent
Runs automatically on a schedule — daily, weekly, or at a specific time. You set it up once; it runs forever. Powered by cron or the /schedule skill.
🌙 Background Agents — Work While You Work
A background agent is Claude running in non-interactive mode. You fire it off in a terminal, switch to something else, and it completes the task on its own. The --print flag is the key — it tells Claude to run once, print the result, and exit.
Launching a background agent
# --print runs Claude non-interactively, outputs result, then exits claude --print "Review all .js files in src/ for unused variables and write a report to review.md" # Run it in the background (& sends it to the background) claude --print "Audit package.json for outdated dependencies and create a report" & # Pipe output to a file claude --print "Generate a weekly summary of changes in this repo" > weekly-summary.md # Run with a specific model for cost control claude --print --model claude-haiku-4-5 "Format all markdown files in docs/"
Passing context to a background agent
Background agents read your CLAUDE.md automatically, just like interactive sessions. For extra context, use -p to pass a full prompt from a file:
# Write a detailed task file cat > agent-task.md << 'EOF' Review the pull request diff below and write a code review. Focus on: security issues, performance problems, missing tests. Format: numbered list, one issue per line. EOF # Run the agent with the task file as input claude --print --input-file agent-task.md > code-review.md
🪝 Hooks — Automate Reactions to Events
Hooks are shell commands that Claude Code runs automatically when specific events happen — before a tool call, after a tool call, when a session stops, or before context is compressed. They're how you wire Claude into your existing dev workflow.
Think of hooks as triggers: when X happens inside Claude Code, automatically run Y.
Available hook events
| Hook | When it fires | Common use |
|---|---|---|
| PreToolUse | Before Claude calls any tool (read, edit, bash) | Log what Claude is about to do; require approval |
| PostToolUse | After each tool call completes | Auto-format files; run linter after an edit |
| Stop | When a session ends or Claude finishes a task | Send a notification; run tests; commit changes |
| PreCompact | Before /compact runs | Save a snapshot of current session state |
Configuring hooks in settings.json
Hooks live in your Claude Code settings file. Open it with /config in a session, or edit it directly:
{ "hooks": { // Run prettier after every file edit "PostToolUse": [ { "matcher": "Edit", "hooks": [ { "type": "command", "command": "prettier --write $CLAUDE_TOOL_INPUT_PATH" } ] } ], // Send a desktop notification when Claude finishes "Stop": [ { "hooks": [ { "type": "command", "command": "osascript -e 'display notification \"Claude finished\" with title \"Claude Code\"'" } ] } ] } }
Practical hooks you can use today
# Auto-run tests after every file edit "command": "npm test --silent" # Auto-lint Python files after edits "command": "ruff check $CLAUDE_TOOL_INPUT_PATH --fix" # Git commit automatically when Claude stops "command": "git add -A && git commit -m 'claude: auto-commit'" # Mac notification when Claude finishes "command": "osascript -e 'display notification \"Done\" with title \"Claude Code\"'" # Windows notification "command": "powershell -command \"[System.Windows.Forms.MessageBox]::Show('Claude finished')\"" # Linux notification "command": "notify-send 'Claude Code' 'Task complete'"
📅 Scheduled Agents — Set It and Forget It
Scheduled agents run automatically at a time you define — once or on a recurring cron schedule. You configure them once and they run without you being present.
Using the /schedule skill
The fastest way to create a scheduled agent is via the /schedule skill inside a Claude session:
# Schedule a one-time task Use the schedule skill to run this task tomorrow at 9am: "Read all open Linear issues, write a prioritized daily plan to daily-plan.md, and create a Notion page from it." # Schedule a recurring weekly task Use the schedule skill to run every Monday at 8am: "Read last week's commits with git log, summarize what changed, and create a weekly-update.md in the project root." # Schedule a daily standup prep Use the schedule skill to run every weekday at 8:30am: "Read my Linear issues and Notion meeting notes from yesterday, then write a standup summary to standup.md."
Using cron directly (advanced)
For more control, schedule Claude directly in your system's cron job manager. This runs even when the Claude desktop app is closed:
# Open your crontab file crontab -e # Add a line in this format: minute hour day month weekday command # Run every Monday at 9:00 AM 0 9 * * 1 cd ~/my-project && claude --print "Generate weekly summary" >> weekly.log 2>&1 # Run every day at 8:30 AM (weekdays only) 30 8 * * 1-5 cd ~/my-project && claude --print "Write standup summary to standup.md"
REM Open Task Scheduler → Create Basic Task
REM Set trigger: Daily at 9:00 AM
REM Set action: Start a program
REM Program: cmd.exe
REM Arguments:
/c "cd %USERPROFILE%\my-project && claude --print "Generate weekly summary" >> weekly.log"
🔀 Multi-Agent Patterns
For complex tasks, one agent isn't always enough. Multi-agent systems use an orchestrator — a top-level agent that breaks the work into parts and delegates each part to a specialized subagent.
🧠 "Audit the entire codebase and write a security report"
Orchestrator prompt pattern
You are an orchestrator. Break this task into 3 parallel subtasks
and execute each one completely before combining the results.
Task: Audit this codebase for quality issues.
Subtask 1: Scan all .js files for unused variables and imports.
Subtask 2: Check all API endpoints for missing input validation.
Subtask 3: Review package.json for outdated or vulnerable dependencies.
When all three are done, write a combined report to audit-report.md
with a section for each subtask and a priority-ranked action list.
Parallel vs. sequential agents
- Independent tasks with no dependencies
- Faster total completion time
- Example: lint JS + lint CSS + lint Python
- Each step depends on the previous output
- Research → write → review → publish
- Example: generate code → run tests → fix failures
💡 Power Patterns — Real Workflows to Steal
Pattern 1 — Auto-PR on commit
Wire a Stop hook so every time Claude finishes a coding session, it auto-commits the changes and opens a GitHub PR with a description Claude wrote.
# In settings.json Stop hook: "command": "git add -A && git commit -m \"$(claude --print 'Write a one-line commit message for these staged changes')\" && gh pr create --fill"
Pattern 2 — Nightly code review
Schedule a nightly agent to review the day's commits and post a summary to Slack or save it to Notion.
0 23 * * 1-5 cd ~/my-project && claude --print "Review today's git commits with git log --since=today, identify any risky changes, and write a nightly-review.md"
Pattern 3 — Self-healing tests
Run tests after every edit (PostToolUse hook). If tests fail, Claude automatically reads the failure output and fixes the code.
After every file edit, run npm test. If tests fail, read the
failure output and fix the code. Keep iterating until all
tests pass. Don't ask me for confirmation between iterations.
Pattern 4 — Weekly report agent
Read: git log for this week's commits, open Linear issues,
and any Notion pages updated this week.
Write a weekly-report.md with:
- What shipped (from git log)
- What's in progress (from Linear)
- Blockers (from Linear high-priority issues)
- Next week's focus (top 3 Linear priorities)
Keep it under 300 words. Executive summary tone.
🎯 Challenge — Wire One Hook and Launch One Background Agent
Two tasks. Both should work on your real project from Module 02.
-
1
Add a Stop hook that sends a desktop notification when Claude finishes. Open
/config, find the hooks section, and add the notification command for your OS. Test it by running a short Claude task — you should get a notification when it ends. -
2
Launch a background agent with
claude --print. Task: "Read all files in this project and write a summary of the codebase to README.md — what each file does in one sentence." While it runs, open a second terminal tab and work on something else. Check README.md when it finishes. -
3
Schedule a recurring task. Use the
/scheduleskill (or cron) to run a task every weekday morning: "Read the git log from yesterday and write 3 bullet points summarizing what changed to daily-log.md." - 4 Try a self-healing loop. In an interactive session, ask Claude: "Intentionally introduce a syntax error into one of my JS files, then run npm test. Read the failure, fix the error, and run tests again until they pass."
🏗 Mini Project — Auto-PR Agent with Notification Hook
You're going to build a real automation: a background agent that reviews your code, writes a commit message, opens a GitHub PR, and notifies you when it's done — all without you watching. Pick your OS.
Navigate to your web app project from Module 02 (or any folder with files). Initialize git if it's not already:
cd ~/my-web-app
# Initialize git (skip if already done)
git init
git add .
git commit -m "initial commit"
# Install GitHub CLI if you don't have it
brew install gh
gh auth login
Open a Claude session in your project, then type /config. This opens your settings.json. Add the Stop hook for your OS:
"Stop": [
{
"hooks": [
{ "type": "command", "command": "osascript -e 'display notification \"Task complete\" with title \"Claude Code\"'" }
]
}
]
Save the file. Test it: run any short Claude task and you should get a notification when it ends.
Open a Claude session in your project and ask it to make a small improvement:
fade-in animation to the hero section in styles.css and
trigger it in app.js when the page loads. Keep it subtle.
When Claude finishes, you'll have uncommitted changes in styles.css and app.js. You can verify this with:
You should see both files listed as modified. These are the changes the background agent will review and commit in the next step.
Open a new terminal window (keep your Claude session open in the original one). In the new window, navigate to your project and run:
claude --print "Review the uncommitted changes with git diff.
Write a clear commit message describing what changed.
Then run: git add -A && git commit with that message.
Finally run: gh pr create --title 'feat: add hero fade animation' --body 'Adds smooth fade-in to hero section on page load'" &
# The & runs it in the background — your terminal is immediately free
Switch to another app and do something else. The agent is working in the background. When it finishes, your Stop hook fires and you get a notification.
When you get the notification, check the results:
git log --oneline -3
# List open PRs to confirm it was created
gh pr list
# View the PR in your browser
gh pr view --web
You should see: a commit with a descriptive message Claude wrote, and an open PR on GitHub. Go look at the PR — Claude wrote the title and description from reading the actual diff.
Open a Claude session in your project and run:
that documents the auto-PR background agent we just built.
Include the exact --print command and the Stop hook config.
Also add a note that a desktop notification fires when done.
Claude updates your CLAUDE.md. Next time you want to run this workflow: open Claude, check the Agents section, copy the command, run it. The whole auto-PR process takes 30 seconds to kick off from now on.