CertSafari
    Anthropic Claude Certified Developer – Foundations (CCDV-F) - December 7 onwards· Lessons

    Domain 3 · Lesson 8/24

    Claude Code surfaces, sessions and headless mode

    Claude Code Operation

    9 min read
    4% of exam
    6 sources
    Published 18 Nov 2026
    Docs as of 18 Nov 2026

    What you will be able to do

    • Move a session between Claude Code surfaces and know what changes on each
    • Pick the right built-in command to reset, compact, branch, or rewind a session
    • Run Claude Code non-interactively with -p, chain runs by session ID, and choose an output format

    1.One agent, several surfaces

    Claude Code is the same agent wherever you run it. It reads your codebase, edits files, and runs commands, and you can drive it from the terminal, an IDE extension (VS Code or JetBrains), the Desktop app, or a browser. A session started on one surface can continue on another. /desktop hands the current terminal session to the Desktop app. /mobile shows a QR code for installing the Claude mobile app, which can reach a running session through Remote Control.

    The surfaces differ mainly in how you change modes and which settings they read. The CLI uses Shift+Tab, VS Code has a mode indicator, and Desktop has a mode selector. VS Code doesn't read project settings when choosing its starting permission mode. Cloud sessions on the web and mobile differ the most. Their mode dropdown offers only Accept edits, Plan, and Auto, and Bypass permissions isn't available there. Cloud sessions pre-approve file edits, which is why the dropdown shows Accept edits where other surfaces show Manual. Of all the managed-settings sources, only server-managed settings reach a cloud session, so policy delivered by an MDM file covers developer machines and not the cloud.

    How the main surfaces differ for operation
    SurfaceSwitch mode withNotable difference
    CLI (terminal)Shift+TabdontAsk is never in the cycle; set it with --permission-mode dontAsk
    VS CodeMode indicatorDoesn't read project settings for the starting permission mode
    DesktopMode selectorBypass permissions needs a Desktop setting or organization policy
    Web and mobile (cloud sessions)Mode dropdownOnly Accept edits, Plan, and Auto; only server-managed settings apply

    Checkpoint 1 of 4· Check yourself

    An organization uses an MDM-deployed managed-settings.json to deny Bash(curl:*) on developer laptops. Developers are starting to run Claude Code sessions on the web. What makes that same block apply in those cloud sessions?

    Sources1234

    2.Managing a session from the prompt

    Built-in commands are how you control a session's state, and the commands that sound alike do different things. /context draws current context usage as a grid and points out what is using the most space. /compact [instructions] summarizes the conversation and keeps it going, and the optional instructions tell it what to focus the summary on. /clear throws the context away and starts a new conversation. The old conversation is not deleted, and /resume can reopen it. Context strategy for long sessions is covered in context management.

    Commands that change session state
    CommandWhat it does
    /clear [name]New conversation with empty context; the old one stays available in /resume
    /compact [instructions]Summarizes the conversation so far to free context, and the conversation continues
    /contextShows context usage as a colored grid with optimization suggestions
    /branch [name]Branches the conversation at this point and switches you into the branch
    /fork [prompt]Copies the conversation into a new background session while you keep working here
    /model [model]Switches the model and saves it as your default for new sessions

    Checkpoints let you undo Claude's work. Every prompt that starts a turn creates one. From /rewind, you can restore the code and the conversation together, restore only the conversation and keep the current files, restore only the files and keep the conversation, or summarize part of the conversation. Checkpoints are saved with the conversation, so a session you resume later can still rewind. Snapshots are deleted by the retention sweep, about 30 days after a session last saved one, unless you raise cleanupPeriodDays.

    Changing models in the middle of a session costs something. /model with no argument opens a picker. Pressing s on a row switches for the current session only, and otherwise the choice becomes your default. Each model has its own prompt cache, so the first request after a switch re-reads the whole conversation without caching. A model set in managed settings is only a starting default. Organizations restrict which models can be chosen with availableModels and deniedModels.

    Checkpoint 2 of 4· Check yourself

    Midway through a debugging task you ran /clear to get a fresh context. Now you realize you need the reasoning Claude worked out in that earlier conversation. What should you do?

    Sources254

    3.Headless runs with claude -p

    claude -p "<prompt>" runs a single non-interactive turn and exits, which suits scripts, pipes, and CI. You can pipe input in, for example cat build-error.txt | claude -p '...', and redirect the output to a file. A -p run starts in default permission mode, and nobody is there to answer a prompt. Approvals therefore have to be arranged in advance with --allowedTools, --permission-mode acceptEdits, dontAsk, or auto. Wiring this into a pipeline is covered in SDLC integration.

    Each -p run is a session, and later runs can continue it. --continue picks up the most recent conversation. --resume with a session ID continues a specific one. Pinning the session ID is the safer choice when several jobs run at once, because "most recent" may belong to a different job.

    Chaining headless runs with --continue, or by a captured session ID with --resumebash
    # First request
    claude -p "Review this codebase for performance issues"
    
    # Continue the most recent conversation
    claude -p "Now focus on the database queries" --continue
    claude -p "Generate a summary of all issues found" --continue
    
    session_id=$(claude -p "Start a review" --output-format json | jq -r '.session_id')
    claude -p "Continue that review" --resume "$session_id"

    --output-format controls the shape of the result. text is the default and returns plain text. json returns a single object with result, the session ID, and metadata. stream-json emits newline-delimited events as the run progresses. Combined with --verbose --include-partial-messages, those events include text deltas you can display as they arrive. If you add --json-schema, the validated object appears under .structured_output in the JSON result. Parsing that output defensively is covered in structured output.

    Most commands still work in -p. Put /skill-name in the prompt string and Claude Code expands it before the run starts. Commands such as /model sonnet, /effort, and /config key=value take their values as arguments. In -p, /model doesn't save the choice as your default. Commands that need the terminal interface, such as /login, are not available. --bare skips loading local configuration, so only what you pass on the command line, such as --mcp-config or --settings, is in effect.

    Checkpoint 3 of 4· Fill the gap

    Two CI jobs can run at the same time, so the script records the session ID and passes it to the follow-up run. Which flag completes the last line?

    # First request
    claude -p "Review this codebase for performance issues"
    
    # Continue the most recent conversation
    claude -p "Now focus on the database queries" --continue
    claude -p "Generate a summary of all issues found" --continue
    
    session_id=$(claude -p "Start a review" --output-format json | jq -r '.session_id')
    claude -p "Continue that review"  ?  "$session_id"

    Checkpoint 4 of 4· Check yourself

    A CI step runs claude -p and pipes the output to jq, which reads the result text and the session ID from one JSON object. Which --output-format value produces that object?

    Sources63

    Practise it for real

    Run Claude Code headlessly, capture its session ID, and continue the same session in a second run.

    1. 1.In a project folder, run: claude -p "Start a review" --output-format json

      Why: JSON output includes the session ID along with the result.

      You should see: A single JSON object containing result and session_id fields.

    2. 2.Run: session_id=$(claude -p "Start a review" --output-format json | jq -r '.session_id')

      Why: Saving the ID lets you continue this exact session even if other sessions start in between.

      You should see: The shell variable holds a session ID string.

    3. 3.Run: claude -p "Continue that review" --resume "$session_id"

      Why: --resume continues the named session, unlike --continue, which takes whichever conversation is most recent.

      You should see: The reply builds on the earlier review instead of starting from nothing.

    4. 4.Run: claude -p "Explain recursion" --output-format stream-json --verbose --include-partial-messages

      Why: Shows the event stream a UI or log consumer would read as the run progresses.

      You should see: Newline-delimited JSON events, including text deltas, printed as they arrive.

    Stuck? Get a nudge

    If the second run seems to have no memory of the first, check that $session_id isn't empty. jq needs the JSON output format to find the field.

    Sources

    (6)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Available in your terminal, IDE, desktop app, and browser.”
      ↩︎ One agent, several surfaces
    2. 2.
      “Continue the current session in the Claude Code Desktop app”
      ↩︎ One agent, several surfaces
      “Free up context by summarizing the conversation so far.”
      ↩︎ Managing a session from the prompt
      “Visualize current context usage as a colored grid.”
      ↩︎ Managing a session from the prompt
      “Start a new conversation with empty context.”
      ↩︎ Exam trap 1
      “To free up context while continuing the same conversation, use /compact instead.”
      ↩︎ Prediction
      “To free up context while continuing the same conversation, use /compact instead. Resume the previous conversation with /resume”
      ↩︎ Checkpoint
    3. 3.
      “Cloud sessions: Accept edits, Plan, and Auto.”
      ↩︎ One agent, several surfaces
      “claude -p or the Agent SDK | default”
      ↩︎ Headless runs with claude -p
    4. 4.
      “Only server-managed settings reach the cloud session”
      ↩︎ One agent, several surfaces
      “Each model has its own prompt cache, so the first request after a switch re-reads the whole conversation uncached”
      ↩︎ Managing a session from the prompt
    5. 5.
      “Every prompt you send that starts a turn creates a new checkpoint”
      ↩︎ Managing a session from the prompt
      “Claude Code saves checkpoints with the conversation, so you can still run /rewind after you resume a session”
      ↩︎ Managing a session from the prompt
    6. 6.
      “json: structured JSON with result, session ID, and metadata”
      ↩︎ Headless runs with claude -p
      “stream-json: newline-delimited JSON for real-time streaming”
      ↩︎ Headless runs with claude -p
      “Include /skill-name in the prompt string and Claude Code expands it before running.”
      ↩︎ Headless runs with claude -p
      “Built-in commands that only run in the terminal interface, such as /login, aren’t available.”
      ↩︎ Exam trap 2

    Ready to test yourself?

    Practise Anthropic Claude Certified Developer – Foundations (CCDV-F) - December 7 onwards in quiz mode.

    Spotted a mistake, or was something unclear? Tell us.