You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Managed app-server runs hooks with the first client's TMUX_PANE/TMUX, misattributing hook events to the wrong terminal pane (0.157 regression) #48500
CLIIssues related to the Codex CLIapp-serverIssues involving app server protocol or interfacesbugSomething isn't workinghooksIssues related to event hooks
Since 0.157 the TUI talks to a shared codex app-server --managed-daemon (one per CODEX_HOME), and lifecycle hooks (UserPromptSubmit, Stop, PostToolUse) run inside that daemon. The daemon inherits the environment of whichever TUI first spawned it, so every hook for every later TUI sees that first client's TMUX / TMUX_PANE. Before 0.157, hooks ran in the TUI's own process and saw the correct pane.
Reproduction (reproduced on 0.157.1, macOS, tmux)
tmux pane A: start codex, submit a prompt (the managed daemon starts).
tmux pane B, same CODEX_HOME: start codex, submit a prompt.
In a UserPromptSubmit hook, log $TMUX_PANE and the hook payload's session_id.
Expected: B's hook reports pane B. Actual: B's hook reports pane A together with B'ssession_id. If pane A has since been closed while the daemon stays alive, B's hooks report a pane that no longer exists.
Impact
Tmux-aware hook consumers (e.g. workmux status tracking) silently write B's session to A's pane (input/status then route to the wrong session), or drop B's updates entirely.
What this is / isn't asking for
Not asking for client metadata on turns (#44774); the thread-vs-client concerns raised there are fair.
Asking only that hooks are not handed a stale, arbitrary client's terminal identity. Suggested:
remove TMUX, TMUX_PANE (and similar terminal-identity variables) from the daemon's environment before running hooks, so consumers fail safely instead of misattributing;
optionally, a hook-scoped, local-only payload field carrying the pid of the client that submitted the turn.
Reacted by rowan-hiro, Axel Karlsson, Sebastian Jug, Can Celik, Zhuoren Ye, Wataru Ashihara, Manuel Martinez, Gjermund Garaba, Adam George, Little Pan and 18 more
Follow-up: the correct-attribution side (hooks receiving the triggering client's terminal context) is tracked in #44902; I've added this reproduction there. This issue stays scoped to not handing hooks a stale client's TMUX/TMUX_PANE.
adding herdr's case. herdr is a terminal workspace for running coding agents, around 1M downloads, and codex is the second most used cli among our users.
we hit the same thing on 0.157.1: each pane launches codex with HERDR_PANE_ID and HERDR_SOCKET_PATH, and our SessionStart hook uses them to record which thread lives in which pane, so we can codex resume <id> in the right pane after a restart. with the managed daemon, every hook carries the first pane's env, so pane B's thread gets saved on pane A. if the panes live in different herdr sessions, the report even goes to the wrong herdr server. tool calls get the same stale env, so commands that read HERDR_* inside codex target the wrong pane.
repro: start codex in pane A and send a prompt, then do the same in pane B. B's SessionStart hook gets B's session_id with A's HERDR_PANE_ID.
stripping the vars would stop the wrong writes, but we'd still have no way to attribute sessions. what we need is the triggering client's context in hook input (#44902), and ideally a per-client "displayed thread" signal so /new and /resume are covered too (#48880). happy to test a build.
There are some misconceptions implicit in this bug report. The app server provides the environment that hosts the Codex harness and runs all active threads. The TUI is one of many clients that can connect to an app server instance. It's possible for many different client instances to connect to an app server concurrently, even interacting with the same thread. It's also possible for an app server to be running in a completely headless manner where no clients are currently attached to it.
Hooks run within the app server and have no relationship to (or knowledge of) the clients that are currently attached to the server or subscribed to a specific session. So it doesn't make sense to attribute a particular session with a particular client instance, at least not from the perspective of a hook callback.
It sounds like you are relying on behavioral side effects that were never intended to be contractual.
Can you describe your use case in more detail? Perhaps there are other means by which we can enable your scenario.
our use case, shared by herdr, tmux and other terminal multiplexers: each pane runs its own codex tui, and the multiplexer tells panes apart through env it injects (HERDR_PANE_ID, TMUX_PANE). hooks read that env to record which thread belongs to which pane, so after a restart we can run codex resume <id> in the right pane. commands the agent runs rely on the same env to know which pane they're in.
with the shared app server, hooks and tool calls get the server's env, so every thread looks like it came from whichever pane started the server.
all we need is a reliable way to know which thread each pane's tui is showing. two options that would work:
the tui binds a few user-configured env values to the thread it opens (startup, /new, /resume), and hooks for that thread receive them. opencode also moved to a shared server, and hit the same problem. it's fixed with a similar solution: feat(tui): inherit terminal environment per session anomalyco/opencode#42957.
I maintain TCrit, a terminal review tool that coding agents invoke through shell tool calls. Here is another concrete use case: opening a review UI alongside the Codex TUI whose work the user is reviewing.
TCrit integrates with tmux and Herdr to open a review pane or tab in the invoking terminal’s context. That placement is part of the workflow: the user can read the proposed changes, leave comments, and return to the corresponding conversation.
Opening the review in whichever window happens to be active is not a suitable fallback. With several Codex sessions working in parallel across different terminals, background sessions could repeatedly open review UIs in front of the user while they are working on something unrelated. Reviews need to appear with their corresponding conversations, independently of which terminal currently has focus. A stale terminal identity can also send them to an entirely different multiplexer instance.
Before the shared daemon, TCrit could recover missing terminal context by following process ancestry back to the invoking TUI. Shell commands running under the shared server no longer have that ancestry.
I understand that a thread can have multiple attached clients, or none, so a permanent thread-to-terminal mapping would not cover every case. Our requirement is narrower: a supported way to route a particular interactive tool request to an appropriate local client, with explicit handling when there is no destination or the choice is ambiguous. For tools like TCrit, an opt-in way to pass selected terminal environment variables from the invoking client through to its shell tool calls would be the simplest integration—for example, TMUX / TMUX_PANE or the relevant HERDR_* variables. Would something along those lines be feasible, scoped to the invocation rather than the shared server environment? Cases with multiple clients or no attached client would still need explicit handling.
Our current workaround uses a dedicated skill bundled with TCrit to instruct the agent to display a short-lived marker in the conversation immediately before launching the review. TCrit locates it in the visible text of registered terminal panes, or receives a notification from a terminal filter. This lets us keep normal daemon behavior, but a supported client-side mechanism would avoid that extra coordination.
You asked for use cases, so here's one where this isn't a cosmetic side effect.
We build Maestri, a workspace where several coding agents run side by side, each in its own terminal, and talk to each other through a CLI. Like tmux, herdr and every terminal multiplexer, we tell terminals apart by environment variables set per terminal. That's not an exotic side effect. It's how Unix processes have worked for fifty years, and it's how Codex itself behaved until 0.157.
0.157 turned the shared server on by default (#47179, listed only in the PR list, not the highlights), and nowhere mentions that commands in every TUI now run with the first client's environment. Minimal repro, no third-party tools:
A=1 codex # terminal 1, run a prompt
A=2 codex # terminal 2: !printenv A → 1
For a tool that routes by terminal, this is misattribution, not missing data: every Codex session acts under the identity, credentials and permissions of whichever terminal happened to start the server first. Nothing errors. It's silently wrong, and which terminal "wins" changes every time the server restarts.
"Never intended to be contractual" is a hard sell when the behavior was the default for every release before this one, and changing it breaks every tool built on the terminal's own environment: direnv, virtualenvs, tmux, herdr, and us. People build on Codex because it behaves like a normal CLI. Breaking that without notice, and then calling the people who relied on it misinformed, is how you lose the ecosystem building on top of you.
Concrete asks:
Don't give one client's environment to other clients' commands. Use a neutral environment or each client's own, but never an arbitrary first client's.
Make the opt-out a stable, documented config setting, not only a CLI flag.
Treat changes to command execution environment as breaking changes in the changelog.
Additional macOS/Herdr confirmation, including a concrete shell-tool routing failure, not just hook attribution.
Versions and process evidence
macOS 27.0 (26A428), Apple Silicon M4 Pro.
Invoking CLI: codex-cli 0.159.0.
Shared managed daemon executable: ~/.codex/packages/app-server-daemon/releases/0.159.2-aarch64-apple-darwin/bin/codex app-server --listen unix:// --managed-daemon. These CLI/daemon versions differ; I am reporting the actual installed combination, not claiming this was a clean same-version test.
Multiple Codex TUIs share this daemon.
We inspected only the relevant terminal-identity variables from the daemon and TUI process environments (ps eww -p PID, filtered to HERDR_ENV, HERDR_PANE_ID, HERDR_TAB_ID, HERDR_WORKSPACE_ID). The second TUI has its own correct pane identity, while shell tools receive the daemon's unrelated identity:
The affected tool environment reported w4:p3, not the caller's w2:pF. The daemon and second-TUI process environments were rechecked on September 30 and still have the values above. These are observations from existing live sessions, not a newly executed synthetic two-client reproduction.
User-visible failure
Our workflow pairs one Codex TUI and one Claude Code process in each Herdr tab. A shell helper invoked by Codex discovers the adjacent Claude pane and sends it a bounded discussion request.
In the affected session:
The actual pair was Codex w2:pF and Claude w2:pG, in tab w2:tB.
Because the shell tool inherited HERDR_PANE_ID=w4:p3, implicit Herdr --current lookup resolved an unrelated pane.
That pane's live layout selected sibling w4:p13, which contained a shell rather than Claude.
The helper returned agent_not_found; no discussion was delivered.
The pane referenced by the stale identity still existed and hosted Codex. Therefore a guard that merely checks “does this pane contain Codex?” does not fix attribution. Incorrect hook attribution also makes the multiplexer-reported thread ID unsuitable as independent proof of which TUI issued a command.
Local mitigation and its limits
We changed our helper to require an explicitly discovered source pane, resolve the peer from live layout, reject self/cross-tab/non-Claude targets, and revalidate tab/terminal identity and the actual TUI PID (when exposed) after readiness waits. Replies target the stated sender explicitly. This prevents the observed accidental routing and fails closed on layout/process changes, but cannot automatically prove the calling conversation's identity or detect a conversation switch inside an unchanged TUI process.
Requested upstream behavior
I understand the app server can have multiple clients per thread or no attached client. This is not a request to permanently equate a thread with a terminal. The concrete need is a supported local-client context for an interactive tool invocation, with an explicit unavailable/ambiguous result when no unique destination exists. Alternatively, removing stale client-specific terminal variables would at least prevent commands from silently impersonating an unrelated client, though it would not restore automatic routing.
The related hook-context/displayed-thread proposals in #44902 and #48880 could help integrations; shell-tool execution also needs consideration. No broader credential-environment leakage was tested here. We have not tested the suggested --no-daemon workaround in these sessions or restarted the daemon as part of this investigation.
Prepared with Codex assistance; process/environment evidence and the failed routing were inspected locally. No private transcripts or credentials are included.
Additional Herdr confirmation on September 30 with Codex CLI 0.159.2 and managed daemon 0.159.2, plus a successful --no-daemon control test.
Environment: macOS, Apple Silicon; Herdr 0.9.1 during diagnosis. The managed server process was codex app-server --listen unix:// --managed-daemon from the installed 0.159.2-aarch64-apple-darwin daemon release.
Observed in existing live sessions:
Four distinct Codex sessions' newly generated shell snapshots all exported the same HERDR_PANE_ID=w2:pB and HERDR_TAB_ID=w2:tA, including a session actually displayed in Herdr pane w1:pN.
herdr pane get w2:pB returned pane_not_found. The live pane inventory identified w1:pN as the pane displaying that conversation.
A Stop hook reads context usage from its own transcript and reports a display-only ctx token to the pane identified by HERDR_PANE_ID. Transcript parsing succeeded independently, but Herdr logged repeated metadata-report failures. Codex SessionStart registration also logged failures; the affected live Codex panes lacked native session references.
Claude Code in the same Herdr server continued reporting its context token and session reference correctly.
Control test: created a fresh Herdr pane and launched codex --no-daemon. After one short turn, the existing hooks successfully registered that pane's Codex session and reported ctx=7%. Its shell snapshot contained its actual pane ID, w1:pP.
These are live-session observations and a no-daemon control, not a fresh isolated reproduction proving which original client seeded the daemon environment. We did not test credential-related environment variables.
Local mitigation for the already-open agents: verified their session IDs using /status, registered those session-to-pane mappings in Herdr, and changed the context hook to resolve the hook payload's session_id through the live registry. This restored context reporting without restarting the Codex agents. It does not provide automatic discovery for new daemon-backed clients or reliable tracking of subsequent /new and /resume switches.
Our concrete use case is per-pane context-window consumption and preserving the correct conversation in each organized pane across multiplexer restarts. A supported client-side displayed-thread signal, as proposed in #48880, would let the multiplexer maintain the mapping while hooks remain server-side. The stale terminal environment also affects shell-tool routing, not only hook consumers.
Prepared with Codex assistance. No private transcripts, credentials, local repository paths, or session IDs are included.
Thanks for explaining, that makes sense. I think I was reading the pre-0.157 behavior as more of a contract than it was.
Our use case is close to what herdr described. I run a small local viewer that shows transcripts of the agent sessions I have open in tmux. From the viewer I can reply to a session, which pastes the text into the pane showing that thread, or jump to that pane. After a reboot, the panes get restored and each one runs codex resume <id> for the thread it had before. All three need to know which thread a given pane's TUI is showing. At the moment we get that from hooks (TMUX_PANE + session_id), which is the part that breaks with the shared server.
So what we need is more the client → thread direction: this TUI, in this pane, is showing thread X right now. The pane → TUI process part we can already get from tmux, so the missing piece is only TUI process → the thread id it's displaying. We don't need to know which clients are attached to a thread. If I understand right, that fits the model you described, since it's something only the TUI knows and hooks can stay unaware of clients. It's basically what herdr's second option and #48880 ask for, and either shape would work for us.
Until something like that exists, one smaller thing that would help: if hooks didn't get the TMUX / TMUX_PANE of whichever client started the server, tools like ours would just fail to find a pane instead of silently writing a session to the wrong one. The wrong-pane case is the one that hurts us, since a reply can end up in a different session.
+1 from PonyMux, a macOS terminal app that shows a live status (running / waiting / idle) for each agent terminal.
With the shared daemon, hooks run without the client's tty or environment, so we can't tell which terminal an event belongs to (#48500). For now we wrap codex with --no-daemon, the same workaround as Orca.
A per-client "displayed thread" signal would let us keep the daemon. We'd bind thread → terminal from the TUI's report, then match hook events by session_id, and hooks could stay client-agnostic. An opt-in escape sequence that writes the full thread ID to the terminal would be enough: the terminal already knows which pane received it.
Adding my macOS Herdr case: I experienced missing terminal context in a daemon-backed session today (14 October), then verified --no-daemon in a later session.
I asked Codex, from its Herdr tab, to delegate a code-review challenge to an already-open Claude Code tab. Verified in the failing session:
The Herdr skill's test "${HERDR_ENV:-}" = 1 check failed twice, including after approving the hooks, reopening Codex, and resuming.
Shell-tool commands had no HERDR_ENV, workspace/tab/pane IDs, or socket path. The live Codex terminal client in the same checkout had HERDR_ENV=1 and the correct IDs and socket.
The shell command's process ancestry ran through the Codex 0.162.1 app-server daemon. Those daemon processes also had no Herdr context.
Herdr reported the Codex pane as working without an agent_session; the neighboring Claude pane had its session reference.
Recovering the terminal client's verified context and passing it to the Herdr CLI restored control of the intended panes.
In a later session, with Herdr 0.9.4 and Codex CLI 0.162.1, I verified that the Codex process was running with --no-daemon, the shell workspace/pane IDs were correct, and Herdr's agent_session matched CODEX_THREAD_ID. Normal herdr tab create, herdr agent start, and herdr agent prompt commands opened a tab in the correct workspace, started Claude Code with Opus 5.5, and sent hi. Claude replied.
These are observations from a real existing session and a later workaround test, not a fresh isolated two-client reproduction. We did not establish why the earlier native session reference was absent.
This workflow needs reliable per-TUI workspace/pane context for shell-tool commands. The correct working directory alone does not identify the intended Herdr workspace or pane.
Anyone found a fix to this? I've noticed that it's always the pane where the codex app-server was started. Run codex app-server daemon restart in a pane, then every herdr pane current will give that pane. As soon as you close than pane herdr pane current will return 'pane not found'.
This is severely limiting my ability to script with codex.
Additional Herdr evidence from an existing macOS setup on 2026-10-23: the shared app-server process is from the 0.164.0-aarch64-apple-darwin release directory; the currently installed CLI reports 0.163.0. Existing TUIs were not restarted, so this is runtime evidence, not a clean-install reproduction of either version.
A long-lived inbox TUI in pane A still had its own inbox resume UUID in its foreground argv and the expected native title/parking draft. Herdr's session reference for that pane was overwritten with the UUID of an unrelated build-runner conversation in pane B. Saved Herdr snapshots captured that mismatch.
The inbox pane consequently inherited the other conversation's pinned topic label. Subsequent unrelated conversations replaced its saved ID again. This affects conversation-keyed titles as well as cold restore, not only transient status.
Shell-tool commands from another conversation also received pane A's HERDR_* context. Process ancestry led through the shared app-server launched from A, while the individual TUI processes retained their own correct pane environments.
Our limited local mitigation rejects hook IDs that conflict with an explicit foreground resume UUID, using live writable-rollout/native-title evidence first and startup argv only as fallback. We repaired the existing restore reference with verified process identity, without restarting the agents or daemon. This does not fix inherited tool environments or establish reliable identity after every in-process thread switch.
A supported TUI-side currently-displayed-thread signal, as discussed in #48880, would remove the need for these heuristics. Private paths, conversation IDs and environment dumps are intentionally omitted.
Same root cause also breaks herdr (a terminal multiplexer that exposes HERDR_ENV, HERDR_PANE_ID, HERDR_TAB_ID, HERDR_WORKSPACE_ID to processes in each pane).
On 0.165.0 (macOS arm64, daemon_auto_start stable/true), codex launched inside a herdr pane forwards turns to the shared app-server --managed-daemon, so shell tool calls inherit the daemon's environment instead of the pane's. In our case the pid-update-loop process carried a stale HERDR_PANE_ID from the first pane that spawned it, while the app-server itself (re-parented to launchd) had no HERDR_* at all, so pane-aware skills refuse to run.
Workaround we're using now:
Disable auto-start in ~/.codex/config.toml:
[features]
daemon_auto_start = false
Stop the already-running shared daemon (the flag alone doesn't stop clients from attaching to a daemon that's already up):
codex app-server daemon stop
Restart sessions from inside the multiplexer pane with codex resume <id> (or codex --no-daemon resume <id> as a one-off without touching config).
After this, env | grep HERDR inside tool calls shows the pane's variables again. Trade-off: codex agents, codex queue and remote control need the shared daemon and stop working.
Suggestion: have the TUI forward the client's environment per session, or at least an allowlist such as shell_environment_policy.forward_client_env = ["TMUX*", "HERDR_*"], so multiplexer-aware tooling keeps working with the daemon on.
I can reproduce this on macOS with Codex CLI, the managed daemon package, and the running app-server all on 0.166.0.
When I launch codex inside a Herdr-managed pane, shell commands executed by the agent do not receive HERDR_ENV. Consequently, the Herdr skill’s environment check fails, preventing the agent from controlling Herdr panes.
Launching with codex --no-daemon works correctly. Aligning the CLI and daemon versions did not resolve the issue.
Is there a supported way to preserve the originating Herdr pane’s environment for tool calls while keeping the shared daemon enabled?
Process-level confirmation on codex-cli 0.166.0 (CLI, managed daemon and app-server all on 0.166.0), Linux x86_64, using herdr's pane-scoped env var HERDR_PANE_ID. The mechanism is the one in this issue's title, and it still reproduces on 0.166.0.
The managed daemon (codex app-server --remote-control --listen unix:// --analytics-default-enabled --managed-daemon, pid 1197041) was started from terminal pane w2Q:p2, and its environment carries HERDR_PANE_ID=w2Q:p2.
A fresh codex TUI (pid 3388450) was started in a different pane, w2J:p1B, and its environment carries HERDR_PANE_ID=w2J:p1B.
A user-config SessionStart hook (listed as Trusted in /hooks) did not fire at TUI start. It fired on the first submitted prompt.
A read-only /proc watcher shows the hook process (pid 3409373) had the managed daemon (pid 1197041) as its parent, with HERDR_PANE_ID=w2Q:p2. That is the first client's terminal, not the terminal of the TUI whose session started.
So the hook cannot attribute the session to its terminal, and the terminal integration reports the session against the wrong pane or not at all.
Ask: give client-originated hooks the attaching client's context, for example the TUI's pid plus an allow-listed set of its environment variables (TMUX_PANE, TERM_PROGRAM, HERDR_* and similar). Alternatively, run client-scoped hooks such as SessionStart in the TUI process, or expose the client-to-thread binding through the app-server protocol.
CLIIssues related to the Codex CLIapp-serverIssues involving app server protocol or interfacesbugSomething isn't workinghooksIssues related to event hooks
Activity
yzcj105 commentedon Sep 26, 2026
Follow-up: the correct-attribution side (hooks receiving the triggering client's terminal context) is tracked in #44902; I've added this reproduction there. This issue stays scoped to not handing hooks a stale client's
TMUX/TMUX_PANE.Record that background-server Codex CLI rows cannot be read or return…
ogulcancelik commentedon Sep 28, 2026
adding herdr's case. herdr is a terminal workspace for running coding agents, around 1M downloads, and codex is the second most used cli among our users.
we hit the same thing on 0.157.1: each pane launches codex with
HERDR_PANE_IDandHERDR_SOCKET_PATH, and ourSessionStarthook uses them to record which thread lives in which pane, so we cancodex resume <id>in the right pane after a restart. with the managed daemon, every hook carries the first pane's env, so pane B's thread gets saved on pane A. if the panes live in different herdr sessions, the report even goes to the wrong herdr server. tool calls get the same stale env, so commands that readHERDR_*inside codex target the wrong pane.repro: start
codexin pane A and send a prompt, then do the same in pane B. B'sSessionStarthook gets B'ssession_idwith A'sHERDR_PANE_ID.stripping the vars would stop the wrong writes, but we'd still have no way to attribute sessions. what we need is the triggering client's context in hook input (#44902), and ideally a per-client "displayed thread" signal so
/newand/resumeare covered too (#48880). happy to test a build.for now we're telling users to run
codex --no-daemon: herdrdev/herdr#4649etraut-openai commentedon Sep 28, 2026
There are some misconceptions implicit in this bug report. The app server provides the environment that hosts the Codex harness and runs all active threads. The TUI is one of many clients that can connect to an app server instance. It's possible for many different client instances to connect to an app server concurrently, even interacting with the same thread. It's also possible for an app server to be running in a completely headless manner where no clients are currently attached to it.
Hooks run within the app server and have no relationship to (or knowledge of) the clients that are currently attached to the server or subscribed to a specific session. So it doesn't make sense to attribute a particular session with a particular client instance, at least not from the perspective of a hook callback.
It sounds like you are relying on behavioral side effects that were never intended to be contractual.
Can you describe your use case in more detail? Perhaps there are other means by which we can enable your scenario.
ogulcancelik commentedon Sep 28, 2026
our use case, shared by herdr, tmux and other terminal multiplexers: each pane runs its own codex tui, and the multiplexer tells panes apart through env it injects (HERDR_PANE_ID, TMUX_PANE). hooks read that env to record which thread belongs to which pane, so after a restart we can run
codex resume <id>in the right pane. commands the agent runs rely on the same env to know which pane they're in.with the shared app server, hooks and tool calls get the server's env, so every thread looks like it came from whichever pane started the server.
all we need is a reliable way to know which thread each pane's tui is showing. two options that would work:
knu commentedon Sep 29, 2026
I maintain TCrit, a terminal review tool that coding agents invoke through shell tool calls. Here is another concrete use case: opening a review UI alongside the Codex TUI whose work the user is reviewing.
TCrit integrates with tmux and Herdr to open a review pane or tab in the invoking terminal’s context. That placement is part of the workflow: the user can read the proposed changes, leave comments, and return to the corresponding conversation.
Opening the review in whichever window happens to be active is not a suitable fallback. With several Codex sessions working in parallel across different terminals, background sessions could repeatedly open review UIs in front of the user while they are working on something unrelated. Reviews need to appear with their corresponding conversations, independently of which terminal currently has focus. A stale terminal identity can also send them to an entirely different multiplexer instance.
Before the shared daemon, TCrit could recover missing terminal context by following process ancestry back to the invoking TUI. Shell commands running under the shared server no longer have that ancestry.
I understand that a thread can have multiple attached clients, or none, so a permanent thread-to-terminal mapping would not cover every case. Our requirement is narrower: a supported way to route a particular interactive tool request to an appropriate local client, with explicit handling when there is no destination or the choice is ambiguous. For tools like TCrit, an opt-in way to pass selected terminal environment variables from the invoking client through to its shell tool calls would be the simplest integration—for example,
TMUX/TMUX_PANEor the relevantHERDR_*variables. Would something along those lines be feasible, scoped to the invocation rather than the shared server environment? Cases with multiple clients or no attached client would still need explicit handling.Our current workaround uses a dedicated skill bundled with TCrit to instruct the agent to display a short-lived marker in the conversation immediately before launching the review. TCrit locates it in the visible text of registered terminal panes, or receives a notification from a terminal filter. This lets us keep normal daemon behavior, but a supported client-side mechanism would avoid that extra coordination.
evertjr commentedon Sep 29, 2026
You asked for use cases, so here's one where this isn't a cosmetic side effect.
We build Maestri, a workspace where several coding agents run side by side, each in its own terminal, and talk to each other through a CLI. Like tmux, herdr and every terminal multiplexer, we tell terminals apart by environment variables set per terminal. That's not an exotic side effect. It's how Unix processes have worked for fifty years, and it's how Codex itself behaved until 0.157.
0.157 turned the shared server on by default (#47179, listed only in the PR list, not the highlights), and nowhere mentions that commands in every TUI now run with the first client's environment. Minimal repro, no third-party tools:
For a tool that routes by terminal, this is misattribution, not missing data: every Codex session acts under the identity, credentials and permissions of whichever terminal happened to start the server first. Nothing errors. It's silently wrong, and which terminal "wins" changes every time the server restarts.
"Never intended to be contractual" is a hard sell when the behavior was the default for every release before this one, and changing it breaks every tool built on the terminal's own environment: direnv, virtualenvs, tmux, herdr, and us. People build on Codex because it behaves like a normal CLI. Breaking that without notice, and then calling the people who relied on it misinformed, is how you lose the ecosystem building on top of you.
Concrete asks:
bshor commentedon Sep 30, 2026
Additional macOS/Herdr confirmation, including a concrete shell-tool routing failure, not just hook attribution.
Versions and process evidence
codex-cli 0.159.0.~/.codex/packages/app-server-daemon/releases/0.159.2-aarch64-apple-darwin/bin/codex app-server --listen unix:// --managed-daemon. These CLI/daemon versions differ; I am reporting the actual installed combination, not claiming this was a clean same-version test.We inspected only the relevant terminal-identity variables from the daemon and TUI process environments (
ps eww -p PID, filtered toHERDR_ENV,HERDR_PANE_ID,HERDR_TAB_ID,HERDR_WORKSPACE_ID). The second TUI has its own correct pane identity, while shell tools receive the daemon's unrelated identity:The affected tool environment reported
w4:p3, not the caller'sw2:pF. The daemon and second-TUI process environments were rechecked on September 30 and still have the values above. These are observations from existing live sessions, not a newly executed synthetic two-client reproduction.User-visible failure
Our workflow pairs one Codex TUI and one Claude Code process in each Herdr tab. A shell helper invoked by Codex discovers the adjacent Claude pane and sends it a bounded discussion request.
In the affected session:
w2:pFand Claudew2:pG, in tabw2:tB.HERDR_PANE_ID=w4:p3, implicit Herdr--currentlookup resolved an unrelated pane.w4:p13, which contained a shell rather than Claude.agent_not_found; no discussion was delivered.The pane referenced by the stale identity still existed and hosted Codex. Therefore a guard that merely checks “does this pane contain Codex?” does not fix attribution. Incorrect hook attribution also makes the multiplexer-reported thread ID unsuitable as independent proof of which TUI issued a command.
Local mitigation and its limits
We changed our helper to require an explicitly discovered source pane, resolve the peer from live layout, reject self/cross-tab/non-Claude targets, and revalidate tab/terminal identity and the actual TUI PID (when exposed) after readiness waits. Replies target the stated sender explicitly. This prevents the observed accidental routing and fails closed on layout/process changes, but cannot automatically prove the calling conversation's identity or detect a conversation switch inside an unchanged TUI process.
Requested upstream behavior
I understand the app server can have multiple clients per thread or no attached client. This is not a request to permanently equate a thread with a terminal. The concrete need is a supported local-client context for an interactive tool invocation, with an explicit unavailable/ambiguous result when no unique destination exists. Alternatively, removing stale client-specific terminal variables would at least prevent commands from silently impersonating an unrelated client, though it would not restore automatic routing.
The related hook-context/displayed-thread proposals in #44902 and #48880 could help integrations; shell-tool execution also needs consideration. No broader credential-environment leakage was tested here. We have not tested the suggested
--no-daemonworkaround in these sessions or restarted the daemon as part of this investigation.Prepared with Codex assistance; process/environment evidence and the failed routing were inspected locally. No private transcripts or credentials are included.
seiverlauth commentedon Sep 30, 2026
Additional Herdr confirmation on September 30 with Codex CLI 0.159.2 and managed daemon 0.159.2, plus a successful
--no-daemoncontrol test.Environment: macOS, Apple Silicon; Herdr 0.9.1 during diagnosis. The managed server process was
codex app-server --listen unix:// --managed-daemonfrom the installed0.159.2-aarch64-apple-darwindaemon release.Observed in existing live sessions:
HERDR_PANE_ID=w2:pBandHERDR_TAB_ID=w2:tA, including a session actually displayed in Herdr panew1:pN.herdr pane get w2:pBreturnedpane_not_found. The live pane inventory identifiedw1:pNas the pane displaying that conversation.ctxtoken to the pane identified byHERDR_PANE_ID. Transcript parsing succeeded independently, but Herdr logged repeated metadata-report failures. Codex SessionStart registration also logged failures; the affected live Codex panes lacked native session references.Control test: created a fresh Herdr pane and launched
codex --no-daemon. After one short turn, the existing hooks successfully registered that pane's Codex session and reportedctx=7%. Its shell snapshot contained its actual pane ID,w1:pP.These are live-session observations and a no-daemon control, not a fresh isolated reproduction proving which original client seeded the daemon environment. We did not test credential-related environment variables.
Local mitigation for the already-open agents: verified their session IDs using
/status, registered those session-to-pane mappings in Herdr, and changed the context hook to resolve the hook payload'ssession_idthrough the live registry. This restored context reporting without restarting the Codex agents. It does not provide automatic discovery for new daemon-backed clients or reliable tracking of subsequent/newand/resumeswitches.Our concrete use case is per-pane context-window consumption and preserving the correct conversation in each organized pane across multiplexer restarts. A supported client-side displayed-thread signal, as proposed in #48880, would let the multiplexer maintain the mapping while hooks remain server-side. The stale terminal environment also affects shell-tool routing, not only hook consumers.
Prepared with Codex assistance. No private transcripts, credentials, local repository paths, or session IDs are included.
yzcj105 commentedon Sep 30, 2026
Thanks for explaining, that makes sense. I think I was reading the pre-0.157 behavior as more of a contract than it was.
Our use case is close to what herdr described. I run a small local viewer that shows transcripts of the agent sessions I have open in tmux. From the viewer I can reply to a session, which pastes the text into the pane showing that thread, or jump to that pane. After a reboot, the panes get restored and each one runs
codex resume <id>for the thread it had before. All three need to know which thread a given pane's TUI is showing. At the moment we get that from hooks (TMUX_PANE+session_id), which is the part that breaks with the shared server.So what we need is more the client → thread direction: this TUI, in this pane, is showing thread X right now. The pane → TUI process part we can already get from tmux, so the missing piece is only TUI process → the thread id it's displaying. We don't need to know which clients are attached to a thread. If I understand right, that fits the model you described, since it's something only the TUI knows and hooks can stay unaware of clients. It's basically what herdr's second option and #48880 ask for, and either shape would work for us.
Until something like that exists, one smaller thing that would help: if hooks didn't get the
TMUX/TMUX_PANEof whichever client started the server, tools like ours would just fail to find a pane instead of silently writing a session to the wrong one. The wrong-pane case is the one that hurts us, since a reply can end up in a different session.Co-authored by AI assistant.
heylittlepan commentedon Oct 1, 2026
+1 from PonyMux, a macOS terminal app that shows a live status (running / waiting / idle) for each agent terminal.
With the shared daemon, hooks run without the client's tty or environment, so we can't tell which terminal an event belongs to (#48500). For now we wrap codex with --no-daemon, the same workaround as Orca.
A per-client "displayed thread" signal would let us keep the daemon. We'd bind thread → terminal from the TUI's report, then match hook events by session_id, and hooks could stay client-agnostic. An opt-in escape sequence that writes the full thread ID to the terminal would be enough: the terminal already knows which pane received it.
9 remaining items
alainkaiser commentedon Oct 14, 2026
Adding my macOS Herdr case: I experienced missing terminal context in a daemon-backed session today (14 October), then verified
--no-daemonin a later session.I asked Codex, from its Herdr tab, to delegate a code-review challenge to an already-open Claude Code tab. Verified in the failing session:
test "${HERDR_ENV:-}" = 1check failed twice, including after approving the hooks, reopening Codex, and resuming.HERDR_ENV, workspace/tab/pane IDs, or socket path. The live Codex terminal client in the same checkout hadHERDR_ENV=1and the correct IDs and socket.agent_session; the neighboring Claude pane had its session reference.Recovering the terminal client's verified context and passing it to the Herdr CLI restored control of the intended panes.
In a later session, with Herdr 0.9.4 and Codex CLI 0.162.1, I verified that the Codex process was running with
--no-daemon, the shell workspace/pane IDs were correct, and Herdr'sagent_sessionmatchedCODEX_THREAD_ID. Normalherdr tab create,herdr agent start, andherdr agent promptcommands opened a tab in the correct workspace, started Claude Code with Opus 5.5, and senthi. Claude replied.These are observations from a real existing session and a later workaround test, not a fresh isolated two-client reproduction. We did not establish why the earlier native session reference was absent.
This workflow needs reliable per-TUI workspace/pane context for shell-tool commands. The correct working directory alone does not identify the intended Herdr workspace or pane.
Related Herdr report: herdrdev/herdr#4649
nastynaz commentedon Oct 14, 2026
Anyone found a fix to this? I've noticed that it's always the pane where the codex app-server was started. Run
codex app-server daemon restartin a pane, then everyherdr pane currentwill give that pane. As soon as you close than paneherdr pane currentwill return 'pane not found'.This is severely limiting my ability to script with codex.
astral303 commentedon Oct 14, 2026
@nastynaz the only workaround is to either always add
--no-daemonflag to yourcodexstartup, or add this to your~/.codex/config.toml:Then make sure the
app-server daemonis stopped and that should keep the sessions behaving like you expect.fix(codex): ignore hooks from Codex's shared app-server daemon (#71) (#…
test(codex): add shared-daemon hook attribution e2e
fix: keep Codex TUIs off the shared app-server daemon
kvz commentedon Oct 23, 2026
Additional Herdr evidence from an existing macOS setup on 2026-10-23: the shared app-server process is from the
0.164.0-aarch64-apple-darwinrelease directory; the currently installed CLI reports0.163.0. Existing TUIs were not restarted, so this is runtime evidence, not a clean-install reproduction of either version.HERDR_*context. Process ancestry led through the shared app-server launched from A, while the individual TUI processes retained their own correct pane environments.Our limited local mitigation rejects hook IDs that conflict with an explicit foreground resume UUID, using live writable-rollout/native-title evidence first and startup argv only as fallback. We repaired the existing restore reference with verified process identity, without restarting the agents or daemon. This does not fix inherited tool environments or establish reliable identity after every in-process thread switch.
A supported TUI-side currently-displayed-thread signal, as discussed in #48880, would remove the need for these heuristics. Private paths, conversation IDs and environment dumps are intentionally omitted.
test(codex): add shared-daemon hook attribution e2e
fix(agent-hook): drop codex events from shared app-server (#849)
Buywatermelon commentedon Oct 28, 2026
Same root cause also breaks herdr (a terminal multiplexer that exposes
HERDR_ENV,HERDR_PANE_ID,HERDR_TAB_ID,HERDR_WORKSPACE_IDto processes in each pane).On 0.165.0 (macOS arm64,
daemon_auto_startstable/true),codexlaunched inside a herdr pane forwards turns to the sharedapp-server --managed-daemon, so shell tool calls inherit the daemon's environment instead of the pane's. In our case thepid-update-loopprocess carried a staleHERDR_PANE_IDfrom the first pane that spawned it, while theapp-serveritself (re-parented to launchd) had noHERDR_*at all, so pane-aware skills refuse to run.Workaround we're using now:
~/.codex/config.toml:codex resume <id>(orcodex --no-daemon resume <id>as a one-off without touching config).After this,
env | grep HERDRinside tool calls shows the pane's variables again. Trade-off:codex agents,codex queueand remote control need the shared daemon and stop working.Suggestion: have the TUI forward the client's environment per session, or at least an allowlist such as
shell_environment_policy.forward_client_env = ["TMUX*", "HERDR_*"], so multiplexer-aware tooling keeps working with the daemon on.hangs0908 commentedon Oct 30, 2026
I can reproduce this on macOS with Codex CLI, the managed daemon package, and the running app-server all on 0.166.0.
When I launch
codexinside a Herdr-managed pane, shell commands executed by the agent do not receiveHERDR_ENV. Consequently, the Herdr skill’s environment check fails, preventing the agent from controlling Herdr panes.Launching with
codex --no-daemonworks correctly. Aligning the CLI and daemon versions did not resolve the issue.Is there a supported way to preserve the originating Herdr pane’s environment for tool calls while keeping the shared daemon enabled?
thewoolleyman commentedon Nov 2, 2026
Process-level confirmation on codex-cli 0.166.0 (CLI, managed daemon and app-server all on 0.166.0), Linux x86_64, using herdr's pane-scoped env var
HERDR_PANE_ID. The mechanism is the one in this issue's title, and it still reproduces on 0.166.0.codex app-server --remote-control --listen unix:// --analytics-default-enabled --managed-daemon, pid 1197041) was started from terminal panew2Q:p2, and its environment carriesHERDR_PANE_ID=w2Q:p2.codexTUI (pid 3388450) was started in a different pane,w2J:p1B, and its environment carriesHERDR_PANE_ID=w2J:p1B./hooks) did not fire at TUI start. It fired on the first submitted prompt./procwatcher shows the hook process (pid 3409373) had the managed daemon (pid 1197041) as its parent, withHERDR_PANE_ID=w2Q:p2. That is the first client's terminal, not the terminal of the TUI whose session started.So the hook cannot attribute the session to its terminal, and the terminal integration reports the session against the wrong pane or not at all.
Ask: give client-originated hooks the attaching client's context, for example the TUI's pid plus an allow-listed set of its environment variables (
TMUX_PANE,TERM_PROGRAM,HERDR_*and similar). Alternatively, run client-scoped hooks such as SessionStart in the TUI process, or expose the client-to-thread binding through the app-server protocol.Integration-side counterpart, with the same measurement: herdrdev/herdr#4649 (comment)
feat(zsh): run Codex without its shared daemon in a herdr pane
Codex: write nothing when the background server runs the hook
fix: hold on Stop from background_tasks, stop treating subagent event…