MeshWorld India LogoMeshWorld.
AICheatsheetClaude CodeCLIDeveloper Tools8 min read

Claude Code CLI Cheatsheet (2026 Edition)

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

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. As developers, having a local, terminal-first autonomous coding companion drastically speeds up debugging, documentation, and routine refactoring.

To use Claude Code efficiently, you must master session commands, command line flags, and local context files. Below is the complete, fact-checked guide to mastering the Claude Code CLI.

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.

How Do You Install and Launch Claude Code?

To install and launch Claude Code, run npm install -g @anthropic-ai/claude-code in your terminal to install the package globally, followed by the claude login command to authenticate your session via the browser. Once authenticated, run the claude command in the root of your project directory to open the interactive REPL.

Here are the basic commands for installation, authentication, and launch:

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

# Authenticate your terminal with Anthropic Console (opens browser)
claude login

# Launch the interactive REPL in the current directory
claude

# Run a single task and return directly to your terminal shell
claude -p "Find all instances of 'any' in src/ and replace with proper types"

What Are the Essential Interactive REPL Commands?

The essential interactive REPL commands inside Claude Code include /help to display all commands, /compact to condense long chats and save token window space, and /clear to wipe the active session context entirely. These commands are typed directly inside the active > claude terminal prompt to manage the agent’s behavior.

Below is the complete reference of slash commands for interactive sessions:

CommandActionDeveloper Description
/helpShows all available slash commandsLists every debugging and configuration command.
/initAuto-generates a baseline CLAUDE.mdScans the local folder structure to initialize coding instructions.
/clearWipes the current context windowWipes previous messages to start fresh, saving token costs.
/compactCondenses the current conversationSummarizes previous steps to free up context window space.
/historyView previous CLI sessionsDisplays a timeline of command usage across this project.
/modelSwitch active modelToggles between default reasoning models.
/configManage local CLI settingsConfigures approval rules, billing alerts, and network pathways.
/doctorRun diagnostic checksVerifies your Node version, git installations, and API reachability.
/costView token usage and costsDisplays session metrics to avoid unexpected API billing.
/exitQuit the active REPLSafely closes the REPL session and returns to normal bash.

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?

You manage context in Claude Code by creating a CLAUDE.md file in the root of your project directory, which the CLI automatically reads on boot to ingest local rules, coding standards, and build commands. This prevents you from repeating core instructions and system boundaries in every session prompt.

Here is a standard template for a CLAUDE.md file designed for modern projects:

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`
- Types Check: `bun x tsc --noEmit`

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

You use CLI flags and non-interactive scripts in Claude Code by appending parameters like —danger-require-approval to enforce user confirmation before running commands, or using —print to pipe markdown outputs directly to local files. This allows you to integrate Claude Code into standard Unix shell pipelines and automated scripting jobs.

Below is a reference of essential CLI flags for script automation:

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?

The best autonomous agent workflows in Claude Code involve executing test-driven loops, analyzing git commit histories, and generating automated project documentation. Because Claude Code can run terminal tools, you can instruct it to write code, test it, read the errors, and iteratively fix the code until the tests pass.

Here are three highly effective prompts for automated workflows:

1. The Test-Driven Debugger

“Write a unit test for the calculateTax function inside tests/tax.test.ts. Run bun test. If it fails, examine the logic inside src/utils/tax.ts and modify it until all test cases pass cleanly.”

2. The Git Archaeologist

“Scan the recent git commit logs using git tools. Find the commit that broke the UserAvatar component. Look at the diffs, check out the previous working files if needed, and tell me who changed it and the technical explanation for the bug.”

3. The Auto-Documentation Writer

“Read all exported files inside the src/utils/ directory. Generate a Markdown table documenting every exported helper function, its input parameter signatures, and return types. Save the resulting summary table to docs/UTILS.md.”


Managing Tool Approvals and Sandbox Safety

One of the biggest concerns with terminal-native agents is safety. By default, Claude Code runs inside your user shell space, meaning it has the permissions of the logged-in user. If you give it a prompt like “Clean up my dependencies,” it could theoretically run a script that alters files outside your repository.

To mitigate this, you should configure your default approval boundaries using the /config REPL command or launch the CLI with explicit tool restriction flags. For example:

  • --danger-require-approval: Recommended when running Claude Code in untrusted projects or when using experimental dependencies.
  • --allowed-tools: Limits the tools Claude can access. If you only want it to suggest changes but not run tests or install packages, pass --allowed-tools "ViewFile,ReplaceContent".

If you are looking to integrate other developer tools, check out our comparison between Cursor and Claude Code, learn how to run local models with our guide to Ollama and Gemma 4, or optimize your local installation speeds using our walkthrough on Fixing Slow Torrent Speeds.


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.

Does Claude Code support custom configurations?

Yes, typing /config inside the REPL allows you to toggle settings such as verbose mode, default tools approval thresholds, billing alerts, and customized formatting options.

What should I do when my context window runs out of memory?

Type /compact to condense the history of the conversation while keeping the active state, or use /clear to start a fresh thread with a completely clean token memory.


If you’re looking for more ways to occupy your screen time, optimize your setup, or keep your digital life secure, check out these guides:

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