Przejdź do głównej zawartości

Command Line Mastery: Tips 26-35

Ta treść nie jest jeszcze dostępna w Twoim języku.

The terminal interface is Claude Code’s primary interaction method, and mastering it transforms your development speed. These 10 tips cover essential commands, keyboard shortcuts, and productivity techniques that power users rely on daily.

Understanding Claude Code’s command structure enables fluid interaction:

Terminal window
# Start interactive session
claude
# Run one-time task
claude "implement user authentication with JWT"
# Quick query with immediate exit
claude -p "explain this regex: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/"
# Continue most recent conversation
claude -c
# Resume specific previous conversation
claude -r

Quick Reference

  • -p, --print: Run single prompt and exit (non-interactive)
  • -c, --continue: Continue last conversation
  • -r, --resume: Resume from history
  • -m, --model: Specify model to use
  • -v, --verbose: Show debug information
  • --add-dir: Include additional directories

Slash commands provide quick access to Claude Code’s features:

Essential Slash Commands:
/help - Show all available commands and usage
/init - Initialize project with CLAUDE.md
/review - Request comprehensive code review
/clear - Clear conversation history
/config - View or modify configuration
/status - View account and system status
/memory - Edit CLAUDE.md memory files
/permissions - Manage tool permissions
/cost - Check token usage and costs
/compact - Compress conversation history
/add-dir - Add directory to workspace
/hooks - Configure automation hooks
/terminal-setup - Configure terminal settings
/ide - Connect to IDE for diagnostics
/install-github-app - Enable GitHub integration

Custom command examples:

Terminal window
# Create custom test command
echo 'Generate comprehensive tests for: $ARGUMENTS' > .claude/commands/test.md
# Use it
/test UserService.js
# Create deployment command
echo 'Deploy to staging following our process: $ARGUMENTS' > .claude/commands/deploy-staging.md
# Use it
/deploy-staging --version 2.1.0

One of the most impactful habits for Claude Code efficiency:

Terminal window
# Clear at the start of each new task
/clear
# Why this matters:
# 1. Saves tokens (no history to process)
# 2. Prevents context confusion
# 3. Avoids compaction overhead
# 4. Faster response times
# 5. Cleaner mental model

When to Clear

  • Starting a new feature
  • Switching between different parts of codebase
  • After completing a task
  • When context becomes confused
  • Before complex architectural discussions

Best practices for context management:

Terminal window
# Good workflow
claude
/clear
# Work on authentication feature
# Complete authentication
/clear
# Work on payment integration
# Complete payment integration
# Bad workflow
claude
# Work on authentication
# Work on payment without clearing
# Work on UI without clearing
# Context becomes muddled

Claude Code maintains comprehensive history across sessions:

Terminal window
# Navigate with arrow keys
# Previous command
# Next command
# Access full history
claude -r
# Shows numbered list of previous conversations
# Jump to specific conversation
claude -r 5
# Resumes conversation #5
# Search history
claude --history | grep "authentication"
# Find all conversations about authentication
Terminal window
# During a session
# Go back through prompts
Escape Escape # Show message list
5 # Jump to message 5
# Between sessions
claude -r # List all sessions
claude -r 12 # Resume session 12
claude -c # Continue last session

Efficient file referencing is crucial for providing context:

  1. Using @ mentions

    Refactor @UserService.js to use dependency injection
    Update @components/Button.tsx to support dark mode
  2. Drag and drop with Shift

    • Normal drag: Opens file in new tab
    • Shift + drag: References file in Claude Code
  3. Glob patterns

    Review all test files: @**/*.test.js
    Update all React components: @components/**/*.tsx
  4. Multiple file references

    Ensure consistency between @User.model.js, @user.service.js, and @user.controller.js

Claude Code excels at understanding intent without specific syntax:

Instead of memorizing commands, just describe what you want:
"Fix the bug in user authentication"
"Add comprehensive tests for the payment module"
"Refactor this function to be more readable"
"Help me understand how the caching layer works"
"Create a new feature for exporting data to CSV"
"Review my code for security vulnerabilities"
"Optimize this query that's running slowly"
"Update the documentation for the API endpoints"

Natural Language Patterns

Claude Code understands:

  • Technical descriptions
  • Colloquial requests
  • Partial information
  • Context from previous messages
  • Implied requirements
  • Domain-specific terminology

Examples of natural language understanding:

Terminal window
# Vague request → Claude asks clarifying questions
"Make this faster"
> I see you want to improve performance. Could you specify:
> 1. Which part is slow?
> 2. What's the current performance?
> 3. What's your target?
# Context-aware request
"Do the same thing for the product service"
> I'll apply the same dependency injection pattern I used
> for UserService to the ProductService
# Implicit requirements
"Make this production ready"
> I'll add:
> - Error handling
> - Input validation
> - Logging
> - Tests
> - Documentation

Claude Code provides sophisticated git integration:

Terminal window
# Status and changes
"What files have I changed?"
"Show me the git diff"
"What's on the staging area?"
# Committing
"Commit my changes with a descriptive message"
"Create a commit following conventional commits"
"Amend the last commit"
# Branches
"Create a new branch called feature/user-auth"
"Switch to the main branch"
"Show me all branches"

Essential keyboard shortcuts for productivity:

Universal Shortcuts:
- Escape - Stop current operation (not exit)
- Escape Escape - Show message navigation
- Tab - Command/file completion
- Shift+Enter - New line in prompt (after setup)
- Ctrl+C - Exit Claude Code
- Ctrl+L - Clear screen
- Ctrl+R - Search command history
File Operations:
- Ctrl+V - Paste image (not Cmd+V on Mac)
- Shift+Drag - Reference file (not open)
Navigation:
- ↑/↓ - Navigate command history
- Page Up/Down - Scroll through output
- Home/End - Jump to start/end
Special:
- # - Quick CLAUDE.md update
- / - Start slash command
- @ - Start file reference

Platform Differences

  • macOS: Use Ctrl for special functions, not Cmd
  • Windows/Linux: Standard Ctrl shortcuts work
  • Terminal app: May need to configure key bindings

Tip 34: Use One-Shot Commands for Quick Tasks

Section titled “Tip 34: Use One-Shot Commands for Quick Tasks”

Perfect for automation and quick operations:

Terminal window
# Quick formatting
claude "format this SQL query" < query.sql > formatted.sql
# Code review
claude "review this PR for security issues" < pr.diff
# Documentation generation
claude "generate JSDoc comments" < utils.js > documented.js
# Batch operations
for file in *.js; do
claude "add error handling" < "$file" > "safe_$file"
done
# Pipeline integration
git diff | claude -p "explain these changes" | tee explanation.md
# Automated testing
claude "write tests for this function" < service.js > service.test.js

Integration examples:

.git/hooks/pre-commit
# Git hooks
files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.js$')
for file in $files; do
claude "check for console.log statements" < "$file"
done
# CI/CD pipeline
# .github/workflows/review.yml
- name: Claude Review
run: |
claude "review for performance issues" < src/

Extend Claude Code with project-specific commands:

  1. Create command directory

    Terminal window
    mkdir -p .claude/commands
  2. Create command file

    .claude/commands/feature.md
    Create a new feature with our standard structure:
    Feature name: $ARGUMENTS
    1. Create feature branch
    2. Set up folder structure:
    - /features/$ARGUMENTS/
    - /features/$ARGUMENTS/components/
    - /features/$ARGUMENTS/hooks/
    - /features/$ARGUMENTS/tests/
    3. Create index files with exports
    4. Add to main router
    5. Create basic test setup
  3. Use the command

    Terminal window
    /feature user-profile
  4. Create nested commands

    .claude/commands/db/migrate.md
    mkdir -p .claude/commands/db
    # Now use: /db/migrate

Advanced command examples:

.claude/commands/review.md
Perform comprehensive code review:
- Security vulnerabilities
- Performance issues
- Code style violations
- Missing tests
- Documentation gaps
Focus on: $ARGUMENTS
# .claude/commands/refactor.md
Refactor following our patterns:
- Extract constants
- Add type safety
- Improve naming
- Reduce complexity
- Add error handling
Target: $ARGUMENTS
# .claude/commands/test/integration.md
Create integration tests for: $ARGUMENTS
- Use our test utilities
- Mock external services
- Test error scenarios
- Verify response format

Command Best Practices

  • Keep commands focused and specific
  • Use $ARGUMENTS for flexibility
  • Include context and requirements
  • Version control command files
  • Share useful commands with team

Combining these command-line techniques creates a powerful workflow:

Terminal window
# Start fresh
claude --dangerously-skip-permissions
/clear
# Set up workspace
/add-dir ../shared
/add-dir ../backend
# Quick task
"Create user authentication with JWT"
# Review and test
/review
"Add comprehensive tests"
# Natural git workflow
"Commit these changes"
"Create a PR"
# Jump to previous work
Escape Escape
3 # Jump to message about database schema
# Quick check
/cost # Monitor token usage
# Continue tomorrow
claude -c # Pick up where you left off

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.