Mastodon Feed: Post

Mastodon Feed

Boosted by baldur@toot.cafe ("Baldur Bjarnason"):
jonny@neuromatch.social ("jonny (good kind)") wrote:

but assuming we're not in coordinator mode, the prompt that instructs the main LLM to create an agent with the prompt text to create our statusline script is emitted, and if that works, then an agent will be run with the statusline system prompt, which is awesome.

So the prompt tells the LLM to modify the $PS1 variable in the shell configuration. for those non-computer touchers out there, the PS1 variable is the thing that customizes "what happens before my cursor on the shell line" - it's what makes it so sometimes it shows that folder you are in, and how people make their terminal look very fancy.

So the prompt text includes a whole fake JSON string that says "write a function that receives these kinds of parameters and then returns a whatever"

observe the prompt text in first image's description of fields and then the description on the claude code docs website. notice that they are ... different!!! like where is the cost field in the prompt description? the docs give a whole example of using this, but if you were to invoke it via the slash command, then it would just have no idea how to do that. the only way this succeeds is by virtue of the fact that the llm is just generating the most likely text anyway and so the odds of any of this succeeding are just "that some script that calls some variables with some maximally likely names represent some value that is maxmially likely, based on the training set prior."

[ a huge fake json object in the prompt, reproduced as far as character limits allow me to go below, most important point for the example being that there is no "cost" field] {  "session_id": "string", // Unique session ID  "session_name": "string", // Optional: Human-readable session name set via /rename  "transcript_path": "string", // Path to the conversation transcript  "cwd": "string",         // Current working directory  "model": {    "id": "string",           // Model ID (e.g., "claude-3-5-sonnet-20241022")    "display_name": "string"  // Display name (e.g., "Claude 3.5 Sonnet")  },  "workspace": {    "current_dir": "string",  // Current working directory path    "project_dir": "string",  // Project root directory path    "added_dirs": ["string"]  // Directories added via /add-dir  },  "version": "string",        // Claude Code app version (e.g., "1.0.71")  "output_style": {    "name": "string",         // Output style name (e.g., "default", "Explanatory", "Learning")  },
[description of fields on claude code's docs site, including a set of fields for "cost" like "total_cost_usd" and "total_duration_ms" and etc.  the page is probably more screen reader friendly, but partially reproduced below: https://code.claude.com/docs/en/statusline#available-data ] model.id, model.display_name	Current model identifier and display name cwd, workspace.current_dir	Current working directory. Both fields contain the same value; workspace.current_dir is preferred for consistency with workspace.project_dir. workspace.project_dir	Directory where Claude Code was launched, which may differ from cwd if the working directory changes during a session workspace.added_dirs	Additional directories added via /add-dir or --add-dir. Empty array if none have been added cost.total_cost_usd	Total session cost in USD cost.total_duration_ms	Total wall-clock time since the session started, in milliseconds cost.total_api_duration_ms	Total time spent waiting for API responses in milliseconds cost.total_lines_added, cost.total_lines_removed	Lines of code changed context_window.total_input_tokens, context_window.total_output_tokens	Cumulative token counts across the session context_window.context_window_size	Maximum context window size in tokens. 200000 by default, or 1000000 for models with extended context. context_window.used_percentage	Pre-calculated percentage of context window used
[example of using cost and duration tracking with the statusline from the claude docs - a bar is shown with a money bag showign 8 cents utsed in 7 minutes 3 seconds with some simple bash script to output a string to that effect https://code.claude.com/docs/en/statusline#cost-and-duration-tracking ] Cost and duration tracking Track your session’s API costs and elapsed time. The cost.total_cost_usd field accumulates the cost of all API calls in the current session. The cost.total_duration_ms field measures total elapsed time since the session started, while cost.total_api_duration_ms tracks only the time spent waiting for API responses. Each script formats cost as currency and converts milliseconds to minutes and seconds: A status line showing model name, session cost, and duration #!/bin/bash input=$(cat) MODEL=$(echo "$input" | jq -r '.model.display_name') COST=$(echo "$input" | jq -r '.cost.total_cost_usd // 0') DURATION_MS=$(echo "$input" | jq -r '.cost.total_duration_ms // 0') COST_FMT=$(printf '$%.2f' "$COST") DURATION_SEC=$((DURATION_MS / 1000)) MINS=$((DURATION_SEC / 60)) SECS=$((DURATION_SEC % 60)) echo "[$MODEL] 💰 $COST_FMT | ⏱️ ${MINS}m ${SECS}s"