fix: session cost from stdin and delegation hook bypass#39
Conversation
Review Summary by QodoFix session cost from stdin and delegation hook subagent deadlock
WalkthroughsDescription• Replace broken daily cost calculation with session cost from stdin JSON - Removed 445 lines of JSONL self-calculation code (9 functions, background refresh, cache files) - Added 5-line read of cost.total_cost_usd from stdin — accurate, zero I/O • Harden delegation hook to prevent subagent deadlocks - Expanded subagent detection to check three env vars: CLAUDE_PARENT_SESSION_ID, CLAUDE_AGENT_ID, CLAUDE_SCRATCHPAD_DIR - Added redundant safety net inside main() rechecking subagent env vars - Normalized CLAUDE_PROJECT_DIR path resolution with Path.resolve() • Bump version to 1.15.2 and update changelog Diagramflowchart LR
A["Old: JSONL cost calculation<br/>9 functions, cache, background refresh"] -->|"Remove 445 lines"| B["New: stdin session cost<br/>5-line read from cost.total_cost_usd"]
C["Subagent detection<br/>CLAUDE_PARENT_SESSION_ID only"] -->|"Expand to 3 env vars"| D["Enhanced bypass<br/>+ CLAUDE_AGENT_ID<br/>+ CLAUDE_SCRATCHPAD_DIR"]
D -->|"Add safety net"| E["Redundant check in main()"]
F["Path resolution<br/>CLAUDE_PROJECT_DIR"] -->|"Normalize with resolve()"| G["Symlink-safe path handling"]
File Changes1. hooks/PreToolUse/require_delegation.py
|
Code Review by Qodo
1.
|
Summary
Cost Display
cost.total_cost_usdfrom stdin JSON — accurate, zero I/O_find_todays_session_files()used file mtime, picking up old sessions touched today and summing their entire history ($1505 instead of actual daily cost)Delegation Hook
CLAUDE_PARENT_SESSION_ID,CLAUDE_AGENT_ID,CLAUDE_SCRATCHPAD_DIR)get_state_dir()now usesPath.resolve()to normalize symlinks when checkingdelegation_activeflagmain()rechecking subagent env varsTest plan
🤖 Generated with Claude Code