Skip to content

Advanced Usage

Advanced techniques to get the most out of Claude Code: subagents, worktrees, CI/CD integration, headless mode, and more.

Subagents

Claude Code can launch subagents: parallel instances of Claude that work independently on subtasks. This is especially useful for tasks that can be parallelized.

Examples where subagents shine:

  • Refactoring 20 files in parallel.
  • Generating tests for multiple modules simultaneously.
  • Investigating different solutions at once and choosing the best one.

Launching subagents with the Claude SDK:

Terminal
# Inside Claude Code, Claude decides when to parallelize
> "Generate unit tests for each file in src/components. Do it in parallel."

# Claude will launch one subagent per file automatically

Git worktrees

Git worktrees let you work on multiple branches of the same repository at the same time, in separate directories. You can use them to isolate large changes before opening Claude Code:

Terminal
# Create a worktree for a feature branch
git worktree add ../mi-proyecto-feature feature/nueva-api

# Enter that directory and open Claude Code there
cd ../mi-proyecto-feature
claude

This way you separate changes from your main branch with a stable, verifiable Git tool. When you're done, review the diff, run tests, and merge or remove the worktree as appropriate.

Headless mode / CI-CD

Claude Code can run without an interactive interface, ideal for CI/CD pipelines, scripts, and automations:

Terminal
# Basic headless mode
claude -p "review the code for SQL vulnerabilities"

# With JSON output for parsing
claude -p --output-format json "list all TODOs in the project" | jq '.result'

# In a Makefile or CI script
claude -p --dangerously-skip-permissions \
  "run the tests, if there are failures fix them and commit"

# In GitHub Actions
- name: Claude Code Review
  run: |
    claude -p "review the PR changes and comment on security issues" \
      --output-format json > review.json
  env:
    ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}

Choosing model and effort

Instead of memorizing specific IDs, use model aliases. Claude Code resolves sonnet, opus, haiku, or fable based on your provider and permissions.

Terminal
# Balanced model for day-to-day use
claude --model sonnet

# More reasoning in the current session
claude --model opus --effort high

# During the session you can open the selector
/model

Long sessions and compaction

In long sessions, context fills up and Claude Code can become slower or lose coherence. Solutions:

Compacting context

Terminal
# Inside Claude Code
/compact

# Claude summarizes the conversation so far
# and replaces it with a compact summary

Resuming a session

Terminal
# View recent sessions
claude resume

# Continue the last session
claude resume --last

# Context is restored automatically

CLAUDE.md in subdirectories

You can have CLAUDE.md files in subdirectories of your project. Claude will read them automatically when working in that folder, giving it specific instructions for that part of the codebase:

Terminal
mi-proyecto/
├── CLAUDE.md              ← global instructions
├── frontend/
│   └── CLAUDE.md          ← instructions for the frontend
├── backend/
│   └── CLAUDE.md          ← instructions for the backend
└── docs/
    └── CLAUDE.md          ← instructions for documentation

Git workflows

Creating feature branches automatically

Terminal
> "Implement the push notification system. Create a feature branch,
   make the necessary changes, and when finished prepare the PR."

# Claude will:
# 1. git checkout -b feature/push-notifications
# 2. Implement the changes
# 3. git add + git commit with a descriptive message
# 4. Prepare the PR body for you to approve

Automated code review

Terminal
# Review the diff of the last commit
claude -p "review this diff for bugs and performance issues" \
  <<< "$(git diff HEAD~1)"

# Review an entire PR
gh pr diff 123 | claude -p "do a complete code review"

Integration with tmux / split panes

A popular workflow is to have Claude Code in one pane and your editor in another:

Terminal
# Create a tmux session with two panes
tmux new-session -d -s dev
tmux split-window -h
tmux send-keys -t dev:0.0 "claude" Enter  # Claude Code on the left
tmux send-keys -t dev:0.1 "nvim ." Enter  # Editor on the right

Productivity tips

  • Be specific with context: mention the file, function, and exact error. The more specific you are, the better the result.
  • A useful alias: alias ai="claude -p" for quick queries without entering interactive mode.
  • Memory across sessions: keep your CLAUDE.md updated with architecture decisions and project conventions.
  • Large tasks: break work into smaller subtasks. Claude works better with focused, clear objectives.
  • Review before accepting: always use the diff view to understand exactly what will change before confirming.

Exporting the session

Terminal
# Save the transcript of the current session
claude -p --output-format json "summary of today's work" > sesion-$(date +%Y%m%d).json
Complete Aulafy mapSee how this lesson fits without leaving your path.

Complete Aulafy map

How all courses connect

This is not a checklist. Start with the foundation, choose an outcome, and go deeper only when your project needs more control.

  1. 1Understand
  2. 2Apply or build
  3. 3Operate with confidence
01

Choose an application

Turn the foundation into a visible outcome: a website, a business improvement, media, or an interactive experience.

Continue into the technical branch when you need to maintain code, data, or infrastructure.

02

Build with code

Prepare your environment, work with coding agents, and run models while keeping control of your projects.

This branch prepares you to design and operate reliable AI systems.

03

Take systems to production

Combine retrieval, agents, evaluation, security, deployment, and model adaptation when the problem requires it.

You do not need every course: choose the component your system needs and return as it grows.

View full catalogue