Tips & Tricks

Practical solutions from 115+ real sessions building with AI coding assistants. Every tip here solved an actual problem.

Claude CodeWindows

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.

# Instead of this (fails):
cd "G:\Shared drives\My Project"
# Use this (works):
claude --add-dir "G:\Shared drives\My Project"

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.

Claude CodeCxMS

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.

# In your .gitignore:
*.local.md
# Your file structure:
MyApp_Session.md # public template
MyApp_Session.local.md # your actual session (gitignored)

The AI reads both files identically. But .local.md files never leave your machine. Same directory, same naming convention, zero risk of accidental publication.

Claude CodeMulti-Session

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.

# Bad (shared, causes contamination):
.claude/context-status.json
# Good (per-session, isolated):
.claude/context-status-{session_id}.json

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.

Claude CodeHooks

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.

// Read stdin with 100ms timeout (won't hang on Windows)
function readStdinFast() {
return new Promise((resolve) => {
let data = "";
const timer = setTimeout(() => resolve(data), 100);
process.stdin.on("data", (chunk) => {
data += chunk;
clearTimeout(timer);
setTimeout(() => resolve(data), 50);
});
process.stdin.on("end", () => {
clearTimeout(timer);
resolve(data);
});
process.stdin.resume();
});
}

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.

CxMSWorkflow

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.

# What the PreCompact hook saves:
.claude/compaction-recovery.md
# Contains:
- Current task and progress
- Files recently edited (breadcrumbs)
- Uncommitted changes
- Active decisions and context

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.

Claude CodeCxMS

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.

# SessionStart hook creates:
.claude/startup-state.json
{ "complete": false, "required": ["Startup.md", "Session.md", "Tasks.md"] }
# PreToolUse hook checks:
if (!startupComplete && toolName !== "Read") {
return { "decision": "block", "reason": "Read startup files first" }
}

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