Claude Code CLI, permission modes and agentic workflows
Learn Claude Code CLI commands, permission modes (default, acceptEdits, plan, bypassPermissions), MCP server integrations, and terminal-to-desktop workflows.
Claude Code is Anthropic's official agentic development tool, operating in developer environments via terminal CLI (claude), desktop applications, and integrated mobile interfaces. It enables Claude to autonomously navigate directory trees, inspect codebases, edit files, execute tests and terminal commands, and manage multi-step engineering workflows with configurable permission guardrails and context persistence.
Key concepts
CLI Commands and Flags
Claude Code is invoked via claude in the terminal. Key flags include --permission-mode <mode> (default, acceptEdits, plan, bypassPermissions), --dangerously-skip-permissions for fully autonomous mode (use with caution), --print for non-interactive output, --resume to continue a previous session, and --model to select a specific model. Slash commands like /compact, /clear, /config, and /help provide in-session controls. The claude --help command shows all available options.
CLAUDE.md Context Files
CLAUDE.md files provide persistent context to Claude Code sessions. Place a CLAUDE.md in your project root to define coding conventions, architecture notes, preferred libraries, and workflow instructions. Claude reads this file at session start, ensuring consistent behavior across sessions. Use it to document project-specific patterns, testing requirements, and code review standards.
Permission Modes
Claude Code provides four documented permission modes to balance autonomy with security: (1) default (prompts the user before executing file edits, bash commands, or destructive actions); (2) acceptEdits (automatically approves file read, write, and patch operations while still prompting for confirmation before running terminal shell commands); (3) plan (restricts the agent to read-only analysis and architectural planning without modifying files or executing side effects); (4) bypassPermissions (disables interactive confirmations for fully autonomous execution—equivalent to --dangerously-skip-permissions—and must only be used in isolated sandboxes or containers). Configure via claude --permission-mode acceptEdits or in configuration files.
MCP (Model Context Protocol) Servers
MCP servers extend Claude Code's capabilities by exposing external tools and data sources. Configure MCP servers in your settings to connect to databases, APIs, file systems, or custom tools. Each server provides tools that Claude can invoke during agentic loops. Popular MCP servers include filesystem access, PostgreSQL connections, web scraping tools, and Git operations. MCP follows a standardized JSON-RPC protocol.
Agentic Loops and Tool Use
Claude Code operates in agentic loops: it plans, executes tools, observes results, and iterates. Tools available include file read/write, shell command execution, and MCP-provided tools. Claude decides which tools to use based on your prompt and context. It can chain multiple operations-reading files, analyzing code, making edits, and running tests-all in a single session without manual intervention.
Hooks and Automation
Hooks allow you to trigger automated actions at specific points in Claude Code's workflow. Pre-tool hooks run before a tool executes, enabling validation or modification of inputs. Post-tool hooks run after completion, useful for logging, notifications, or cleanup. Hooks are configured in settings and can call external scripts or APIs. Use hooks to enforce coding standards, run linters automatically, or integrate with CI/CD pipelines.
Context Management and /compact
Claude Code maintains a conversation context that grows as the session progresses. Use /compact to summarize and condense the context, retaining key information while reducing token usage. This is essential for long sessions. The --resume flag lets you continue previous sessions, and context is persisted across restarts. Strategic use of /clear and /compact keeps sessions responsive.
Session Persistence and History
Claude Code saves session state, allowing you to resume work after interruptions. Use claude --resume to pick up where you left off. Session history is stored locally and includes conversation, file states, and tool outputs. You can also export sessions for sharing or documentation. This persistence enables iterative development over days, not just single sessions.
Worked examples
Example 1
You want Claude Code to automatically apply file edits without prompting for confirmation on each file write, while still prompting before running arbitrary bash/shell commands. What permission mode and command-line flag should you configure?
Solution
Step 1: Identify Claude Code's permission architecture.
Claude Code provides four documented permission modes: default (prompts for approvals), acceptEdits (auto-accepts file edits and creation while prompting for bash commands), plan (disallows edits and execution for read-only planning), and bypassPermissions (bypasses all approval prompts).
Step 2: Match the requirement.
The mode that automatically applies file edits while retaining prompt confirmations for shell execution is acceptEdits.
Step 3: CLI invocation.
Pass --permission-mode acceptEdits (or configure "permissionMode": "acceptEdits" in ~/.claude.json / project configuration).
Answer: Set --permission-mode acceptEdits.
Example 2
Your project has specific coding conventions (use tabs, prefer named exports, no console.log in production). How do you ensure Claude Code follows these consistently across all sessions?
Solution
Step 1: Create a CLAUDE.md file in the project root directory.
Step 2: Document the coding conventions clearly:
# Project Conventions
- Use tabs for indentation
- Prefer named exports over default exports
- No console.log statements in production code
- Run `npm test` after each changeStep 3: Claude Code reads this file automatically at session start.
Answer: Place coding conventions in a CLAUDE.md file at the project root-Claude reads it each session and follows the documented patterns.
Example 3
You're working on a long-running Claude Code session that has accumulated many messages. The response quality is degrading due to context bloat. How do you reduce context size without losing important information?
Solution
Step 1: Identify the problem-context window is filling with irrelevant or repetitive history.
Step 2: Use the /compact slash command to summarize the session.
Step 3: /compact condenses the conversation, retaining key decisions and file states while removing verbose outputs.
Step 4: Alternatively, use /clear to reset if you want to start fresh.
Answer: Use the /compact command during the session to summarize and condense context, or use /clear to reset entirely. For future sessions, use --resume to continue from a compacted state.
Example 4
You need Claude Code to connect to a PostgreSQL database and query data as part of an agentic workflow. What mechanism enables this external tool integration?
Solution
Step 1: Claude Code needs external tool access beyond its built-in file/shell capabilities.
Step 2: MCP (Model Context Protocol) servers provide this extensibility.
Step 3: Configure a PostgreSQL MCP server in Claude Code settings.
Step 4: Once configured, Claude can invoke the MCP server's tools to run queries.
Answer: Use an MCP (Model Context Protocol) server for PostgreSQL. Configure it in settings, and Claude Code can invoke the server's tools to execute database queries during agentic loops.
Representative solved questions
See the kind of question in this topic before opening the full practice set.
Question 1
What is the purpose of the --output-format flag in Claude Code?
Answer: D. To specify structured output formats like JSON for parsing Claude's responses programmatically
ExplanationStep 1: Structured output is valuable for automation.
Step 2: --output-format json forces Claude to return valid JSON.
Step 3: This enables integration with scripts and other tools.
Answer: Specify structured output formats like JSON for programmatic parsing.
Sources and review notes
This is an AISEA-authored practice question.
Review status: accepted · Reviewed 2026-08-13 · structure and answer-key checks, editorial quality checks, duplicate screening
Question 2
A developer wants Claude Code to automatically commit changes after completing a task. Which approach is recommended?
Answer: C. Use a post-edit hook that runs 'git add -A && git commit -m "Automated by Claude"'
ExplanationStep 1: Hooks are the recommended way to add custom automation.
Step 2: A post-edit hook can trigger git commands after file changes.
Step 3: This provides flexibility without requiring built-in features.
Answer: Use a post-edit hook running git commands.
Sources and review notes
This is an AISEA-authored practice question.
Review status: accepted · Reviewed 2026-08-13 · structure and answer-key checks, editorial quality checks, duplicate screening
Question 3
When using MCP servers, how does Claude Code discover available tools?
Answer: C. MCP servers expose a tools/list endpoint that Claude queries to discover available capabilities
ExplanationStep 1: MCP follows a standardized protocol for tool discovery.
Step 2: Servers implement tools/list which returns available tool definitions.
Step 3: Claude automatically queries this on connection.
Answer: MCP servers expose a tools/list endpoint for capability discovery.
Sources and review notes
This is an AISEA-authored practice question.
Review status: accepted · Reviewed 2026-08-13 · structure and answer-key checks, editorial quality checks, duplicate screening
Common mistakes and useful habits
- Start with the default permission mode until you are familiar with the codebase, then use `--permission-mode acceptEdits` for rapid automated file changes while keeping shell safety. Reserve `bypassPermissions` for isolated containerized environments.
- Keep CLAUDE.md focused and concise-include only conventions, patterns, and instructions that Claude can act on. Long context files dilute signal and waste tokens.
- Use `/compact` proactively every 20-30 turns in long sessions to maintain response quality and keep context relevant.
- Configure hooks to run linters (ESLint, Pylint) automatically after file edits-this catches issues early and maintains code quality without manual intervention.
- When debugging complex issues, use `--resume` to continue from a previous session rather than re-explaining the problem. Claude retains the investigation context.
- MCP servers are powerful but add complexity. Start with the built-in tools (file read/write, shell commands), then add MCP servers only when you need capabilities like database access or API integration.
Sources and review notes
Reviewed by AISEA Editorial Desk on 7 Nov 2026.
- Updated permission mode architecture to match official Anthropic Claude Code documentation (default, acceptEdits, plan, bypassPermissions).
- Corrected CLI flag syntax to --permission-mode acceptEdits.
- Added multi-surface coverage spanning terminal CLI, desktop app, and mobile interfaces.
- Claude Code CLI Reference & Permission ModesAnthropic · Checked 7 Nov 2026Supports: permission mode flags, acceptEdits mode, and CLI options
- Model Context Protocol SpecificationAnthropic · Checked 7 Nov 2026Supports: MCP JSON-RPC tools and client-server architecture
Ready to test your understanding?
Work through 105 questions with explanations after each answer.