lookupBoundTask returns the task whose session_id matches $CLAUDE_CODE_SESSION_ID, or nil if no such task exists, the env var is unset, or the DB lookup fails. Hook code must never fail loud — a hook error blocks the user's session — so all errors are swallowed and treated as "unbound".
()
| 122 | // hook error blocks the user's session — so all errors are swallowed |
| 123 | // and treated as "unbound". |
| 124 | func lookupBoundTask() *flowdb.Task { |
| 125 | sid := currentSessionID() |
| 126 | if sid == "" { |
| 127 | return nil |
| 128 | } |
| 129 | dbPath, err := flowDBPath() |
| 130 | if err != nil { |
| 131 | return nil |
| 132 | } |
| 133 | db, err := flowdb.OpenDB(dbPath) |
| 134 | if err != nil { |
| 135 | return nil |
| 136 | } |
| 137 | defer db.Close() |
| 138 | t, err := flowdb.TaskBySessionID(db, sid) |
| 139 | if err != nil { |
| 140 | return nil |
| 141 | } |
| 142 | return t |
| 143 | } |
| 144 | |
| 145 | // lookupBoundTaskSlug returns the slug of the bound task, or "" if the |
| 146 | // session is unbound. Thin wrapper over lookupBoundTask. |
no test coverage detected