启动参数看官方文档将调试日志写入指定文件路径Syntax--debug-file <path>示例claude --debug-file /tmp/claude-debug.log全网调研整理典型场景调试 MCP server 连接失败:将完整握手日志写入文件后离线分析CI/CD 流水线中用 -p 非交互模式运行时,保留调试产物供事后排查对比 interactive 模式与 -p headless 模式的行为差异时,各自生成独立日志文件生成可附加到 GitHub Issue / 支持工单的调试文件,而非截图滚动的终端长时间 session 中用 tail -f 实时跟踪日志,同时保留完整记录实用技巧该 flag 同时隐式开启 debug 模式,无需再加 --debug,一个 flag 两用搭配 CLAUDE_CODE_DEBUG_LOG_LEVEL=info 可大幅缩减日志体积,过滤掉低级 verbose 噪音与 -p 组合使用最典型:claude -p "fix build" --debug-file /tmp/ci-debug.log若只想改日志路径而不开 debug,用环境变量 CLAUDE_CODE_DEBUG_LOGS_DIR 代替此 flag(但需另行启用 debug 模式)不指定该 flag 时,debug 模式日志默认写入 ~/.claude/debug/<session-id>.txt,可作为事后回溯入口常见坑单独设置 CLAUDE_CODE_DEBUG_LOGS_DIR 不会自动开启 debug 模式,必须同时加 --debug 或 session 内 /debug 才能写入日志隐式开启 debug 模式会增加 I/O 开销并产生大量输出,生产环境长时间运行需注意磁盘用量DEBUG=1 环境变量同样能开启 debug 模式但官方文档未记载,行为可能在版本间变化,不建议依赖来源CLI reference - Claude Code DocsClaude Code: 10 CLI flags you probably aren't using - mager.coShow HN: I built a tool to un-dumb Claude Code's CLI output | Hacker News[DOCS] Document that DEBUG environment variable enables debug mode · Issue #59223 · anthropics/claude-codeclaude-code-best-practice/claude-cli-startup-flags.md · shanraisshan回到命令字典