Fundamentally understand Claude Code as a command-line tool with all its basic characteristics.
# Claude Code can execute all standard CLI operations
claude --help
claude --version
claude --list-sessions
Use the -P parameter to run in command-line mode.
# Directly pass prompts to execute tasks
claude -P "Analyze package.json and list all dependencies"
Use the -P parameter to run in non-interactive mode.
# Non-interactive mode, output results directly
claude -P "Generate a React component" --no-interactive
Connect other command-line tools (bash/CLI tools) to the workflow.
# Use with other tools
git diff | claude -P "Explain these code changes"
npm test 2>&1 | claude -P "Analyze test failure reasons"
Pass data to Claude Code through pipes (|).
# Pass data via pipe
cat error.log | claude -P "Analyze error log and provide solutions"
curl https://api.example.com | claude -P "Parse this API response"
Run multiple Claude Code instances simultaneously to handle different tasks.
# Terminal 1
claude --session frontend-work
# Terminal 2
claude --session backend-api
# Terminal 3
claude --session testing
Instruct Claude Code to launch a new instance to handle tasks.
Please run tests in a new Claude instance and report the results to me.
Use the shortcut Shift+Command+Control+4 to copy screenshots to clipboard.
Press Shift+Command+Control+4
Select the area to screenshot
Screenshot automatically copies to clipboard
Use Control+V (not Command+V) to paste images to terminal.
Note: In macOS terminal, use
Control+Vinstead ofCommand+Vto paste images
Paste design mockups and let Claude Code build the interface.
[Paste design image]
Please generate corresponding React components based on this design, including:
- Responsive layout
- Mobile adaptation
- Using Tailwind CSS
Screenshot the current state of your app and feed it back to Claude Code for iterative modifications.
Generate initial interface code
Capture running effect screenshot
Adjust based on screenshot
Repeat until satisfied
Use Puppeteer MCP service to automate the screenshot generation process.
// Automated screenshot script example
const puppeteer = require('puppeteer')
async function captureScreenshots() {
const browser = await puppeteer.launch()
const page = await browser.newPage()
// Capture screenshots of different states
await page.goto('https://localhost:3000')
await page.screenshot({ path: 'homepage.png' })
await page.click('.login-button')
await page.screenshot({ path: 'login-page.png' })
await browser.close()
}
Process multiple image files simultaneously.
Please analyze all screenshots in the screenshots/ directory and identify UI inconsistencies.
Claude Code can act as both an MCP server and connect to other services as a client.
// MCP configuration example
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["@modelcontextprotocol/server-postgres"]
}
}
}
Use Postgres MCP server to connect Claude Code to your database.
After connecting to the database, please:
1. Analyze existing table structure
2. Generate TypeScript type definitions
3. Create CRUD API interfaces
Use MCP servers provided by companies like Cloudflare to get real-time updated documentation.
Please get the latest Workers API documentation from Cloudflare MCP and create a sample project.
Paste a URL directly and Claude Code will crawl the webpage content as context.
https://docs.example.com/api/v2
Please create a corresponding TypeScript SDK based on the above documentation.
Use URL crawling to get external knowledge and apply it to code.
https://en.wikipedia.org/wiki/Chess_rules
Based on the above rules, implement the core logic of a chess game.
CLAUDE.md is a system prompt file that loads on every request.
# CLAUDE.md Example Structure
## Project Overview
Brief description of project purpose and tech stack
## Development Standards
- Code style guide
- Naming conventions
- File organization structure
## Common Commands
List frequently used project commands
## Important Notes
Project-specific notes and limitations
Run /init command in project directory to auto-generate CLAUDE.md based on project structure.
# Run in project root directory
> /init
# Claude Code will analyze project and generate configuration file
Define project-specific coding rules in CLAUDE.md.
## Project Rules
- All API responses must include status and data fields
- Use camelCase for variables, PascalCase for components
- Forbidden to use any type, must define explicit TypeScript types
Include frequently used code templates in configuration file.
## Code Templates
### React Component Template
\```tsx
import React from 'react';
interface Props {
// props definition
}
export const ComponentName: React.FC<Props> = ({ }) => {
return <div></div>;
};
\```
Use CLAUDE.md to record important architecture decisions.
## Architecture Decision Records
### ADR-001: Using Redux Toolkit
- **Date**: 2024-01-15
- **Decision**: Adopt Redux Toolkit for state management
- **Reason**: Simplify Redux usage, reduce boilerplate code
Document the purpose and version requirements of key dependencies.
## Key Dependencies
| Package | Version | Purpose | Notes |
| ------- | ------- | -------------------- | ------------------------- |
| react | ^18.0.0 | UI framework | Using concurrent features |
| next | ^14.0.0 | Full-stack framework | App Router |
Clarify project testing requirements and strategy.
## Testing Strategy
- Unit test coverage > 80%
- All API endpoints must have integration tests
- Using Jest + React Testing Library
- E2E testing with Playwright
Create custom commands in .claude/commands/ directory.
// .claude/commands/test-all.js
module.exports = {
name: 'test-all',
description: 'Run all tests and generate coverage report',
execute: async () => {
await runCommand('npm test -- --coverage')
await runCommand('npm run e2e')
}
}
Create short aliases for frequently used long commands.
// .claude/commands/aliases.js
module.exports = {
c: 'commit',
p: 'push',
ta: 'test-all',
dev: 'npm run dev'
}
Create batch commands that execute multiple operations.
// .claude/commands/deploy.js
module.exports = {
name: 'deploy',
description: 'Complete deployment process',
execute: async () => {
await runCommand('npm test')
await runCommand('npm run build')
await runCommand('npm run deploy:prod')
}
}
Support custom commands that accept parameters.
// .claude/commands/create-component.js
module.exports = {
name: 'create-component',
description: 'Create new component',
parameters: ['name', 'type'],
execute: async (name, type = 'functional') => {
// Generate component based on parameters
}
}
Commands that execute different operations based on conditions.
// .claude/commands/smart-test.js
module.exports = {
name: 'smart-test',
execute: async () => {
const files = await getChangedFiles()
if (files.some((f) => f.endsWith('.tsx'))) {
await runCommand('npm run test:components')
}
if (files.some((f) => f.includes('api/'))) {
await runCommand('npm run test:api')
}
}
}
Create interactive commands that require user input.
// .claude/commands/scaffold.js
module.exports = {
name: 'scaffold',
interactive: true,
execute: async () => {
const type = await prompt('Choose type: component/page/api')
const name = await prompt('Enter name:')
// Generate code based on input
}
}
Use terminal split screen functionality to view code and Claude Code output simultaneously.
# Horizontal split
Ctrl+b "
# Vertical split
Ctrl+b %
# Switch panes
Ctrl+b arrow keys
# Horizontal split
Cmd+D
# Vertical split
Cmd+Shift+D
# Switch panes
Cmd+Option+arrow keys
Set up dedicated workspaces for different types of tasks.
# Create frontend development workspace
claude --workspace frontend --dir ./src/components
# Create backend development workspace
claude --workspace backend --dir ./src/api
# Create testing workspace
claude --workspace testing --dir ./tests
Use session history to quickly restore previous work state.
# View session history
claude --history
# Resume specific session
claude --resume <session-id>
# Export session record
claude --export-session > session-backup.json
Deeply understand Claude Code's essence as a CLI tool and fully utilize command-line features.
Make good use of screenshot and image processing features to build visual feedback loops for accelerated development.
Connect databases, API documentation and other external resources to expand Claude Code's capabilities.
Create a project-specific environment through CLAUDE.md and custom commands.
Use split screen, workspaces, session management and other techniques to improve development efficiency.
💡 Tip: These 34 tips cover all aspects of Claude Code. It's recommended to first master the basic tips, then gradually apply advanced features based on project needs, ultimately forming your own efficient workflow.