25 Claude Code Tips & Tricks for Faster AI Coding
Claude Code is packed with features that most developers never discover. This guide collects 25 practical tips and tricks -- organized by category -- that will make your AI coding sessions noticeably faster and more reliable.
Setup & Configuration
1. Create a project CLAUDE.md
The single highest-impact thing you can do. A CLAUDE.md at your repo root is loaded into every conversation, giving Claude your build commands, conventions, and architecture context. Keep it under 150 lines. See the best practices guide for detailed examples.
# CLAUDE.md
## Commands
- `npm run dev` - Start dev server
- `npm test` - Run vitest
## Conventions
- Named exports only, no default exports
- Error responses: { error: string, code: number }
2. Use a global CLAUDE.md for personal preferences
Place a file at ~/.claude/CLAUDE.md for settings that apply across all projects -- code style, commit format, timezone. Loaded alongside project-level files. Learn more in the memory guide.
# ~/.claude/CLAUDE.md
- Prefer functional style over classes
- Concise commit messages (under 72 chars)
- Don't add comments unless logic is non-obvious
3. Add directory-scoped CLAUDE.md files
For monorepos, place a CLAUDE.md inside subdirectories. Claude loads them automatically when working in that directory, keeping context relevant without bloating the root file.
# apps/api/CLAUDE.md
- Express + TypeScript, routes use asyncHandler()
- Tests use supertest + vitest
4. Configure keybindings for common actions
Use Escape to interrupt Claude mid-response, Ctrl+C to cancel current input, Tab for file path autocompletion, and Up arrow to recall your previous prompt for quick edits.
5. Set your default model
Switch models with --model. Use Opus for complex architecture, Sonnet for general coding, Haiku for quick questions. See the CLI reference for all flags.
claude --model haiku "what does this regex do: ^[\w.-]+@[\w.-]+$"
claude config set model sonnet
Workflow Tips
6. Use slash commands to save time
The most useful built-in commands: /plan for complex tasks, /compact to shrink context, /clear to reset the conversation, and /cost to check token usage. Custom slash commands live in .claude/skills/.
7. Create custom skills for repeated workflows
If you give Claude the same instructions more than twice, extract them into a skill. Skills are markdown files in .claude/skills/ invoked as slash commands.
# .claude/skills/review.md
When reviewing code:
1. Check for security issues (injection, auth bypass)
2. Verify error handling on all async paths
3. Flag any missing input validation
8. Pipe output directly into Claude
One of the most powerful and underused tricks. Pipe any command output directly to Claude for instant analysis -- no copy-pasting needed.
git diff --staged | claude "review these changes"
npm run build 2>&1 | claude "fix this build error"
npm test 2>&1 | claude "why are these tests failing?"
9. Use /plan before complex changes
For tasks spanning multiple files or requiring architectural decisions, start with /plan. Claude outlines its approach without making changes, letting you review and adjust before any code is modified.
10. Point Claude to specific files
Instead of "find the login bug," tell Claude exactly where to look. Direct file references save context tokens and produce better first-attempt results.
Look at src/auth/middleware.ts lines 45-60.
The JWT validation is not checking token expiry.
11. Ask for multi-file edits in a single prompt
Describe all changes together rather than file-by-file. Claude produces more consistent results when it understands the full scope.
Add a "lastLogin" field to the User model in src/models/user.ts,
update the login handler in src/routes/auth.ts to set it,
and add a migration in src/db/migrations/.
12. Commit after each discrete unit of work
Ask Claude to commit after each logical change for clean rollback points. Avoid letting changes accumulate across a long session without committing.
Advanced Tricks
13. Set up hooks for automatic formatting
Use hooks to run your formatter every time Claude writes a file. Style drift is eliminated entirely.
// .claude/settings.json
{ "hooks": { "PostToolUse": [{
"matcher": "Write|Edit",
"hook": "npx prettier --write $CLAUDE_FILE_PATH 2>/dev/null; exit 0"
}]}}
14. Use Stop hooks for test feedback loops
A Stop hook runs after Claude finishes. Use it to run tests automatically -- failures are fed back to Claude so it can self-correct.
{ "hooks": { "Stop": [{
"hook": "npm test -- --bail 2>&1 | tail -20"
}]}}
15. Guard critical files with PreToolUse hooks
Protect lock files, production configs, or migrations from accidental edits with a PreToolUse hook that blocks writes to specific paths.
{ "hooks": { "PreToolUse": [{
"matcher": "Write|Edit",
"hook": "echo $CLAUDE_FILE_PATH | grep -qE 'lock' && echo 'BLOCK' && exit 1; exit 0"
}]}}
16. Run Claude headless in CI/CD
Claude Code works in non-interactive mode for CI pipelines. Use one-shot mode with structured output for automated PR review, code generation, and test writing.
claude --output-format json --max-turns 5 \
"review the changes in this PR and output a JSON summary"
17. Build custom tools with the SDK
The Claude Code SDK lets you build programmatic agents for batch processing, multi-repo changes, or embedding Claude into your own tools.
import { claude } from "@anthropic-ai/claude-code";
const result = await claude({
prompt: "find and fix all TODO comments in src/",
maxTurns: 10, model: "sonnet"
});
18. Use MCP servers to extend capabilities
MCP servers give Claude access to databases, APIs, browsers, and more. Browse the MCP directory to find servers for your stack.
{ "mcpServers": { "postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/mydb"]
}}}
Performance & Context
19. Use /compact when context gets long
Long conversations slow Claude down as the context window fills. Run /compact to summarize history into a condensed form, freeing context space and speeding up subsequent responses.
20. Spawn subagents for parallel work
Claude can spawn subagent tasks that run in parallel. Independent pieces of work -- updating tests while refactoring code -- are handled concurrently via the Task tool.
21. Keep CLAUDE.md lean
Every line consumes context tokens in every conversation. Move specialized instructions into skills that are only loaded when invoked.
Rule of thumb: if an instruction applies to fewer than half your sessions, it belongs in a skill, not in CLAUDE.md.
22. Use one-shot mode for quick questions
Pass your prompt as a command argument for simple questions. Claude answers and exits immediately without session state.
claude "what port does this project run on?"
claude "explain the User type in src/types.ts"
23. Avoid dumping entire files into prompts
Reference files by path and tell Claude which section matters. Claude reads files itself using far less context than a raw paste.
Debugging & Troubleshooting
24. Use verbose mode to see what Claude is doing
Run claude --verbose to see every tool call, file read, and API request in real time. Invaluable when Claude seems stuck or you want to understand its approach.
claude --verbose
claude config list
25. Check permissions when commands fail
If Claude cannot run a command or edit a file, check .claude/settings.json. Use claude config list to review active permission settings.
{ "permissions": {
"allow": ["Bash(npm test)", "Bash(npm run build)"],
"deny": ["Bash(rm -rf)"]
}}
Stuck in a loop? Use /compact to reset context, then re-describe the problem with more specifics about what you have already tried.