aaif-goose/goose · error
AGENT_SESSION_ID not set. Initialize terminal integration wi
Error message
AGENT_SESSION_ID not set. Initialize terminal integration with `goose term init <shell>` and reload your shell first.
What it means
`goose term log` records a command in the session bound to the current terminal. That binding is the AGENT_SESSION_ID environment variable, exported by the shell-integration script emitted by `goose term init <shell>`. If the variable is absent — shell never sourced the script, or the command runs outside an integrated shell — the handler has no session to append to and fails.
Source
Thrown at crates/goose-cli/src/commands/term.rs:232
session
}
};
let goose_bin = std::env::current_exe()
.map(|p| p.to_string_lossy().into_owned())
.unwrap_or_else(|_| "goose".to_string());
println!(
"{}",
render_term_init_script(shell, &session.id, &goose_bin, with_command_not_found)
);
Ok(())
}
pub async fn handle_term_log(command: String) -> Result<()> {
let session_id = std::env::var("AGENT_SESSION_ID").map_err(|_| {
anyhow!(
"AGENT_SESSION_ID not set. Initialize terminal integration with `goose term init <shell>` and reload your shell first."
)
})?;
let message = Message::new(
Role::User,
chrono::Utc::now().timestamp_millis(),
vec![MessageContent::text(command)],
)
.with_metadata(MessageMetadata::user_only())
.with_generated_id();
let session_manager = SessionManager::instance();
session_manager.add_message(&session_id, &message).await?;
Ok(())
}
View on GitHub (pinned to 3810898a74)
Solutions
- Run `goose term init <shell>` and ensure its output is evaluated in your shell profile, then reload the shell
- Verify with `echo $AGENT_SESSION_ID` that the variable is set
- Only call `goose term log` from an integrated terminal session
Example fix
# before goose term log 'cargo build' # after goose term init bash >> ~/.bashrc && exec bash echo $AGENT_SESSION_ID # non-empty now goose term log 'cargo build'
Defensive patterns
Strategy: validation
Validate before calling
let session_id = match std::env::var("AGENT_SESSION_ID") {
Ok(v) => v,
Err(_) => {
eprintln!("run `goose term init <shell>` and reload your shell first");
return Ok(());
}
}; Type guard
fn term_integration_active() -> bool {
std::env::var("AGENT_SESSION_ID").map(|v| !v.is_empty()).unwrap_or(false)
} Try / catch
if let Err(e) = handle_term_log(cmd).await {
if e.to_string().contains("AGENT_SESSION_ID not set") {
// environment problem, not a command failure: guide the user, exit success
} else {
return Err(e);
}
} Prevention
- Source the `goose term init` script from your shell profile so every shell has AGENT_SESSION_ID
- Assert `test -n "$AGENT_SESSION_ID"` before any term command in scripts
When it happens
Trigger: Running `goose term log <cmd>` in a shell that has not sourced the init script; running from cron, a clean env subprocess, or a terminal where the integration was installed but the shell was not reloaded.
Common situations: Forgetting `exec $SHELL` / reopening the terminal after `goose term init`; SSH sessions without the profile; scripts stripping the environment.
Related errors
- AGENT_SESSION_ID not set. Initialize terminal integration w
- GOOSE_BINARY is only supported in development builds
- Invalid GOOSE_BINARY path: ${pathFromEnv} (pwd is ${process.
- GOOSE_SERVER__SECRET_KEY must be set when using GOOSE_EXTERN
- No goose binary available for ${key}. Set GOOSE_BINARY to th
AI-assisted analysis of aaif-goose/goose@3810898a74 (2026-08-16).
Data as JSON: /api/errors/46e5396022feef92.
Report an issue: GitHub.