learning_ai_common_plat/AI.dev/CHEATSHEETS/claude-code-cli.md
saravanakumardb1 f0911e65ed docs(cheatsheets): add Devin/Claude/Codex CLI cheat sheets
New AI.dev/CHEATSHEETS/ reference set for delegating to terminal AI agents:
- README.md: comparison matrix, 'which CLI?' decision guide, official-docs links,
  cross-CLI rules + ByteLyst environment facts
- devin-cli.md: sessions, --permission-mode dangerous vs --sandbox, resume, the
  sandbox-stall gotcha, delegation pattern + prompt preamble
- claude-code-cli.md: REPL/-p/-c/--resume, permission+plan modes, slash commands, MCP
- codex-cli.md: interactive vs codex exec for CI, sandbox x approval matrix, config.toml

Flags hedged with 'confirm via --help' since they drift between versions; durable
value is the ByteLyst workflow. Does not reference .devin/config.local.json contents.
2026-05-28 19:42:07 -07:00

128 lines
5.8 KiB
Markdown

# 🟣 Claude Code CLI — Cheat Sheet
> **What it is:** Anthropic's **Claude Code** — an agentic coding tool that runs in your
> terminal, reads/edits files, runs commands, and pair-programs interactively.
> **Best for:** Deep, multi-file changes where you want to stay in the loop — reasoning
> through a refactor, debugging across modules, or building a feature with review at each step.
> **Per-repo rules:** reads `AGENTS.md` (canonical) and, if present, `CLAUDE.md`.
> ⚠️ **Flags/commands drift between versions.** Confirm with `claude --help` and
> `/help` inside a session.
>
> **Official docs:** <https://docs.anthropic.com/en/docs/claude-code>
---
## Install & auth
```bash
npm install -g @anthropic-ai/claude-code # or the documented installer
claude --version
claude # first run walks you through login
```
- Auth via Anthropic account (Pro/Max) or an `ANTHROPIC_API_KEY`.
- Config & history live under `~/.claude/`.
## Launching
```bash
claude # interactive REPL in the current dir
claude "explain src/server.ts and propose a refactor" # seed a first prompt
claude -p "list the failing tests" # print mode: one-shot, non-interactive
cat error.log | claude -p "what's the root cause?" # pipe context in
```
## Session management
```bash
claude -c # continue the most recent conversation
claude --resume # pick a past session to resume
claude --resume <id> "<prompt>" # resume a specific session with a new instruction
```
Inside a session, history is preserved; use `/clear` to reset context when switching tasks.
## Permission modes
| How | Effect |
| -------------------------------- | ------------------------------------------------------- |
| _(default)_ | Prompts before edits / commands |
| `--permission-mode acceptEdits` | Auto-accepts file edits, still gates commands |
| `--permission-mode plan` | **Plan mode** — proposes a plan, makes no changes |
| `--dangerously-skip-permissions` | Auto-approves **everything** (use only in a sandbox/VM) |
```bash
claude --permission-mode plan # safe: get a plan first, no edits
claude --dangerously-skip-permissions # full auto — only in throwaway/sandboxed env
```
> 🧠 Prefer **plan mode** for anything non-trivial: review the plan, then let it execute.
> Reserve `--dangerously-skip-permissions` for isolated environments (devcontainer/VM).
## Useful in-session slash commands
| Command | Purpose |
| --------------- | ------------------------------------------- |
| `/help` | List commands |
| `/clear` | Reset conversation context |
| `/init` | Generate/refresh a `CLAUDE.md` for the repo |
| `/review` | Review recent changes |
| `/model` | Switch model |
| `/agents` | Manage subagents |
| `/mcp` | Inspect/connect MCP servers |
| `#` (prefix) | Add a durable memory to `CLAUDE.md` |
| `@path/to/file` | Pull a file into context |
## Config files & memory
- **`AGENTS.md`** (repo root) — canonical agent rules; Claude reads it.
- **`CLAUDE.md`** — optional Claude-specific memory; `/init` scaffolds it, `#` appends to it.
- **`.claude/settings.json`** (repo or `~/.claude/`) — permissions, hooks, tools, MCP.
- **MCP servers** — connect tools/data via `claude mcp add ...` or `.mcp.json`.
## ByteLyst workflow
Open every delegation with the shared guardrails — Claude honors `AGENTS.md`, but
re-stating scope keeps it tight:
```text
Follow AGENTS.md + AI.dev/SKILLS/agent-behavior-guidelines.md.
Scope: <paths>. Tests are sacred; fix code, not tests.
Verify: pnpm --filter <pkg> typecheck && ... test && ... build (next build --webpack).
pnpm workspace; @bytelyst/* link via workspace:*. Conventional commits, one per logical change.
Use plan mode first for multi-file work; show the plan before editing.
```
- Use `/review` before committing a cluster of edits.
- For repo onboarding context, run `/init` once and commit the resulting `CLAUDE.md`
(keep it thin — it should point at `AGENTS.md`, not duplicate it).
## Troubleshooting
| Symptom | Fix |
| ---------------------------- | ------------------------------------------------------------------------------------- |
| Edits applied without asking | You're in `acceptEdits`/`--dangerously-skip-permissions`; switch to default or `plan` |
| Context bloated / confused | `/clear` and re-seed with `@` file references |
| Can't reach Gitea/registry | Corp proxy must be active (`NETWORK=corp`); workspace deps avoid the registry |
| Build fails on Turbopack | Use `next build --webpack` |
| Wants a tool it can't access | Wire it via MCP (`/mcp`, `claude mcp add`) |
## Quick-reference card
```text
claude # interactive
claude -p "..." # one-shot print mode
claude -c # continue last session
claude --resume # pick a session
claude --permission-mode plan # plan first, no edits
/init /clear /review /model /mcp #memory @file
```
---
**Related:** [`devin-cli.md`](./devin-cli.md) · [`codex-cli.md`](./codex-cli.md) ·
[`../PROMPTS/`](../PROMPTS/) · [`../SKILLS/agent-behavior-guidelines.md`](../SKILLS/agent-behavior-guidelines.md)
_Last updated: 2026-05-28 · verify flags against your installed version (`claude --help`)._