{"record":{"id":"0917e01e162ee5e7","repo":"charmbracelet/crush","slug":"cannot-continue-an-agent-tool-session-s","errorCode":null,"errorMessage":"cannot continue an agent tool session: %s","messagePattern":"cannot continue an agent tool session: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/app/app.go","lineNumber":242,"sourceCode":"\n// ReportCurrentSession tells herdr which session the user is now\n// viewing so it can persist a resumable reference for the pane. Safe\n// to call when not running inside a herdr pane; the underlying client\n// is nil-safe. Call this whenever the active session changes (load,\n// new, or select).\nfunc (app *App) ReportCurrentSession(sessionID string) {\n\tapp.herdrClient.SetSessionID(sessionID)\n}\n\n// resolveSession resolves which session to use for a non-interactive run\n// If continueSessionID is set, it looks up that session by ID\n// If useLast is set, it returns the most recently updated top-level session\n// Otherwise, it creates a new session\nfunc (app *App) resolveSession(ctx context.Context, continueSessionID string, useLast bool) (session.Session, error) {\n\tswitch {\n\tcase continueSessionID != \"\":\n\t\tif app.Sessions.IsAgentToolSession(continueSessionID) {\n\t\t\treturn session.Session{}, fmt.Errorf(\"cannot continue an agent tool session: %s\", continueSessionID)\n\t\t}\n\t\tsess, err := app.Sessions.Get(ctx, continueSessionID)\n\t\tif err != nil {\n\t\t\treturn session.Session{}, fmt.Errorf(\"session not found: %s\", continueSessionID)\n\t\t}\n\t\tif sess.ParentSessionID != \"\" {\n\t\t\treturn session.Session{}, fmt.Errorf(\"cannot continue a child session: %s\", continueSessionID)\n\t\t}\n\t\treturn sess, nil\n\n\tcase useLast:\n\t\tsess, err := app.Sessions.GetLast(ctx)\n\t\tif err != nil {\n\t\t\treturn session.Session{}, fmt.Errorf(\"no sessions found to continue\")\n\t\t}\n\t\treturn sess, nil\n\n\tdefault:","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/app/app.go#L224-L260","documentation":"resolveSession rejects --continue/--session targeting a session created by the agent (task) tool. Sub-sessions spawned via the agent tool are internal worker sessions and are not valid continuation roots, so continuing them is blocked by design.","triggerScenarios":"Calling RunNonInteractive (or the CLI equivalent) with continueSessionID set to a session ID that IsAgentToolSession reports as an agent-tool-created session — e.g. copying a sub-agent's session ID from the UI or DB.","commonSituations":"Users grabbing an internal sub-agent session ID from logs/database; scripts that enumerate all sessions and pick the latest, accidentally selecting an agent-tool session.","solutions":["Use the top-level (parent) session ID instead of the agent-tool sub-session ID.","If scripting, filter sessions to those where IsAgentToolSession(id) is false before choosing one.","Start a new session if the intent was to resume work not tied to a top-level conversation."],"exampleFix":"// before\napp.RunNonInteractive(ctx, \"abc123-agent-subsesson-id\", prompt, quiet)\n\n// after\nif app.Sessions.IsAgentToolSession(id) {\n    id = parentSessionID // resolve to the top-level session\n}\napp.RunNonInteractive(ctx, id, prompt, quiet)","handlingStrategy":"validation","validationCode":"if app.Sessions.IsAgentToolSession(sessionID) {\n    return fmt.Errorf(\"%s is an agent-tool session; use its parent instead\", sessionID)\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.HasPrefix(err.Error(), \"cannot continue an agent tool session\") {\n        // resolve and retry with the parent session ID\n    }\n    return err\n}","preventionTips":["Only pass session IDs obtained from top-level conversation creation.","When enumerating sessions programmatically, skip those where IsAgentToolSession(id) is true.","Do not copy sub-agent session IDs from logs into --continue flags."],"tags":["go","session","agent","cli"],"backgroundTag":"invalid-session-resume","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}