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:
# Dentro de Claude Code, Claude decide cuándo paralelizar > "Genera tests unitarios para cada archivo en src/components. Hazlo en paralelo." # Claude lanzará un subagente por archivo automáticamente
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:
# Crear un worktree para una feature branch git worktree add ../mi-proyecto-feature feature/nueva-api # Entrar en ese directorio y abrir Claude Code allí 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:
# Modo headless básico
claude -p "revisa el código en busca de vulnerabilidades SQL"
# Con output JSON para parsear
claude -p --output-format json "lista todos los TODO del proyecto" | jq '.result'
# En un Makefile o script CI
claude -p --dangerously-skip-permissions \
"ejecuta los tests, si hay fallos corrígelos y haz commit"
# En GitHub Actions
- name: Claude Code Review
run: |
claude -p "revisa los cambios del PR y comenta problemas de seguridad" \
--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.
# Modelo equilibrado para el día a día claude --model sonnet # Más razonamiento en la sesión actual claude --model opus --effort high # Dentro de la sesión puedes abrir el selector /model
Long sessions and compaction
In long sessions, context fills up and Claude Code can become slower or lose coherence. Solutions:
Compacting context
# Dentro de Claude Code /compact # Claude resume la conversación hasta el momento # y la reemplaza por un resumen compacto
Resuming a session
# Ver sesiones recientes claude resume # Continuar la última sesión claude resume --last # El contexto se restaura automáticamente
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 ← instrucciones globales
├── frontend/
│ └── CLAUDE.md ← instrucciones para el frontend
├── backend/
│ └── CLAUDE.md ← instrucciones para el backend
└── docs/
└── CLAUDE.md ← instrucciones para documentaciónGit workflows
Creating feature branches automatically
> "Implementa el sistema de notificaciones push. Crea una feature branch, haz los cambios necesarios y al terminar prepara el PR." # Claude hará: # 1. git checkout -b feature/push-notifications # 2. Implementar los cambios # 3. git add + git commit con mensaje descriptivo # 4. Preparar el cuerpo del PR para que lo apruebes
Automated code review
# Revisar el diff del último commit claude -p "revisa este diff en busca de bugs y problemas de rendimiento" \ <<< "$(git diff HEAD~1)" # Revisar todo un PR gh pr diff 123 | claude -p "haz un code review completo"
Integration with tmux / split panes
A popular workflow is to have Claude Code in one pane and your editor in another:
# Crear sesión tmux con dos paneles tmux new-session -d -s dev tmux split-window -h tmux send-keys -t dev:0.0 "claude" Enter # Claude Code a la izquierda tmux send-keys -t dev:0.1 "nvim ." Enter # Editor a la derecha
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
# Guardar el transcript de la sesión actual claude -p --output-format json "resumen del trabajo de hoy" > sesion-$(date +%Y%m%d).json