claude::code

tool claude code AI assistant
Getting started CLAUDE.md Memory CLI flags Slash commands Keyboard Hooks Permissions Skills MCP Settings Built-in tools Models IDE Workflows Best practices
01Getting Started
Install & first run
curl -fsSL https://claude.ai/install.sh | bash
brew install --cask claude-code          # macOS
irm https://claude.ai/install.ps1 | iex  # Windows

# first session
cd your-project/
claude              # start interactive session
/init               # generate CLAUDE.md from codebase

# update
claude update
Tip: /init scans your codebase and creates a starter memory file with tech stack, conventions, and architecture.
Session basics
claude                    # interactive REPL
claude "explain this project"
claude -p "fix lint"       # print mode (one-shot)
cat err.log | claude -p "summarize"
claude -c                  # continue last conversation
claude -r my-session      # resume named session
Auth
claude auth login    # sign in
claude auth status   # check status
claude auth logout   # sign out
02Understanding CLAUDE.md
What to put in it

Persistent project instructions loaded automatically at start of every session.

Tech stackLanguages, frameworks, versions
Build cmdsnpm run dev, make test
ConventionsNaming, patterns, architecture
DesignDecisions & their rationale
WorkflowsPR process, deploy steps
Keep it < 200 lines. Ruthlessly prune. Bloated CLAUDE.md hurts more than it helps — Claude reads it every turn.
File hierarchy
Highest priority first
/etc/claude-code/CLAUDE.md   # Managed policy (enterprise)
~/.claude/CLAUDE.md          # User (all projects)
./CLAUDE.md                  # Project root (committed)
./.claude/CLAUDE.md          # Alt project location
./src/module/CLAUDE.md       # Nested (on-demand)
./.claude/rules/*.md         # Path-scoped rules
CLAUDE.md = instructions you write. Auto memory = notes Claude writes.
03Auto Memory System
Memory files
~/.claude/projects/<hash>/memory/
  MEMORY.md      # Index (first 200 lines loaded)
  *.md           # Individual memory files
Memory types
userRole, preferences, knowledge level
feedbackCorrections & confirmations on approach
projectOngoing work, goals, deadlines
referencePointers to external systems
Memory file format
---
name: memory-name
description: "one-line summary"
type: user|feedback|project|reference
---

Content goes here.
What NOT to save

Code patterns / architecture (derive from code)

Git history / who-changed-what (use git log)

Debugging solutions (fix is in the code)

Anything in CLAUDE.md already

Ephemeral task details

Save what's surprising. If the user asks to remember a PR list, ask what was non-obvious about it — that's worth keeping.
04CLI Flags & Options
Core & model
Core
claudeInteractive session
claude "query"Session with initial prompt
-p "query"Print mode (query & exit)
cat f | claude -pPipe content in
-cContinue last conversation
-r <id|name>Resume specific session
-n <name>Name current session

Model & behavior
--model <m>sonnet, opus, haiku, opusplan
--effort <e>low, medium, high, max
--output-formattext, json, stream-json
--max-turns <n>Limit agentic turns
--max-budget-usdSpending limit
Permissions & advanced
Permissions
--permission-modedefault, plan, auto, bypassPermissions
--allowedToolsPre-approve tools
--disallowedToolsBlock tools

Advanced
-w [name]Isolated git worktree
--add-dir <p>Add working directory
--mcp-config fLoad MCP servers from file
--bareSkip hooks, skills, MCP
--system-promptReplace system prompt
--append-system-promptAdd to system prompt
--debug [cat]Enable debug logging
05Slash Commands
Session & configuration
Session
/clearClear history (alias: /reset, /new)
/compact [msg]Compress conversation context
/resume [s]Resume previous session
/export [f]Export conversation
/rewindRestore previous checkpoint
/rename [n]Rename session
/branchFork conversation
/copy [N]Copy last response

Configuration
/model [m]Select model
/effort [e]Set effort level
/configOpen settings UI
/permissionView/update permissions
/memoryView/edit CLAUDE.md & auto memory
/initGenerate CLAUDE.md
/theme [c]Change color theme
/vimToggle vim editing mode
Tools, extensions & info
Tools & extensions
/mcpConfigure MCP servers
/hooksView hook configurations
/skillsList available skills
/agentsManage subagent configs
/ideManage IDE integrations
/chromeConfigure Chrome extension

Info & debug
/costShow token usage & costs
/statusVersion, model, account
/contextVisualize context usage
/doctorDiagnose installation
/diffView uncommitted changes
/debugEnable debug logging
/tasksList background tasks

Built-in skills
/simplifyReview recent changes for improvements
/batch <inst>Parallel refactoring (5-30 workers)
/loop [t] <p>Run prompt on recurring interval
/fastToggle fast output mode
06Keyboard Shortcuts
General & navigation
Ctrl+CCancel generation / input
Ctrl+DExit session
Ctrl+LClear terminal screen
Ctrl+OToggle verbose transcript
Ctrl+RSearch command history
Ctrl+GOpen external editor
Ctrl+VPaste image from clipboard
Ctrl+BBackground running tasks
Ctrl+TToggle task list
Mode switching & input
Mode switching
Shift+TabCycle permission modes
Alt+PSwitch model
Alt+TToggle extended thinking
Alt+OToggle fast mode
Esc EscRewind / summarize

Multiline input
\+EnterLine continuation (universal)
Opt+EntermacOS newline
Shift+EnteriTerm2, WezTerm, Ghostty, Kitty
Ctrl+JLine feed

Quick prefixes
/Command / skill menu
!Bash mode (execute directly)
@File path autocomplete
07Setting Up Hooks
Configuration & events

Deterministic shell commands that run at lifecycle events. Defined in settings.json.

{
  "hooks": {
    "PreToolUse": [{
      "matcher": "Edit|Write",
      "hooks": [{
        "type": "command",
        "command": "my-script.sh"
      }]
    }]
  }
}
Key events
PreToolUseBefore tool runs (can block)
PostToolUseAfter tool succeeds
NotificationAlerts (permission prompt, idle)
StopResponse finished
SessionStartSession begins or resumes
UserPromptSubmitBefore prompt processed
FileChangedWatched file modified
Exit codes & hook types
Exit codes
0Allow action (or inject context via stdout)
2Block action (stderr = reason shown to Claude)
otherAllow, log stderr as warning

Hook types
commandShell command (most common)
httpPOST to HTTP endpoint
promptSingle-turn LLM evaluation
agentMulti-turn agent verification
Example: Auto-format on save — matcher Edit|Write → command npx prettier --write $TOOL_INPUT_FILE
08Permissions & Safety
Permission modes
defaultPrompt for each action
planRead-only analysis
acceptEditsAuto-accept file changes
autoClassifier approves safe actions
bypassPermissionsSkip all prompts
Cycle modes live: Shift+Tab
Rules format
{
  "permissions": {
    "allow": [
      "Bash(git *)",
      "Bash(npm run *)",
      "Edit(/src/**/*.ts)",
      "WebFetch(domain:github.com)",
      "mcp__github__*"
    ],
    "deny": ["Bash(rm -rf *)"]
  }
}
Glob patterns work in paths. * matches any arguments. mcp__<server>__* allows all tools from an MCP server.
09Adding Skills (Custom Commands)
Create a skill

Skills = custom slash commands. Claude auto-invokes via natural language match on description.

Locations
~/.claude/skills/my-skill/SKILL.md     # user-level
.claude/skills/my-skill/SKILL.md      # project-level
SKILL.md frontmatter
---
name: my-skill
description: "What it does"
user-invocable: true
allowed-tools: "Read,Grep,Bash(git *)"
effort: high
model: opus
context: fork          # run in subagent
paths: "src/**/*.ts"   # auto-load for files
shell: bash            # bash or powershell
---

Instructions for the skill.
Use $ARGUMENTS for user input.
Key fields & dynamic context
Important frontmatter
descriptionCritical for auto-invocation matching
allowed-toolsPre-approved tools for the skill
context: forkRun in isolated subagent context
pathsAuto-load when matching files are open
user-invocableShow in / menu as slash command

Dynamic context in SKILL.md
## Live data
- Branch: !`git branch --show-current`
- Diff: !`git diff --stat`
- Status: !`git status -s`

Backtick commands in SKILL.md run at load time and inject output into the prompt.

10MCP Servers
Model Context Protocol

Connect external tools & services. Claude can call MCP tools like native tools.

Configuration
# In settings.json or .claude/mcp.json
{
  "mcpServers": {
    "github": {
      "type": "stdio",
      "command": "gh",
      "args": ["api-server"]
    },
    "remote": {
      "type": "http",
      "url": "https://mcp.example.com"
    }
  }
}
CLI management
claude mcpList configured servers
claude mcp add <n>Add server (interactive)
claude mcp remove <n>Remove server
/mcpManage in-session
Types: stdio (local process), http (remote), sse (streaming)
Settings files
Locations (highest priority first)
Managed/etc/claude-code/ (enterprise)
CLI flags--model, --effort (session override)
Local.claude/settings.local.json (gitignored)
Project.claude/settings.json (committed)
User~/.claude/settings.json (personal)

Minimal example
{
  "model": "opus",
  "effortLevel": "medium",
  "permissions": {
    "allow": ["Bash(git *)", "Edit"]
  },
  "hooks": { ... },
  "mcpServers": { ... },
  "env": { "DEBUG": "true" }
}
11Built-in Tools
Read-only (no permission needed)
ReadRead file contents (text, images, PDFs, notebooks)
GlobFind files by pattern (replaces find)
GrepSearch file contents with regex (replaces grep/rg)
LSPType errors, goto definition
Requires permission
File & web
BashExecute shell commands
EditTargeted string replacements in files
WriteCreate / overwrite files
WebFetchFetch content from URLs
WebSearchSearch the web
NotebookEditEdit Jupyter notebooks

Agentic
AgentSpawn subagent for parallel work
SkillExecute a skill
TaskCreateTrack progress on tasks
AskUserQuestionGather requirements (multi-choice)
12Model Selection
Model aliases & effort
Models
opusMost capable — Opus 4.6
sonnetBalanced — Sonnet 4.6
haikuFast & efficient — Haiku 4.5
opusplanOpus plans, Sonnet executes
sonnet[1m]Sonnet with 1M context window
defaultBest for your plan tier

Set model
claude --model opus       # at startup
/model opus               # during session
Alt+P                    # keyboard shortcut
Effort levels
/effort low|medium|high|max
# max = Opus 4.6 only, deepest reasoning
IDE integration
VS Code
Cmd+EscToggle focus editor / Claude
Opt+KInsert @mention for selection
Cmd+NNew conversation
Spark iconToolbar / sidebar / status bar

JetBrains
Cmd+EscFocus Claude terminal
Cmd+Opt+KShare file selection

Both IDEs support diff viewer, diagnostics sharing, and inline suggestions.

13Workflow Patterns
The 4-layer architecture
L1CLAUDE.md — persistent project knowledge
L2Skills — auto-invoked knowledge packs
L3Hooks — deterministic safety gates
L4Agents — subagents with own context

Recommended flow
cd project && claude
  # 1. Describe feature / intent
  # 2. Let Claude explore (Plan mode)
  # 3. Review & approve implementation
/compact    # if context fills up
/clear      # between unrelated tasks
Esc Esc     # rewind if wrong direction
Parallel & headless
Parallel execution
claude -w feature-auth   # isolated worktree 1
claude -w feature-ui     # isolated worktree 2
/batch "add tests to *"  # 5-30 parallel workers
CI / headless
claude -p "fix lint" --output-format json
cat err.log | claude -p "summarize"
claude -p "review" --max-turns 5
Effective prompts
# use structure for complex requests
Goal: exploit SSTI safely in local challenge
Context: Flask/Jinja app in ./src
Constraints: no external tools
Files: @src/app.py
Expected output: curl PoC + explanation
14Best Practices
Do
Keep CLAUDE.md under 200 lines
Use /clear between unrelated tasks
Give Claude tests to verify its work
Use @file to reference files
Use /compact when context fills
Use subagents for deep investigation
Use hooks for deterministic actions
Don't
Kitchen-sink sessions (do everything in one)
Over-correct (after 2 fails, /clear & reprompt)
Bloat CLAUDE.md with every detail
Skip verification — always provide checks
Unscoped exploration — limit or use subagents
Pro tips
• Ground prompts in files — better context = better output
• Copy-paste commands are drafts until tested
• Use Plan mode first, then switch to execute
Esc Esc to rewind wrong directions fast
• Name sessions with -n for easy resume