PTENES
TRACK 4

🔁 Automation

Subagents, hooks, slash commands, and recurring tasks—put Claude Code on autopilot and multiply your productivity.

4
Modules
24
Topics
~3h
Duration
Inter
Intermediate
Orchestrator Claude Code 🤖 Subagent research 🪝 Hook automatic linting ⏰ Cron daily review Result automated

Learning path map

Detailed content

4.1 ~45 min

🤖 Subagents: Delegating Tasks

Learn to delegate complex tasks to parallel subagents and multiply Claude Code's capacity without increasing wait time.

What it is

A subagent is a Claude Code instance launched by the main agent to perform a specific task in isolation. It receives a well-defined prompt, works independently, and returns a summarized result to the orchestrator.

Why learn

With subagents, you can parallelize work—while one researches docs, another writes tests, and a third reviews the code. What would take hours in sequence happens in minutes.

Key Concepts

  • • Isolation: each subagent has its own context
  • • Summarized return: only the result goes back to the main agent
  • • Task tool: internal launch mechanism

What it is

Not every task deserves a subagent. Delegation makes sense when the task is independent, has a clear scope, and its result can be consumed atomically by the orchestrator.

Why learn

Delegating poorly increases cost without any benefit. Knowing when to delegate is the difference between efficient automation and unnecessary overhead.

Key Concepts

  • • Independent tasks: don't need shared context
  • • Broad searches: explore multiple sources at the same time
  • • Atomic scope: the result fits in a few lines

What it is

Fan-out is a pattern where an orchestrator launches N subagents simultaneously, each solving part of the problem. The results are collected and integrated at the end.

Why learn

Fan-out is the most powerful automation pattern with Claude Code. Research that would take 1 hour in sequence can be completed in minutes when parallelized with 4-8 subagents.

Key Concepts

  • • Orchestrator: primary agent that distributes tasks
  • • Workers: subagents that run in parallel
  • • Aggregation: orchestrator integrates the results

What it is

Claude Code supports different subagent profiles: the Explore type focuses on reading and analysis (no writing); General can run any tool. The choice determines permissions and risk.

Why learn

Using the wrong subagent type can create security risks (a research agent with write permission) or limit functionality (a coding agent without exec permission).

Key Concepts

  • • Explore: read-only — ideal for research and analysis
  • • General: full access to tools
  • • Principle of least privilege: always use the minimum required type

What it is

A subagent's result returns to the orchestrator as compressed text — a summary of what was done, not the full execution log. This preserves the main agent's context.

Why learn

Understanding how the result is returned helps you write better prompts: specifying the expected output format (JSON, markdown, list) ensures the orchestrator can consume the result without rework.

Key Concepts

  • • Atomic return: one message with the consolidated result
  • • Explicit format: instruct the subagent on how to format
  • • Context pressure: long results consume the orchestrator's tokens

What it is

Each subagent uses tokens: the instruction prompt + execution + result. With multiple subagents running in parallel, costs can scale quickly without controls.

Why learn

Poorly planned automation can cost more than equivalent manual work. Calculating ROI before implementing subagents is an essential professional practice.

Key Concepts

  • • Cost per subagent: prompt + execution + output
  • • Prompt caching: reusing context reduces cost by up to 90%
  • • ROI: time saved × value of time vs. API cost
View Full
4.2 ~50 min

🪝 Hooks: automate the harness

Configure event hooks to automate actions before and after each tool—linting, security, and context injection without touching the agent’s code.

What it is

Hooks are external scripts run by the harness at specific points in the agent lifecycle: before a tool (PreToolUse), after one (PostToolUse), when a session starts (SessionStart), or when it stops (Stop).

Why learn

With hooks, you can add behavior without modifying the agent's prompt or code. It's the cleanest way to enforce policies: lint always runs, and prohibited commands are blocked automatically.

Key Concepts

  • • PreToolUse: before running any tool
  • • PostToolUse: after the tool returns a result
  • • SessionStart: when opening a new session
  • • Stop: when the agent ends

What it is

Hooks are configured in the key hooks of the file settings.json (global in ~/.claude/ or local in .claude/). Each hook is an object with an event, a tool matcher, and a shell command.

Why learn

Declarative configuration in settings.json lets you version hooks alongside the project. Entire teams inherit policies automatically without manual onboarding.

Key Concepts

  • • Global: ~/.claude/settings.json — applies to all projects
  • • Local: .claude/settings.json — project-specific
  • • matcher: filters by tool name (glob)

What it is

A PreToolUse hook can return a nonzero exit code to abort the tool before it runs. This lets you create command blacklists — for example, block git push --force.

Why learn

Destructive commands like rm -rf or force-pushing to main can cause irreversible damage. A blocking hook is the last line of defense.

Key Concepts

  • • Exit 1: signals a block to the harness
  • • stderr message: explains the reason to the agent
  • • Regex patterns: detect prohibited commands

What it is

A PostToolUse hook can run linting or formatting automatically whenever the agent saves a file. The lint output is injected back into the context, allowing the agent to fix errors in the next iteration.

Why learn

Without automatic linting, the agent may generate code with formatting errors that only show up in CI. With the hook, every save produces clean code — an instant feedback loop.

Key Concepts

  • • Trigger: PostToolUse on Write/Edit
  • • Output injection: hook stdout enters the context
  • • Examples: eslint, prettier, ruff, black

What it is

The SessionStart hook runs when a new session begins. Its output is injected as an initial message into the context — ideal for loading project metadata, the current branch, environment variables, or relevant memories.

Why learn

Instead of repeating the project status in every new prompt, SessionStart injects it automatically. The agent starts each session with context already in place—fewer tokens spent, more focus on the work.

Key Concepts

  • • git status, branch, latest commit
  • • Pending project tasks
  • • Relevant environment variables

What it is

By default, if a hook fails (timeout, script error), the harness continues execution — a "fail-open" behavior. For critical security hooks, you can configure fail-closed to stop everything.

Why learn

Relying too much on fail-open can leave security gaps. Understanding hooks’ failure model lets you design more robust systems where critical policies are never silently ignored.

Key Concepts

  • • Fail-open: a hook error does not block execution
  • • Timeout: slow hooks are aborted
  • • Principle: audit hooks fail open; security hooks fail closed
View Full
4.3 ~45 min

⌨️ Slash commands and workflows

Create reusable shortcuts and deterministic pipelines that orchestrate multiple agents sequentially or in parallel with a single command.

What it is

Slash commands are text shortcuts that expand into complete prompts. When you type /review in Claude Code, the harness expands this into a preconfigured code review prompt.

Why learn

Instead of repeatedly rewriting the same long prompt, you type 3 characters and get consistent results every time. Entire teams use the same patterns without memorizing complex instructions.

Key Concepts

  • • Expansion: /comando → full prompt
  • • Arguments: /comando arg1 arg2
  • • Scope: global or per project

What it is

Custom commands are defined as files .md inside the folder .claude/commands/. The file name becomes the command. Its contents are the prompt that will be expanded.

Why learn

Each project has unique needs. A React project might have /component, one for data has /migrate. Customizing is part of a professional setup.

Key Concepts

  • • Local: .claude/commands/meu-cmd.md
  • • Global: ~/.claude/commands/meu-cmd.md
  • • Variables: $ARGUMENTS, $FILE, $SELECTION

What it is

A deterministic workflow is a predefined sequence of steps — each step can be an agent, a shell command, or a data transformation. The output of one step feeds into the next, with no random variation.

Why learn

When the process needs to be auditable and reproducible (CI/CD, releases, mandatory reviews), consistency is more valuable than creativity. Workflows ensure that every step always happens.

Key Concepts

  • • Idempotency: running it 2x produces the same result
  • • Rollback: each step must have a defined undo
  • • Logging: record each step for auditing

What it is

Pipeline: chained steps where A's output is B's input. Parallel: multiple agents running at the same time without depending on one another. Many workflows combine both patterns.

Why learn

Choosing the wrong pattern can double execution time (when you should parallelize) or produce inconsistent results (when you should serialize). Workflow design matters as much as content.

Key Concepts

  • • Pipeline: data dependency between steps
  • • Parallel: complete independence between workers
  • • Barrier: synchronization point after parallel execution

What it is

Workflows are better suited when a task is repeated often, involves multiple agents, or needs to be auditable. One-off, creative tasks are better handled with free-form prompts.

Why learn

Over-engineering workflows for simple tasks is wasteful. Under-engineering for critical tasks is risky. Knowing the right balance is the most valuable skill in automation.

Key Concepts

  • • Frequency: daily tasks are worth the investment
  • • Risk: destructive tasks need a controlled workflow
  • • Team: shared standards need a workflow

What it is

A meta-agent (or higher-level orchestrator) can invoke entire workflows as subtasks. This creates a hierarchy: orchestrator → workflow → subagents — each level with clearly defined responsibilities.

Why learn

For large projects, a single monolithic agent gets lost in complexity. The orchestrator hierarchy divides the problem into manageable layers—each layer well-tested and replaceable.

Key Concepts

  • • Composition: workflows as building blocks
  • • Interface: each workflow has clear inputs and outputs
  • • Observability: logs propagate through the hierarchy
View Full
4.4 ~40 min

⏰ Cron and recurring tasks

Schedule agents to run at set intervals — daily reviews, automatic reports, and continuous monitoring without human intervention.

What it is

Cron lets you schedule tasks to run at specific times (daily, weekly, hourly). Claude Code integrates with cron via the /schedule skill to create agent routines.

Why learn

Recurring tasks are developers' biggest time sink. Daily code reviews, dependency updates, metrics reports — all can run without human intervention.

Key Concepts

  • • Cron syntax: minute hour day month weekday
  • • /schedule: Claude Code native skill
  • • Trigger: time event or system event

What it is

The command /loop repeats a task at set intervals while the session is active. It’s ideal for status polling, build monitoring, or continuous system observation.

Why learn

/loop is simpler than cron for short-lived tasks. It requires no infrastructure setup — it runs in the current session and stops when you close the terminal.

Key Concepts

  • • /loop 5m /status: runs /status every 5 minutes
  • • Auto-pace: without an interval, the agent decides the pace
  • • Cancellation: Ctrl+C stops the loop

What it is

Remote agents run on Claude's infrastructure without needing an open local terminal. They're triggered by events (webhook, cron) and run completely autonomously.

Why learn

Remote agents are the boundary between local automation and production automation. When you don't want (or can't) keep a laptop on 24/7 to run tasks, remote agents are the solution.

Key Concepts

  • • RemoteTrigger: launches an agent without a local session
  • • Asynchronous result: notification when it finishes
  • • Permissions: defined in settings.json before deploy

What it is

A daily review agent runs via cron every day at 9 a.m., analyzes code committed the previous day, generates a quality report, and sends it as a notification or saves it to a file.

Why learn

Automated code review doesn't replace the human reviewer—but it catches 80% of mechanical errors before human review. The human reviewer can focus on what matters: architecture and business logic.

Key Concepts

  • • git log --since=yesterday: gets the day's commits
  • • /code-review: Claude Code native skill
  • • Output: .md file or webhook to Slack/Discord

What it is

Asynchronous agents don't return results immediately. The output can be collected via PushNotification (webhook), a generated file, or polling with Monitor — depending on the configured delivery mechanism.

Why learn

Automation without observability is blind automation. Knowing where and how the result arrives is essential to trusting the automation — and to debugging when something goes wrong at 3 a.m.

Key Concepts

  • • PushNotification: webhook with result
  • • Monitor: real-time event stream
  • • File: configurable output path

What it is

Recurring agents accumulate costs over time. Idempotency ensures that running the agent twice produces the same result — crucial when failures lead to reruns.

Why learn

A cron task that fails and is rerun 5× can create 5 identical PRs or incur 5× the expected cost. Idempotency isn’t a detail — it’s a production requirement.

Key Concepts

  • • Check before acting: verify whether the task is already done
  • • Lock file: prevent simultaneous runs
  • • Budget alerts: notify when cost exceeds the threshold
View Full
← Track 3: Skills Track 5: Projects →