mateaix/mateclaw/python-debugpy
Claude Code and agent skill by mateaix/mateclaw
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
Debug Python: pdb REPL + debugpy remote (DAP).
Install
npx vskill@latest install mateaix/mateclaw/python-debugpySemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as mateaix/mateclaw/python-debugpy.
Python Debugger (pdb + debugpy)
Overview
Three tools, picked by situation:
| Tool | When | |
|---|---|---|
| `breakpoint()` + pdb | Local, interactive, simplest. Add breakpoint() in the source, run normally, get a REPL at that line. | |
| `python -m pdb` | Launch an existing script under pdb with no source edits. Useful for quick poking. | |
| `debugpy` | Remote / headless / "attach to already-running process." Talks DAP, scriptable from terminal, works for long-lived processes (gateway, daemon, PTY children). |
Start with `breakpoint()`. It's the cheapest thing that works.
When to Use
- A test fails and the traceback doesn't reveal why a value is wrong
- You need to step through a function and watch a collection mutate
- A long-running process (the agent gateway, tui_gateway) misbehaves and you can't restart it
- Post-mortem: an exception fired in prod-ish code and you want to inspect locals at the crash site
- A subprocess / child (Python
_SlashWorker, PTY bridge worker) is the actual bug site
Don't use for: things print() / logging.debug solve in under a minute, or things pytest -vv --tb=long --showlocals already reveals.
pdb Quick Reference
Inside any pdb prompt ((Pdb)):
| Command | Action | |
|---|---|---|
h / h cmd | help | |
n | next line (step over) | |
s | step into | |
r | return from current function | |
c | continue | |
unt N | continue until line N | |
j N | jump to line N (same function only) | |
l / ll | list source around current line / full function | |
w | where (stack trace) | |
u / d | move up / down in the stack | |
a | print args of the current function | |
p expr / pp expr | print / pretty-print expression | |
display expr | auto-print expr on every stop | |
b file:line | set breakpoint | |
b func | break on function entry | |
b file:line, cond | conditional breakpoint | |
cl N | clear breakpoint N | |
tbreak file:line | one-shot breakpoint | |
!stmt | execute arbitrary Python (assignments included) | |
interact | drop into full Python REPL in current scope (Ctrl+D to exit) | |
q | quit |
The interact command is the most powerful — you can import anything, inspect complex objects, even call methods that mutate state. Locals are read-only by default; use !x = 42 from the (Pdb) prompt to mutate.
Recipe 1: Local breakpoint
Easiest. Edit the file:
Run the code normally. You land at the breakpoint() line with full access to locals.
Don't forget to remove `breakpoint()` before committing. Use git diff or a pre-commit grep:
Recipe 2: Launch a script under pdb (no source edits)
Recipe 3: Debug a pytest test
The the agent test runner and pytest both support this:
Note: scripts/run_tests.sh uses xdist (-n 4) by default, and pdb does NOT work under xdist. Add -p no:xdist or run a single test with -n 0:
This bypasses the hermetic-env guarantees — fine for debugging, but re-run under the wrapper to confirm before pushing.
Recipe 4: Post-mortem on any exception
Or wrap a whole script:
Or set a global hook in a repl/jupyter:
Recipe 5: Remote debug with debugpy (attach to running process)
For long-lived processes: the agent gateway, tui_gateway, a daemon, a process that's already misbehaving and can't be restarted clean.
Setup
Pattern A: Source-edit — process waits for debugger at launch
Add near the top of the entry point (or inside the function you want to debug):
Start the process; it blocks on wait_for_client().
Pattern B: No source edit — launch with -m debugpy
Equivalent for module entry:
Pattern C: Attach to an already-running process
Needs the PID and debugpy preinstalled in the target's environment:
Some kernels/security configs block the ptrace-based injection (/proc/sys/kernel/yama/ptrace_scope). Fix with:
Connecting a client from the terminal
The easiest terminal-side DAP client is VS Code CLI or a small script. From inside the agent you have two practical options:
Option 1: `debugpy`'s own CLI REPL — not an official feature, but a tiny DAP client script:
This is fine for one-off automation but painful as an interactive UX.
Option 2: Attach from VS Code / Cursor / Zed — if the user has one open, they can add a launch.json:
Option 3: Ditch DAP, use `remote-pdb` — usually what you actually want from a terminal agent:
In your code:
Then from the terminal:
remote-pdb is the cleanest agent-friendly choice when debugpy's DAP protocol is overkill. Use debugpy only when you actually need IDE integration.
Debugging the agent-specific Processes
Tests
See Recipe 3. Always add -p no:xdist or run single tests without xdist.
run_agent.py / CLI — one-shot
Easiest: add breakpoint() near the suspect line, then run the agent normally. Control returns to your terminal at the pause point.
tui_gateway subprocess (spawned by the agent --tui)
The gateway runs as a child of the Node TUI. Options:
A. Source-edit the gateway:
Start the agent --tui. The TUI will appear frozen (its backend is waiting). Attach a client; execution resumes when you continue.
B. Use `remote-pdb` at a specific handler:
Trigger the matching slash command from the TUI, then nc 127.0.0.1 4444 in another terminal.
_SlashWorker subprocess
Same pattern — remote-pdb with set_trace() inside the worker's exec path. The worker is persistent across slash commands, so the first trigger blocks until you connect; subsequent slash commands pass through normally unless you re-arm.
Gateway (gateway/run.py)
Long-lived. Use remote-pdb at a handler, or debugpy with --wait-for-client if you're restarting the gateway anyway.
Common Pitfalls
- pdb under pytest-xdist silently does nothing. You won't see the prompt, the test just hangs. Always use
-p no:xdistor-n 0.
- `breakpoint()` in CI / non-TTY contexts hangs the process. Safe locally; never commit it. Add a pre-commit grep as a safety net.
- `PYTHONBREAKPOINT=0` disables all
breakpoint()calls. Check the env if your breakpoint isn't hitting:
``bash echo $PYTHONBREAKPOINT ``
- `debugpy.listen` blocks only if you also call `wait_for_client()`. Without it, execution continues and your first breakpoint may fire before the client is attached.
- Attach to PID fails on hardened kernels.
ptrace_scope=1(Ubuntu default) allows only same-user ptrace of child processes. Workaround:echo 0 > /proc/sys/kernel/yama/ptrace_scope(needs root) or launch underdebugpyfrom the start.
- Threads.
pdbonly debugs the current thread. For multithreaded code, usedebugpy(thread-aware DAP) or setthreading.settrace()per thread.
- asyncio.
pdbworks in coroutines butawaitinside pdb requires Python 3.13+ orawaitfrominteractmode on older versions. For 3.11/3.12, useasyncio.run_coroutine_threadsafetricks or!stmt-based awaits viaasyncio.ensure_future.
- `scripts/run_tests.sh` strips credentials and sets `HOME=<tmpdir>`. If your bug depends on user config or real API keys, it won't reproduce under the wrapper. Debug with raw
pytestfirst to repro, then re-confirm under the wrapper.
- Forking / multiprocessing. pdb does not follow forks. Each child needs its own
breakpoint()orset_trace(). For the agent subagents, debug one process at a time.
Verification Checklist
- [ ] After
pip install debugpy, confirm:python -c "import debugpy; print(debugpy.__version__)" - [ ] For remote debug, confirm the port is actually listening:
ss -tlnp | grep 5678 - [ ] First breakpoint actually hits (if it doesn't, you likely have
PYTHONBREAKPOINT=0, you're under xdist, or execution finished before attach) - [ ]
where/wshows the expected call stack - [ ] Post-debug cleanup: no stray
breakpoint()/set_trace()in committed code
``bash rg -n 'breakpoint\(\)|set_trace\(|debugpy\.listen' --type py ``
One-Shot Recipes
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingmateclaw-server/src/main/resources/skills/python-debugpy/SKILL.md
Popularity
- Repository stars
- 1,147
- Repository forks
- 337
- 7-day trend score
- 40
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/mateaix/mateclaw/python-debugpy)