MeshWorld India LogoMeshWorld.
AICheatsheetClaude CodeCLIDeveloper Tools5 min read

Claude Code CLI Cheatsheet (2026 Edition)

Vishnu
By Vishnu
|Updated: Jul 23, 2026
Claude Code CLI Cheatsheet (2026 Edition)

Key Takeaways

  • Install with npm install -g @anthropic-ai/claude-code, then authenticate via claude login.
  • Run claude for interactive REPL or claude -p 'prompt' for non-interactive execution.
  • Auto-generate project context with /init to populate CLAUDE.md.
  • Manage context size using /compact to condense threads and /clear to reset token windows.
  • Configure permission boundaries with --allowed-tools and --danger-require-approval.

Anthropic’s claude-code CLI is the definitive tool for developers who hate leaving their terminal. Unlike IDE plugins that fight for sidebar space, Claude Code runs directly in your shell, executing git commands, reading files, and running your test suite natively.

TL;DR
  • Install: npm install -g @anthropic-ai/claude-code, then claude login
  • Launch REPL: claude — one-shot: claude -p "prompt"
  • Use /compact to save context window space during long sessions
  • Create CLAUDE.md in project root for persistent context
  • Use --danger-require-approval when you want confirmation before running commands

Here is the no-nonsense cheatsheet for surviving and thriving with Claude Code in 2026.

How Do You Install and Launch Claude Code?

bash
# Global installation (requires Node 20+)
npm install -g @anthropic-ai/claude-code

# Authenticate (opens browser)
claude login

# Launch the interactive REPL in the current directory
claude

# Run a single command without entering the REPL
claude -p "Find all instances of 'any' in src/ and replace with proper types"

What Are the Essential Interactive REPL Commands?

Once you are inside the > claude REPL, you aren’t just typing prompts; you have access to specific slash commands to manage the session.

CommandAction
/helpShows all available slash commands.
/initScans repository structure and auto-generates a baseline CLAUDE.md.
/clearWipes the current context window (crucial for long sessions).
/compactCondenses the current conversation to save token space.
/historyView previous interactions in this project.
/modelSwitch between claude-3-7-sonnet (default coding) and claude-3-opus.
/configManage local CLI settings and permission preferences.
/doctorRun diagnostic checks on Node environment and API connectivity.
/costView the token usage and estimated cost of the current session.
/exitQuit the CLI.

The Scenario: You’ve been debugging a messy Next.js routing issue for an hour. The REPL is lagging, and Claude is starting to suggest weird, unrelated changes to your database. Your context window is full of garbage. You type /compact. Claude condenses the 50-message thread into a 500-word state, freeing up 90% of your context window so you can finally fix the bug without restarting entirely.

How Do You Manage Context with CLAUDE.md?

The biggest mistake beginners make is pasting the same rules into the CLI every day.

Create a CLAUDE.md file in the root of your project. The CLI reads this file automatically every time it boots up in that directory.

Example CLAUDE.md:

markdown
# Project Context
This is a Next.js 15 App Router project using Tailwind CSS and Drizzle ORM.

## Coding Standards
1. Use Server Components by default.
2. Only use `'use client'` if `useState` or `useEffect` is required.
3. Use Lucide React for all icons.

## Build Commands
- Dev server: `bun run dev`
- Tests: `bun test`
- Lint: `bun run lint`

How Do You Use CLI Flags and Non-Interactive Scripts?

If you use the -p (prompt) flag, you can pass contextual flags to restrict, guide, or automate the agent.

bash
# Force the agent to ask for permission before running ANY terminal command
claude -p "Install the stripe SDK and wire it up" --danger-require-approval

# Pass specific files into context before the prompt
claude -f src/api/stripe.ts -p "Add error handling to this webhook"

# Non-interactive script mode: print response to stdout and pipe to file
claude -p "Audit src/auth.ts for security vulnerabilities" --print > audit.md

# Restrict allowed tool executions explicitly
claude -p "Refactor components" --allowed-tools "ViewFile,ReplaceContent"

# Ignore certain directories (overrides .gitignore)
claude --ignore "tests/**/*.ts" -p "Refactor the auth flow"

What Are the Best Autonomous Agent Workflows?

Claude Code shines when you let it run tasks autonomously.

The “Test-Driven” Loop:

“Write a test for the calculateTax function. Run bun test. If it fails, fix the function until the test passes.”

The “Git Archaeologist”:

“Find the commit that broke the UserAvatar component. Look at the git log, checkout the files, and tell me who changed it and why.”

The “Documentation Writer”:

“Read the entire src/utils/ directory. Generate a Markdown table documenting every exported function, its parameters, and its return type. Save it to UTILS.md.”

Frequently Asked Questions

What is the difference between CLAUDE.md and system prompts?

CLAUDE.md provides local, project-level rules (like build commands and linter rules) that are automatically ingested by the Claude Code CLI upon launch. System prompts are lower-level instructions passed directly to the Anthropic API.

How do I control tool execution permissions in script pipelines?

Use --danger-require-approval to enforce interactive user prompts before any shell execution, or pass --allowed-tools to restrict the agent to specific read/write operations.


Found this useful? Check out our Claude API Cheatsheet for SDK details, Gemma 4 Local Setup for running AI locally, and Cursor vs. Claude Code comparison.

Share_This Twitter / X
Vishnu
Written By

Vishnu

Founder & Principal Architect at MeshWorld. Senior engineer and instructor specializing in AI agent systems, scalable web architecture, and modern development workflows.

Enjoyed this article?

Support MeshWorld and help us create more technical content