You’re 40 messages deep, Claude has lost the thread, every response is slower than the last, and you can’t remember which of yesterday’s sessions had the schema work. The Claude Code CLI has a precise answer for each of those problems — resuming the right session, clearing context at the right moment, and shelling out to headless mode for the parts a script should own. These tips cover the commands and shortcuts that separate a fluent power user from someone fighting the REPL.
The correct claude -r / claude -c resume model (by session name or picker — no fabricated index numbers)
Headless one-liners that produce parseable JSON for commit messages, reviews, and CI
Copy-paste prompts for a conventional-commit generator, a pre-commit console.log scan, and a reusable PR-review command
A “When This Breaks” section for the failure modes that actually bite: wrong session resumed, runaway --dangerously-skip-permissions, and JSON parsing that silently fails
Claude Code persists sessions across runs, but resume works by ID, name, or picker — there is no numeric index like claude -r 5. Knowing the exact forms saves you from re-opening the wrong conversation:
Terminal window
# Within a session, navigate prior prompts with arrow keys
↑# Previous prompt
↓# Next prompt
# Open an interactive picker of recent sessions
claude-r
# Use arrow keys or type to filter, then Enter to resume
# Resume directly by session ID or name, and queue a query
claude-r"auth-refactor""Finish this PR"
# Continue the most recent session in the current directory
claude-c
Name your sessions intentionally (the picker and -r "<name>" both rely on it) and the “which one had the schema work?” problem disappears.
For automation and quick operations, always reach for -p (print/non-interactive). Bare claude "..." launches the REPL and will hang in a pipeline; claude -p "..." runs once and exits. Redirect a single file with <, and pipe a directory’s worth of code with cat/git diff — you cannot redirect stdin from a directory (< src/ errors with “Is a directory”).
Terminal window
# Quick formatting (single file via stdin)
claude-p"format this SQL query"<query.sql>formatted.sql
# Code review of a diff
gitdiff|claude-p"review these changes for security issues"
The CLI is fast, which means a wrong assumption burns time or tokens before you notice. The failure modes that actually bite:
Resume opens the wrong session.claude -r without an argument shows a picker; resuming “the last one” with -c grabs whatever ran most recently in this directory — which may not be the work you meant. Name sessions and resume by name (claude -r "auth-refactor") when it matters. There is no claude -r 5 index to fall back on.
--dangerously-skip-permissions on a runaway task. Skipping approvals is great until Claude loops on a failing build and burns tokens unattended. Use it for short, well-scoped tasks; keep /cost open, and never pair it with a vague prompt like “fix everything”.
Headless JSON parsing silently fails.claude -p "..." defaults to plain text, so piping it to jq errors or returns null. Add --output-format json and read the .result field (or .structured_output when you pass --json-schema). A hook that forgets this will pass when it should block.
Bare claude "..." hangs in CI. Without -p, the command launches the interactive REPL and waits forever in a non-interactive pipeline. Every scripted invocation needs -p.
Shift+Enter inserts nothing. Multiline input requires terminal key bindings; run /terminal-setup once. Until then, paste multiline prompts or wrap them in quotes on the command line.
With command-line mastery achieved, you’re ready to tackle large, complex codebases. Continue to Large Codebase Management to learn strategies for enterprise-scale development.