Tutorial 09: Custom Legal Skills, Hooks & Agents
Build custom skills for your firm's workflows, create compliance hooks, and deploy multi-agent systems for complex legal tasks.
What You'll Learn
This tutorial shows you how to build custom legal skills, add safety checks (hooks), and run multi-agent workflows. Some technical comfort is required.
Expert Level
Developer skills recommended. Estimated time: 120 minutes.
Learning Objectives
By the end of this tutorial, you will:
- Understand Claude Code's architecture (Skills, Hooks, Sub-agents)
- Build custom legal skills for your firm's workflows
- Create hooks for quality control and compliance
- Deploy multi-agent systems for complex legal tasks
Part 1: Understanding the Claude Code Stack
Architecture Overview
Why This Matters for Legal
| Component | Legal Application |
|---|---|
| Skills | Encode playbooks, review procedures, drafting standards |
| Hooks | Enforce compliance, prevent unauthorized actions, audit logging |
| Sub-agents | Parallelize document review, research tasks |
| Plugins | Package firm workflows for distribution |
May 2026 source check
Claude Code 2.1.133 adds worktree.baseRef, effort-level hook inputs, managed sandbox binary settings, and fixes for MCP OAuth proxy handling, concurrent-session auth, and subagent skill discovery. For legal automations, set the worktree base deliberately, retest hooks that depend on effort level or permissions, and rerun MCP-connected document workflows before production use.
Claude Code 2.1.139 update
Claude Code 2.1.139 adds agent view, /goal, direct hook argument execution with args, PostToolUse continuation with continueOnBlock, MCP CLAUDE_PROJECT_DIR environment support, and subagent telemetry headers. For legal workflows, retest privileged-folder hooks, MCP server configs, and goal-driven unattended sessions in a sandbox before using them on client or privileged material.
Part 2: Building Custom Legal Skills
What Are Skills?
Skills are specialized instructions stored in files that Claude reads based on context. Unlike prompts (one-time), Skills persist and activate automatically.
Skill File Structure
Creating a Contract Review Skill
Step 1: Create Skill Directory
Step 2: Write SKILL.md
Step 3: Create Playbook Resource
resources/playbook.json:
Step 4: Create Clause Library
resources/clause-library.md:
Step 5: Install and Test
Part 3: Building Compliance Hooks
What Are Hooks?
Hooks are scripts that execute at specific points in Claude's operation:
Production note: Hooks can block or alter a workflow. Test them in a sandbox with the real permissions, effort levels, and MCP servers before using them on client matters or privileged documents.
Claude Code 2.1.139 adds an exec-form hook args field and continueOnBlock for PostToolUse. Prefer exec-form arguments for hooks that receive file paths or matter identifiers because they avoid shell quoting issues. Use continueOnBlock only when the hook's rejection reason is safe to feed back into the model and does not reveal privileged or confidential facts.
| Hook Type | Trigger Point | Use Case |
|---|---|---|
PreToolUse | Before any tool runs | Block dangerous actions |
PostToolUse | After tool completes | Audit logging |
SessionStart | When session begins | Load context |
UserPromptSubmit | Before prompt processing | Filter content |
Stop | When Claude finishes responding | Quality checks |
Claude Code 2.1.141 hook updates
Claude Code 2.1.141 adds a terminalSequence field to hook JSON output for desktop notifications, window titles, and bells without a controlling terminal. It also fixes hook transcript paths after EnterWorktree changes the working directory. For legal workflows, keep hook output limited to non-confidential status signals, retest transcript-path assumptions, and avoid putting matter names or privileged facts into terminal titles or notifications.
Legal Compliance Hook Example
Purpose: Prevent Claude from making unauthorized changes to privileged documents.
Step 1: Create Hook Directory
Step 2: Create Hook Scripts
~/.claude/hooks/pretool-privileged-guard.sh:
~/.claude/hooks/posttool-audit-log.sh:
Step 3: Configure Hook
~/.claude/settings.json:
Additional Hook Use Cases
Citation Verification Hook (Stop):
Confidentiality Check Hook:
Part 4: Multi-Agent Legal Workflows
Understanding Sub-Agents
Claude can spawn sub-agents to handle specific tasks:
- Parallelization: Multiple documents reviewed simultaneously
- Specialization: Different agents for different tasks
- Isolation: Separate context for separate analyses
Claude Code 2.1.141 adds claude agents --cwd <path> to scope the session list to a directory, and background agents launched with /bg or ←← now preserve the current permission mode. Use the directory scope when auditing agents tied to a matter workspace, and verify background sessions keep the intended permission posture before assigning privileged-document or repository-writing tasks.
Example: Parallel Due Diligence Review
Example: Research + Draft Workflow
Part 5: Packaging Skills into Plugins
Plugin Structure
Plugin Manifest
Plugin metadata and schema evolve quickly. Use the official plugins reference for the current manifest format, then map your legal assets into that structure.
Minimal hooks/hooks.json example:
Installing and Distributing
For environments without a GitHub SSH key, Claude Code 2.1.141 adds CLAUDE_CODE_PLUGIN_PREFER_HTTPS so GitHub plugin sources can be cloned over HTTPS. Enterprise teams using workload identity federation can also set ANTHROPIC_WORKSPACE_ID to scope minted tokens to a specific workspace when the federation rule covers more than one workspace.
Part 6: Security Considerations
Skill Security
- Source verification: Only install skills from trusted sources
- Code review: Review all hook code before deployment
- No client data: Never include client data in skill files
- Version control: Track changes to skills
- Access control: Limit who can modify firm skills
Data Protection
Compliance Requirements
- Skills reviewed by IT security
- Hooks tested in sandbox environment
- Audit logging enabled
- Client data segregation verified
- Access controls configured
- Backup procedures documented
Do This Now
- Create a custom skill for one of your firm's review processes
- Add at least one safety check (hook) for compliance or audit logging
- Test a multi-agent workflow for parallel document processing
- Document your skill so your team can use it
- Consider packaging as a plugin for distribution
Related family pages
Navigation
Quick Reference: Claude Code Commands
Sources
- Agent Skills Overview (Claude Docs)
- Agent Skills Quickstart (Claude Docs)
- Agent Skills Best Practices (Claude Docs)
- Use Skills in Claude Code
- Hooks Reference (Claude Code Docs)
- Create custom subagents (Claude Code Docs)
- Connect Claude Code to tools via MCP
- Plugins Reference (Claude Code Docs)