A debugging loop Claude can drive
- Gather evidenceerror, stack trace, logs, screenshot
- Reproducea failing test or command
- Find root causeone hypothesis at a time
- Fix + verifytest passes; nothing suppressed
test still fails → next hypothesis
Using Claude on a live problem
Anthropic’s account of its own teams gives two operational examples. The data infrastructure team feeds Claude Code dashboard screenshots and system documentation during incidents; the write-up describes it diagnosing a Kubernetes pod-scheduling problem, and spotting IP address exhaustion during an outage. The security engineering team feeds it stack traces and documentation, and reports diagnosing production issues about three times faster. The pattern is the same in both: Claude gets the evidence a human engineer would look at, not a one-line summary of the symptom.
Claude Code’s best-practices guide turns that into prompting rules. Describe the symptom, the likely location and what “fixed” looks like. Ask for a failing test that reproduces the issue before the fix. And, in its own words, address the root cause, don’t suppress the error. Evidence can come in several ways: pipe a log with cat error.log | claude, paste a screenshot, point Claude at the file, or let it pull context itself through a CLI such as sentry-cli or an MCP server connected to your monitoring tools.
An incident request, weak and strong
Symptom only
checkout is broken, fix it asapEvidence, scope, proof
since the 01:40 deploy, ~8% of
checkout calls return 500.
stack trace and 200 filtered log
lines attached. read-only: do not
change config or data. find the
root cause in payments-service,
write a failing test that
reproduces it, then propose the
fix. don't suppress the error.Keep the evidence from drowning the context
Logs are the classic way to wreck a debugging session. Claude Code’s cost guide gives the fix directly: rather than have Claude read a 10,000-line log, a hook can grep for ERROR and return only matching lines, cutting tens of thousands of tokens to hundreds. It also suggests delegating verbose work, such as running tests or processing log files, to a subagent, so only a summary reaches the main conversation. The troubleshooting page describes the failure when this goes wrong: an “autocompact is thrashing” error, where a file or tool output refills the context immediately after every compaction. Its recovery steps are to read the file in chunks, compact with a focus, move the work to a subagent, or clear.
When Claude Code itself misbehaves
The second half of this objective is supporting a team whose tooling isn’t behaving. Claude Code’s “Debug your configuration” page puts the usual cause plainly: the file didn’t load, it loaded from a different location than expected, or another file overrode it. So the first move is always to look at what actually loaded, not to edit more files.
| Symptom | Look first with | Common cause |
|---|---|---|
| Claude ignores a CLAUDE.md rule | /context, then /memory | File not loaded (subdirectory files load on demand), or the rule is vague, conflicting or buried in a long file |
| A setting doesn’t take effect | /status (setting sources) | Overridden by a higher scope or an environment variable; managed settings win |
| An MCP tool is missing | /mcp, then claude --debug=mcp | Project server never approved; relative path in command; .mcp.json inside .claude/ |
| A hook never fires | /hooks, then claude --debug | Matcher is an array, lowercase or misspelled; hooks in a standalone file |
| Something’s wrong, unsure what | /doctor, claude --safe-mode | A plugin, MCP server or hook; safe mode disables customisations to isolate it |
Isolating a misbehaving setup
claude --safe-mode?- No — it disappearsA customisationcheck
/context,/mcp,/hooks - Yes, and
/statusshows managedOrganisation policytalk to the admin - Yes, with a clean config dirInstall, auth or network
claude doctor, login docs - Can’t tell from outsideTurn on logging
/debugorclaude --debug
Operating Claude Code across a fleet
For a whole organisation, you need telemetry, not anecdotes. Claude Code exports OpenTelemetry metrics and events once CLAUDE_CODE_ENABLE_TELEMETRY is set with exporters and an endpoint, and administrators can push that configuration to every machine through the env block of managed settings. Metrics include claude_code.session.count, claude_code.token.usage, claude_code.cost.usage and claude_code.active_time.total. Events include claude_code.api_request, claude_code.api_error, claude_code.tool_result and claude_code.tool_decision, tied together by a prompt.id. A beta tracing mode adds spans for each interaction, model request and tool call, and passes a TRACEPARENT to Bash subprocesses.
{
"env": {
"CLAUDE_CODE_ENABLE_TELEMETRY": "1",
"OTEL_METRICS_EXPORTER": "otlp",
"OTEL_LOGS_EXPORTER": "otlp",
"OTEL_EXPORTER_OTLP_PROTOCOL": "grpc",
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://otel-collector.internal:4317"
}
}Cost spikes are the operational issue admins see most. The cost guide says unexpectedly high API spend usually traces back to long sessions that were never cleared, or to the most expensive model left as the default. It also lists quieter causes in long sessions: cache misses after breaks, scheduled tasks firing while idle, and compaction of a very large context. Individual developers can see attribution by skill, subagent, plugin and MCP server in /usage (/cost is an alias), and /insights reports friction patterns across recent sessions. Observability of Claude-powered products you build, as opposed to the developer tooling, is 3.4 and 4.6.
Traps the wrong answers are built from
| Tempting but wrong | Do this instead |
|---|---|
| Asking Claude to “fix it” with only a one-line symptom | Give the error, stack trace, recent change and what “fixed” means, and ask for a failing test first. |
| Letting Claude silence an error to make the build pass | Ask for the root cause explicitly and verify with a reproduction test. |
| Granting Claude write access to production during an incident | Investigate read-only in plan mode; a human approves and runs remediation. |
| Pasting entire logs into the conversation | Filter with a hook or CLI, or delegate log processing to a subagent that returns a summary. |
| Editing more config files when a rule or tool “doesn’t work” | Check what loaded with /context, /status, /mcp or /hooks, and isolate with --safe-mode. |
| Turning on full prompt and tool-content logging fleet-wide by default | Collect usage and cost metrics broadly; enable content logging only with a clear data-handling reason. |
You should now be able to
- Structure a debugging request around evidence, scope and a reproducible check.
- Keep large logs and test output out of the main context with hooks, CLIs or subagents.
- Bound Claude’s access during incidents with read-only tools, plan mode and human approval.
- Diagnose configuration problems with
/context,/status,/mcp,/hooks,/doctor,--debugand--safe-mode. - Deploy OpenTelemetry through managed settings and use its metrics and events to explain usage and cost.
- Trace a spend spike to a cause such as long sessions, model choice or a verbose tool.