>Use CLAUDE.md for Persistent Context
Create a CLAUDE.md file in your project root to give Claude Code persistent context about your project. This file is automatically read at the start of every conversation, so you can include coding standards, project structure, and key decisions.
# CLAUDE.md
## Project Overview
This is a Next.js 14 app using TypeScript and Tailwind.
## Coding Standards
- Use functional components with hooks
- Prefer named exports over default exports
- Always use TypeScript strict mode
## Key Decisions
- We use Zustand for state management
- API routes are in /app/api>Set Max Turns for Autonomous Mode
Use the --max-turns flag to let Claude Code work autonomously for multiple steps. Great for complex refactoring tasks where you trust Claude to make good decisions.
# Let Claude work for up to 10 turns without asking
claude --max-turns 10 "Refactor all components to use TypeScript strict mode">Git Integration Best Practices
Let Claude Code handle your git workflow. It can stage changes, write commit messages, and even create PRs. Just be clear about when you want to commit.
# Good prompts for git operations
"Stage and commit these changes with a descriptive message"
"Create a PR for this feature branch to main"
"Show me the diff before committing"
# Claude will handle git commands and ask for approval>Use /compact to Save Context
When your conversation gets long, use the /compact command to summarize the conversation and free up context window space. This lets you continue working on complex projects without losing important information. AI context is like milk - it's best served fresh and condensed.
>Use Plan Mode for Complex Tasks
Before tackling a big feature, ask Claude to create a plan first. This helps ensure you're aligned on the approach before any code is written. People new to AI coding often assume it can one-shot anything - plan mode doubles your success rate.
# Start with a plan
You: "Plan how we should implement user authentication with OAuth"
# Claude will outline the steps, files to create, and approach
# Then you can approve or adjust before implementation>Debug with Screenshots
Claude Code can analyze screenshots! Take a screenshot of a bug and paste it directly into the conversation for visual debugging.
>Slash Commands Reference
Memorize these essential slash commands to navigate Claude Code like a pro.
/help - Show all available commands
/clear - Clear conversation history
/compact - Summarize and compress context
/status - Show current session status
/config - View/edit configuration
/undo - Undo last file change
/diff - Show pending changes>Custom MCP Server for Database Queries
Build a custom MCP server to let Claude Code query your database directly. This enables intelligent data exploration without manually writing SQL queries.
// mcp-server/database.ts
import { Server } from "@modelcontextprotocol/sdk/server";
const server = new Server({
name: "database-mcp",
version: "1.0.0",
});
server.tool("query_database", {
description: "Run a read-only SQL query",
parameters: {
query: { type: "string", description: "SQL query to run" }
},
handler: async ({ query }) => {
// Validate query is read-only
if (!query.trim().toLowerCase().startsWith("select")) {
throw new Error("Only SELECT queries allowed");
}
return await db.query(query);
}
});>Memory Files for Long Projects
Create a memory.md file to track project state, decisions, and TODO items across sessions. Reference it in your CLAUDE.md so Claude always knows the current status.
# memory.md
## Current Sprint
- [x] Setup authentication
- [ ] Add user profiles
- [ ] Implement dashboard
## Decisions Made
- Using Postgres for database
- JWT tokens for auth
- Tailwind for styling
## Blockers
- Waiting on API keys from client>Test-First Development
Ask Claude to write tests before implementing features. This leads to better code design and catches bugs early.
# Great prompt for TDD
"Before implementing the user registration feature:
1. Write unit tests for the registration logic
2. Write integration tests for the API endpoint
3. Then implement the feature to make tests pass">Infinite Agentic Loop for Parallel Generation
Use Claude Code's programmable nature to create infinite agentic loops that generate multiple variations in parallel. With just two prompts, you can spawn multiple agents working simultaneously.
# Use the /project:infinite slash command
/project:infinite specs/my_spec.md output_dir 5
# This deploys 5 parallel agents to generate
# 5 unique iterations simultaneously>Use Task Agents for Parallel Work
Claude Code can spawn sub-agents to work on independent tasks in parallel. This dramatically speeds up multi-file changes and is one of the most powerful features for complex refactoring.
# In your conversation
"Update all API routes to use the new auth middleware.
You can work on multiple routes in parallel using task agents."
# Claude will spawn agents for independent route updates>Quick Install with npx
No need to install Claude Code globally. Run it directly with npx for the latest version every time.
# Run Claude Code without installing
npx @anthropic-ai/claude-code
# Or install globally for faster startup
npm install -g @anthropic-ai/claude-code>Vim Mode Navigation
Enable vim keybindings in Claude Code for faster navigation. Perfect for developers who live in the terminal.
# In your shell config (.zshrc or .bashrc)
export CLAUDE_EDITOR=vim
# Or configure in settings
claude config set editor vim>API Key Management
Set your Anthropic API key as an environment variable for seamless authentication. Never hardcode keys in your projects!
# Add to your shell profile
export ANTHROPIC_API_KEY="sk-ant-..."
# Or use a .env file (add to .gitignore!)
echo "ANTHROPIC_API_KEY=sk-ant-..." >> .env
echo ".env" >> .gitignore