# CLI Tips

This guide compiles 34 practical Claude Code tips, from basic operations to advanced features, helping you maximize Claude Code's potential.

## Basic Operations

### 1. Tab Autocomplete for File Paths

Press `Tab` after typing `@` to autocomplete file paths—no need to remember full paths.

### 2. Use @ to Reference Files Precisely

```
> Analyze security in @src/utils/auth.ts
> Compare @v1/api.js with @v2/api.js
```

Direct file references are more accurate than describing file locations.

### 3. Pipe Input for Analysis

```bash
git diff | claude "explain these changes"
cat error.log | claude "analyze error causes"
npm test 2>&1 | claude "analyze test failures"
```

### 4. Keyboard Shortcuts

| Shortcut | Function |
|----------|----------|
| `Tab` | Autocomplete file paths |
| `Esc` | Interrupt current output |
| `Ctrl+C` | Cancel current operation |
| `↑` / `↓` | Browse command history |
| `Shift+Tab` (twice) | Enter plan mode |
| `Alt+Tab` / `Option+Tab` | Toggle thinking mode |

### 5. Use ! for Quick Commands

Prefix with `!` to execute shell commands directly:

```
> !git status
> !npm run build
```

## Slash Commands

### 6. /help - View All Commands

```
> /help
```

Shows all available slash commands and shortcuts.

### 7. /clear - Clear Conversation

```
> /clear
```

Clear context before starting new tasks to avoid interference from previous conversations.

### 8. /compact - Compress History

```
> /compact
```

Use when context gets too long—compresses history to save tokens while keeping core information.

### 9. /context - Check Context Usage

```
> /context
```

Shows current context usage percentage. Consider compacting or starting a new session at 60%.

### 10. /model - Switch Models

```
> /model opus
> /model sonnet
```

- **Opus 4.7 / 4.6**: Complex tasks, architecture design, difficult problems (4.7 is current flagship)

- **Sonnet 4.6**: Daily coding, quick iterations (cost-effective)

### 11. /memory - Edit Project Memory

```
> /memory
```

Opens CLAUDE.md file for editing project standards and preferences.

### 12. /init - Initialize Project Config

```
> /init
```

Let Claude analyze your project and generate a CLAUDE.md configuration file.

### 13. /commit - Smart Commit

```
> /commit
```

Automatically analyzes changes, generates proper commit messages, and commits.

### 14. /review - Code Review

```
> /review
```

Reviews current changes for potential issues.

### 15. /resume - Resume Session

```
> /resume
```

Resume a previous conversation session to continue unfinished work.

## Context Management

Claude Code has a ~200K token context limit. Keep one session focused on one task, use `/context` to monitor usage, `/compact` to compress history, and `/clear` to start fresh.

For detailed context management strategies (including long-session overflow handling) → [Context Management](/docs/usage/context-management)

## Plan Mode

### 19. Enter Plan Mode

Press `Shift+Tab` twice to enter plan mode. Claude will research and create plans without modifying code.

### 20. Plan Before Execute

For complex tasks, have Claude create a plan first:

```
> Analyze this feature requirement and create an implementation plan, don't write code yet
```

Confirm the plan before execution to reduce rework.

### 21. Execute Complex Tasks Step by Step

Break large tasks into smaller steps:

```
> Step 1: Analyze the existing auth system
> Step 2: Design the new JWT approach
> Step 3: Implement core functionality
> Step 4: Add tests
```

## Subagents

### 22. Use Explore Agent for Fast Search

The Explore agent specializes in fast codebase searches:

```
> Use the Explore agent to find all payment handling code
```

### 23. Use Plan Agent for Design

The Plan agent specializes in implementation planning:

```
> Use the Plan agent to design the user permission system
```

### 24. Background Agents for Parallel Tasks

Launch multiple background agents to process tasks in parallel for better efficiency.

## CLAUDE.md Configuration

`CLAUDE.md` is a project-level config file that Claude reads automatically on startup. Use `/init` to generate one, or create it manually. Define code standards, common commands, and project architecture to avoid repeating yourself every session.

Full configuration guide with examples → [CLAUDE.md Configuration](/docs/usage/claude-md)

## Git Workflow

### 28. Smart Commit Messages

```
> /commit
```

Claude analyzes all changes and generates proper commit messages.

### 29. Create PR Descriptions

```
> Create a PR description for the current branch
```

Automatically generates PR descriptions with change summary and test plan.

### 30. Analyze PR Changes

```bash
gh pr diff 123 | claude "review this PR"
```

## Testing & Debugging

### 31. Have Claude Write Tests

```
> Write unit tests for @src/services/UserService.ts
```

Let Claude write tests to verify its own code correctness.

### 32. Analyze Test Failures

```bash
npm test 2>&1 | claude "analyze failures and fix"
```

### 33. Debug Errors

```
> Analyze this error: [paste error message]
> Debug the issue in @src/pages/Login.tsx
```

## Advanced Tips

### 34. Use Screenshots/Images

Claude Code supports image understanding:

```
> Look at this screenshot @screenshot.png and analyze UI issues
```

## Efficiency Comparison

| Scenario | Traditional | Claude Code |
|----------|-------------|-------------|
| Find code | grep + manual browsing | `@file` or Explore agent |
| Write tests | Manual + debugging | `/review` + auto-generate |
| Git commit | Think message + write | `/commit` one-click |
| Code review | Line-by-line review | `/review` smart analysis |
| Understand code | Read docs + read code | Just ask Claude |

## Best Practices Summary

1. **Be specific**: Clearly describe requirements with constraints

2. **Use references**: Use `@` to specify files, avoid guessing

3. **Step by step**: Break complex tasks into smaller steps

4. **Interrupt early**: Press `Esc` immediately if output is wrong

5. **Stay focused**: One session for one task

6. **Compact regularly**: Use `/compact` when context gets long

7. **Plan first**: Create plans before complex tasks

8. **Let AI test**: Have Claude write tests to verify its code

## Next Steps

- Learn [Workflow Tips](/docs/usage/workflow-tips) for efficient development processes

- Explore [Context Management](/docs/usage/context-management) for long-session and token overflow handling

- Set up [CLAUDE.md Configuration](/docs/usage/claude-md) to customize Claude's behavior for your project

- Check out [Codex Integration](/docs/ide/codex) to use another AI tool