Skip to content

Instantly share code, notes, and snippets.

@btakita
Last active April 8, 2026 04:33
Show Gist options
  • Select an option

  • Save btakita/ab31879717d229d50c4b13e7031717e3 to your computer and use it in GitHub Desktop.

Select an option

Save btakita/ab31879717d229d50c4b13e7031717e3 to your computer and use it in GitHub Desktop.
agent-doc: agent:terminal + Musing status capture

agent-doc: agent:terminal + Musing status capture

agent-doc: agent:terminal + Musing status capture

agent-doc: agent:console — streaming terminal output to a document

Exchange

❯ Can agent-doc capture terminal output + chain of thought? Would the "Musing..." status bar message be captured? ❯ (Screenshot: Claude Code status bar showing "Musing... 12m 32s ↑ 1.2k tokens")

Re: agent:console — StreamCapture mode

Can agent-doc stream terminal output to a document?

Yes — via StreamCapture mode. agent-doc watch polls the claimed tmux pane via tmux capture-pane, diffs for new lines, and writes into the <!-- agent:console --> component with tail truncation.

Document setup:

---
agent_doc_write: crdt
stream_config:
  target: console    # writes into <!-- agent:console --> (default)
  max_lines: 50      # keep last N lines (default: 50)
  strip_ansi: true   # strip escape codes (default: true)
  interval: 200      # poll interval ms (default: 200)
  thinking: false    # include chain-of-thought blocks (default: false)
---

Add to the document body:

<!-- agent:console -->
<!-- /agent:console -->

Would "Musing..." be captured?

Not directly. The Claude Code status bar is a terminal UI element rendered via escape sequences — not stdout. agent:console captures pane content via tmux capture-pane, which renders the visible screen. So it would show "Musing..." if the pane being captured is the Claude Code pane, but you'd also get surrounding chrome and prior output.

For clean capture of the thinking status, you'd need either:

  • Terminal screen scraping: tmux capture-pane -p -t <pane> on a timer — rough but functional
  • Claude API integration: hooking into the API response stream directly to get thinking tokens before rendering

❯ How can we implement the Claude API integration approach — streaming thinking tokens from the API before they're rendered?

Re: Claude API thinking token streaming

agent-doc stream already implements this. It spawns Claude with --output-format stream-json, and streaming.rs extracts both "type": "text" and "type": "thinking" blocks. Thinking is buffered separately and flushed to a target component on the write interval.

Document setup:

---
agent_doc_format: template
agent_doc_write: crdt
agent_doc_stream:
  target: exchange        # response text → agent:exchange
  thinking: true
  thinking_target: log    # thinking tokens → agent:log (separate component)
  interval: 200
---

Add components to the document body:

<!-- agent:exchange -->
<!-- /agent:exchange -->

<!-- agent:log -->
<!-- /agent:log -->

Run: agent-doc stream <FILE>

The stream loop feeds "type": "thinking" chunks to thinking_buffer, interleaved with response text in the main buffer. Both flush to their components on the timer interval (default 200ms). You see thinking tokens appearing live in the agent:log component as Claude reasons.

Caveat: This only works for sessions run through agent-doc stream. If Claude Code is running independently in another tmux pane (not as an agent-doc stream session), its API stream is not accessible — tmux capture-pane is the only option for that case.


❯ Why was the initial answer incorrect — saying agent-doc doesn't support thinking capture?

Re: why the initial "No" was wrong

The initial answer was framed around Claude Code hooks (does CC expose hook events for status indicators?) and correctly said "No" to that narrow question — there are no hook events for "Musing/Orbiting" state changes.

But the question also contained a broader implication: can thinking be captured at all? I listed --output-format stream-json + stream_config.thinking as a bullet point under "Capture options" but buried it under "No" framing, making it sound like a workaround rather than a first-class feature.

The accurate framing should have been:

agent-doc stream supports thinking capture natively via stream_config.thinking: true. For the "agent:console" use case, run the Claude session through agent-doc stream and route thinking tokens to a component. This is the intended path — no scraping needed.

The confusion: I mentally categorized the question as "Claude Code hooks" rather than "what does agent-doc support?" Since the user was looking at the Claude Code status bar and asking about capturing it, I anchored on "Claude Code hooks don't support this" instead of "agent-doc stream already does thinking capture."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment