Claude Code CLI tips and workflows 2026
Claude Code CLI is the most capable terminal-first AI coding tool available in 2026 - but most developers only scratch the surface of what it can do. The basic workflow (install, run claude, ask it to do something) works fine for simple tasks. The advanced workflow - CLAUDE.md for standing context, MCP for live data, prompt patterns that produce precise output, and tight integration with your git workflow - is what makes it genuinely transformative for daily development. This guide covers all of it.
Install and first run
Install Claude Code globally via npm:
npm install -g @anthropic-ai/claude-code
Authenticate with your Anthropic API key (set ANTHROPIC_API_KEY as an environment variable, or Claude Code will prompt you). Navigate to any project directory and run:
cd your-project claude
Start with an orientation prompt to test it: "Describe this codebase's architecture in 3 sentences." Claude Code will read your files and give you a grounded answer. If it gets the architecture right, your CLAUDE.md setup (covered next) is working. If it seems to misunderstand the project, that is your signal to write a CLAUDE.md.
CLAUDE.md: the highest-leverage setup step
CLAUDE.md is a markdown file you commit to your repo root. Claude Code reads it at the start of every session as standing context - before it reads a single line of your code. It is the equivalent of a thorough onboarding document for the AI.
A minimal but effective CLAUDE.md:
# Project: [Name] ## Stack - Node 20, TypeScript 5 (strict mode) - Express 4 / Postgres 15 via Prisma - Vitest for tests ## Structure - src/routes/ - HTTP handlers - src/services/ - business logic (never in routes) - src/db/ - Prisma queries only - tests/ - co-located as [module].test.ts ## Commands - Dev: npm run dev - Tests: npm test - Type check: npm run typecheck ## Never - Never use `any` in TypeScript - Never write business logic in route handlers - Never modify prisma/schema.prisma directly - Never add console.log - use src/utils/logger.ts
Once CLAUDE.md is in place, every Claude Code session starts with full awareness of your stack and conventions. The quality improvement on the first prompt after adding a good CLAUDE.md is immediately noticeable.
The best use cases for Claude Code CLI
Claude Code is most valuable for tasks where the terminal model is an advantage - not a compromise. These are the workflows where it consistently outperforms an IDE-based agent:
Batch operations across many files
Rename a module used across 40 files. Update all API calls from a deprecated format to a new one. Add error handling to every function in a directory. These are tasks where the IDE overhead of Cursor slows you down - Claude Code runs autonomously to completion.
claude "Rename all imports of UserService to UserRepository across the entire codebase. Update the class definition too."
Generating test suites
After writing a new module in Cursor, hand it to Claude Code to generate the full test suite:
claude "Write comprehensive Vitest tests for src/services/payment.ts. Test both happy paths and error cases. Co-locate the test file at src/services/payment.test.ts."
One-off scripts and data migrations
Write a script that transforms a CSV, seeds a database, or migrates data from one schema to another. Claude Code writes the script, you review it, run it, done - no permanent file change needed.
Codebase exploration and Q&A
Ask questions about an unfamiliar codebase before touching it:
claude "How does authentication work in this project? Which files handle token validation?"
This is faster than reading dozens of files manually and gives you a map before you start making changes.
CI-integrated automation
Claude Code can be invoked from CI scripts for automated tasks - generating changelogs, validating that documentation matches code, or running code quality checks beyond what standard linters catch.
Prompt patterns that produce better output
Be explicit about scope
Tell Claude Code exactly which files or directories are in scope. Without this, it may do more or less than you intended.
# Vague - may touch too much claude "Refactor the auth module" # Better - explicit scope claude "Refactor src/services/auth.ts only. Extract the token validation logic into a separate function called validateToken. Do not modify any other files."
Specify the expected output format
For tasks where the output format matters (tests, scripts, migration files), say what you expect:
claude "Write a database seed script at scripts/seed.ts. It should use Prisma, seed 10 test users with realistic data, and be idempotent (safe to run multiple times)."
Include constraints upfront
State what NOT to do before Claude Code starts a session, not after it has already done the wrong thing:
claude "Add input validation to all POST routes in src/routes/. Use zod for validation. Do NOT modify any existing response shapes - only add validation before the handler logic."
Use --print for non-interactive output
The --print flag outputs Claude Code's response to stdout without interactive prompts - useful for piping into other commands or CI scripts:
claude --print "Summarize the changes in the last 5 commits" > changelog-draft.md
MCP integration
MCP (Model Context Protocol) servers extend Claude Code with live data sources. Configure them in ~/.claude.json or a project-level .claude.json:
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres"],
"env": { "DATABASE_URL": "${DATABASE_URL}" }
}
}
}
With the Postgres MCP server configured, Claude Code can query your live schema rather than guessing it. The impact: no more incorrect column names, no more wrong data types, no more queries that would fail on your actual database. See our best MCP servers guide for the full list of recommended integrations.
Git workflow with Claude Code
Always run Claude Code on a branch - never directly on main:
git checkout -b ai/add-search-feature claude "Add full-text search to the /products endpoint using Postgres tsvector..." git diff # review all changes git add -p # stage by hunk git commit -m "feat: add full-text product search"
The git add -p step is key - it lets you stage exactly the changes you want and skip anything the agent did that you do not agree with, without losing the rest of the session's work. See our diff-based workflows guide for the full approach.
Pairing Claude Code with Cursor
The most productive setup for most developers: Cursor for interactive IDE work (feature dev, diff review, iterating on a specific file), Claude Code for batch and automation tasks (test generation, refactors across many files, scripts). Both tools work on the same repo. The split that works:
- Cursor Agent: writing new features, reviewing diffs inline, anything where you want back-and-forth in the editor
- Claude Code: test suites, batch renames, data migrations, CI scripts, codebase exploration
Use BrainGrid as the shared spec layer between both - write the task spec once, reference it in your Cursor Agent prompt and your Claude Code session, keep both agents aligned on the same goal.
Pricing: API vs Claude Max
Claude Code uses Anthropic API tokens by default - you pay per token used. A focused session (one clear task, 2–3 file edits) typically costs $0.50–$2. A longer session exploring a large codebase or generating a big test suite can cost $3–10. Claude Max ($100/mo) includes generous Claude Code usage limits and is the better option for developers who use it daily. See our Claude Code vs Cursor Agent pricing comparison for a worked example.
Better prompts = better output. Write a structured task spec in BrainGrid before each Claude Code session - clearer scope, fewer wasted tokens, more focused output.