openclaw attach CLI Reference: Launch Claude Code with Scoped MCP Grant

This page covers the openclaw attach command for launching Claude Code with a temporary, scoped Gateway MCP grant. Developers integrating Claude Code with Gateway sessions should review the available flags and configuration options.

Read this when

  • You want Claude Code to use OpenClaw Gateway MCP tools
  • You need a temporary session-bound MCP grant for an external harness

openclaw attach starts Claude Code with a strict temporary MCP configuration tied to a single Gateway session.

openclaw attach
openclaw attach --session agent:main:telegram:123 --ttl 600000
openclaw attach --print-config

Available flags:

  • --session <key> associates the grant with a specific Gateway session. The main session is used by default.
  • --ttl <ms> sets a desired grant lifetime in milliseconds. The Gateway enforces its own maximum limit.
  • --bin <path> chooses which Claude Code binary to use. Falls back to claude.
  • --print-config creates the temporary .mcp.json, outputs the launch command and environment variables, and keeps the grant active until its TTL expires (without starting Claude Code or invalidating the grant).

The bearer token is delivered through environment variables rather than command arguments. OpenClaw starts Claude Code with --strict-mcp-config --mcp-config <path> to prevent ambient Claude MCP servers from connecting to the attached session. Standard launches (without --print-config) remove the grant once the Claude Code process terminates.

Related documentation: Gateway CLI, MCP CLI, and ACP CLI.