🚀 Running claude for the First Time
Type claude in the terminal. In the first run, Claude Code doesn't open the REPL directly — it detects that there are no credentials and starts the onboarding flow.
Detects missing credentials
Claude Code checks ~/.claude/
Welcome to Claude Code!
To get started, you'll need to authenticate...
Shows authentication options
Choose between an Anthropic account (OAuth) or an API key
1. Login with Anthropic account (browser)
2. Enter API key manually
>
Browser opens (option 1)
Authenticate via OAuth; token saved locally
Opening browser for authentication...
✓ Authentication successful
✓ Session saved to ~/.claude/
Interactive REPL opens
Ready for your first prompt
Claude Code (claude-sonnet-4-5)
Working directory: /home/user/meu-projeto
>
🔐 Detailed Login Flow
Claude Code uses OAuth2 via browser as the primary method. The credentials are stored in ~/.claude/ and remain valid until they expire (usually weeks).
Authentication commands
# Autenticar pela primeira vez (abre browser)
claude
# Verificar status de autenticação
claude --status
# Forçar reautenticação
claude --logout
claude
# Ver onde as credenciais estão salvas
ls ~/.claude/
# Autenticar em ambiente sem browser (API key)
export ANTHROPIC_API_KEY="sk-ant-..."
claude
💡 Token expired? Don’t worry
When the OAuth token expires, Claude Code notifies you in the next session and automatically reopens the browser. The flow is identical to the first login. Your settings and history are unaffected.
💳 API key vs. subscription
Two ways to pay for usage. The right choice depends on your usage volume — occasional use favors API key, heavy daily use favors Claude Max subscription.
🔑 API Key (Pay Per Use)
- •Pay per token consumed (input + output)
- •Ideal for occasional use or automated scripts
- •Granular cost control
- •Rate limits per minute/day
- •Variable:
ANTHROPIC_API_KEY
📋 Claude Max (subscription)
- •Fixed monthly fee with a generous allowance
- •Best value for daily use (8h/day)
- •Access to the latest models
- •Login via browser OAuth (no API key)
- •Quota resets monthly
Using an API key in Claude Code
# Opção 1: variável de ambiente (sessão atual)
export ANTHROPIC_API_KEY="sk-ant-api03-..."
claude
# Opção 2: persistir no .bashrc ou .zshrc
echo 'export ANTHROPIC_API_KEY="sk-ant-api03-..."' >> ~/.bashrc
source ~/.bashrc
# Opção 3: informar na autenticação interativa
claude
# Escolher opção 2 (Enter API key manually)
# Colar a chave quando solicitado
# Verificar qual método está sendo usado
claude --status
⚠️ Never expose your API key
Don't git add .env or committing files with ANTHROPIC_API_KEY. Add to the .gitignore. Exposed keys in public repos are automatically detected and revoked by Anthropic, but damage can still be done.
💬 The interactive prompt (REPL)
Claude Code's REPL accepts natural language, slash commands and references to files with @. Understanding these three inputs multiplies your productivity.
✓ What you can type
- ✓Requests in Portuguese: "Create a basic Express server"
- ✓File reference: "Refactor @src/api.js"
- ✓Slash commands:
/help,/clear,/status - ✓Long messages: Shift+Enter for a new line
- ✓Accumulated context: Claude remembers the conversation
✗ Avoid in the REPL
- ✗Vague requests without context: "improve the code"
- ✗Tasks that are too large for a single prompt
- ✗Paste secrets/tokens directly into chat
- ✗Ignore permission confirmations
Most useful slash commands
/help # Lista todos os comandos disponíveis
/clear # Limpa o contexto da conversa atual
/status # Mostra modelo, uso de contexto, autenticação
/exit # Sair do REPL (ou Ctrl+C)
/mcp # Lista servidores MCP conectados
/init # Gera CLAUDE.md para o projeto atual
/cost # Mostra tokens usados na sessão
💡 Use @ to reference files
Type @ in the REPL, opens autocomplete for project files. You can reference a specific file without manually pasting its contents:
> Explique o que faz @src/auth/middleware.js e sugira melhorias
⌨️ First real commands
Get hands-on now. These are the first requests you'll make to Claude Code—each demonstrates a different capability.
1. Create a file
> Crie um arquivo README.md para este projeto com seções básicas
Claude asks for confirmation before writing → you approve → file created
2. Explore the project
> O que faz este projeto? Leia os arquivos principais e me explique
Reading is safe — no confirmation needed. Claude reads and summarizes the codebase
3. Run command
> Rode os testes e me diga se todos passaram
Claude asks permission to run bash → you approve → it runs and reports back
4. Refactor code
> Refatore @src/index.js para usar async/await em vez de callbacks
Claude shows the diff before applying it → you review → approve or cancel
📊 Confirmation loop
Every action that modifies files or runs commands requires confirmation. This is the central safety mechanism:
- y → approve and execute
- n → decline (Claude tries an alternative approach)
- a → approve all pending actions for this task
- Ctrl+C → cancel the current task
🔄 Exit, resume, and manage sessions
Claude Code sessions retain context that you can resume. Understanding the session lifecycle helps you avoid losing important context in the middle of a project.
Session commands
# Sair do REPL
/exit # ou Ctrl+C duas vezes
# Retomar sessão anterior do mesmo diretório
claude --resume
# Ver sessões disponíveis
claude --list-sessions
# Iniciar sessão sem histórico (limpa)
claude --no-resume
# Usar claude sem REPL (modo print, para scripts)
claude --print "Gere um script Python para ordenar arquivos por data"
# Passar contexto via stdin
cat meu_arquivo.py | claude --print "Explique este código"
✓ Session best practices
- ✓Use
/clearwhen switching tasks - ✓Resume with
--resumeto continue bugs - ✓Use
/statusto see tokens used
💡 Context and tokens
Each session uses context tokens. Long sessions get more expensive/slower. Use /clear to reset when the context is no longer needed.
✅ Module 2.2 Summary
ANTHROPIC_API_KEY for automation and CI/CDNext Module:
2.3 — Configuration: settings.json and permissions. Full control over Claude Code’s behavior in your environment.