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:
# 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:
# 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:
# 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.
# 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
# Inside Claude Code /compact # Claude summarizes the conversation so far # and replaces it with a compact summary
Resuming a session
# 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:
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 documentationGit workflows
Creating feature branches automatically
> "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
# 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:
# 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
# Save the transcript of the current session claude -p --output-format json "summary of today's work" > sesion-$(date +%Y%m%d).json