Tips & Tricks
Practical solutions from 115+ real sessions building with AI coding assistants. Every tip here solved an actual problem.
Access Google Drive and Virtual Drives with --add-dir
Claude Code can't cd into virtual drives like Google Drive (G:\) or mapped network drives. The shell simply can't reach them. But you can still give Claude full access.
The --add-dir flag mounts the directory into Claude's working context without needing to change into it. Works with any path the OS can resolve but the shell can't navigate to directly.
Use .local.md for Confidential Files Alongside Public Templates
Need to keep confidential content (patents, financials, client data) in the same repo structure as your public templates? Use the .local.md suffix.
The AI reads both files identically. But .local.md files never leave your machine. Same directory, same naming convention, zero risk of accidental publication.
Prevent Concurrent Session Contamination with Per-Session State Files
Running two Claude Code sessions on the same project? They'll share state files and corrupt each other's context tracking. The fix: include the session ID in your state file names.
CxMS v2.0.5+ does this automatically via hooks. If you're building custom hooks, read the session ID from stdin in your SessionStart hook and use it to namespace all state files. Clean them up in your SessionEnd hook.
Read Session ID from stdin in Hooks (Windows-Safe)
Claude Code passes a JSON object to hooks via stdin, including the session ID. But on Windows, reading stdin can hang if the pipe is empty. Use a fast-resolve pattern with a timeout.
Resolves on first chunk with a 50ms settle time, or after 100ms if stdin is empty. Parse the result as JSON to get session_id, tool_name, and other hook context.
Survive Context Compaction with Automatic Recovery Files
Claude Code automatically compacts your conversation when context gets too long. Without preparation, you lose your working state. CxMS hooks write a recovery file before compaction happens.
After compaction, the SessionStart hook detects the recovery file and tells the AI to read it. Your new context picks up where the old one left off. We've ridden through dozens of compactions without losing work.
Enforce Startup File Reading with a PreToolUse Gate
The AI says it will read your context files. Then it doesn't. Or it reads one and skips the rest. The fix: block all non-Read tools until the required files are confirmed read.
PostToolUse tracks which files have been read. Once all required files are confirmed, the gate opens and the AI can use all tools normally. No more skipped context files.
More tips added as we discover them. Building with AI is a daily learning process.
Have a tip? Email opencxms@proton.me