Claude's answers, rendered: Markdown, math, charts and diagrams drawn in the Claude Code terminal. Independent project, not affiliated with Anthropic.
TypeScript claude-code-mod
Turn off the copy shims; picture select from Claude Code 2.1.298
razorback16876d6e03d54d
diff --git a/hooks/lib/api.ts b/hooks/lib/api.tsindex 407d291..d1caed9 100644--- a/hooks/lib/api.ts+++ b/hooks/lib/api.ts@@ -14,7 +14,7 @@ export type EnvName =| 'CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC' | 'CLAUDE_CODE_FORCE_TERMINAL_IMAGES' | 'CLAUDE_CODE_SESSION_KIND' | 'CLAUDE_CODE_TMPDIR'| 'CMUX_SOCKET_PATH' | 'CMUX_SURFACE_ID' | 'CMUX_WORKSPACE_ID' | 'COLORFGBG' | 'DISABLE_AUTOUPDATER' | 'DISABLE_UPDATES' | 'DISPLAY'| 'GHOSTTY_RESOURCES_DIR' | 'HOME'- | 'ITERM_PROFILE' | 'ITERM_SESSION_ID' | 'IUI_COPY_ASK' | 'IUI_DEBUG' | 'IUI_FORCE' | 'KITTY_CONFIG_DIRECTORY' | 'KITTY_PID'+ | 'ITERM_PROFILE' | 'ITERM_SESSION_ID' | 'IUI_COPY_ASK' | 'IUI_COPY_SHIM' | 'IUI_DEBUG' | 'IUI_FORCE' | 'KITTY_CONFIG_DIRECTORY' | 'KITTY_PID'| 'KITTY_WINDOW_ID' | 'LC_TERMINAL' | 'PATH' | 'RIO_CONFIG_HOME' | 'SHELL' | 'SSH_CONNECTION' | 'SSH_TTY' | 'STY'| 'TERM' | 'TERM_PROGRAM' | 'TMUX' | 'WAYLAND_DISPLAY' | 'XDG_CONFIG_HOME' | 'XDG_CURRENT_DESKTOP' | 'ZDOTDIR'// The variables the mod sets (the clipboard shims).@@ -62,6 +62,7 @@ export function envGet($: EngineInterface, name: EnvName): Promise<string | undecase 'ITERM_PROFILE': return $.env.get('ITERM_PROFILE')case 'ITERM_SESSION_ID': return $.env.get('ITERM_SESSION_ID')case 'IUI_COPY_ASK': return $.env.get('IUI_COPY_ASK')+ case 'IUI_COPY_SHIM': return $.env.get('IUI_COPY_SHIM')case 'IUI_DEBUG': return $.env.get('IUI_DEBUG')case 'IUI_FORCE': return $.env.get('IUI_FORCE')case 'KITTY_CONFIG_DIRECTORY': return $.env.get('KITTY_CONFIG_DIRECTORY')diff --git a/hooks/lib/env.ts b/hooks/lib/env.tsindex ae7bdc5..ff76e84 100644--- a/hooks/lib/env.ts+++ b/hooks/lib/env.ts@@ -4,7 +4,7 @@ import { atom, update } from 'claude-code'import type { EngineInterface } from 'claude-code'import {- BASE_THEME, DEFAULT_HEIGHT, DEFAULT_SIZE, DESIGNS_KEPT_DAYS, DEFAULT_THEME, DEFAULT_WIDTH, MAX_HEIGHT, MAX_SIZE, MAX_WIDTH, MIN_HEIGHT, MIN_SIZE, MIN_WIDTH, noTypstOf,+ BASE_THEME, DEFAULT_HEIGHT, DEFAULT_SIZE, DESIGNS_KEPT_DAYS, DEFAULT_THEME, DEFAULT_WIDTH, MAX_HEIGHT, MAX_SIZE, MAX_WIDTH, MIN_HEIGHT, MIN_SIZE, MIN_WIDTH, noTypstOf, USE_COPY_SHIM,} from './settings'import { DEFAULT_METRICS, refresh, S, type Env } from './state'import { resolveMode, settingOf } from './mode'@@ -73,7 +73,8 @@ export function setUp($: EngineInterface): Promise<Env> {S.isRemote = ssh// On this computer, where pictures draw: the clipboard shims, before Claude Code copies.if (!ssh && (S.hostOs === 'Darwin' || S.hostOs === 'Linux')) {- if (background) noShims('a background session')+ if (!USE_COPY_SHIM && !isSet(await envGet($, 'IUI_COPY_SHIM'))) noShims('the copy shims are off')+ else if (background) noShims('a background session')else if (!canDraw) noShims('no pictures in this terminal')// Never in the shared fallback folder.else if (made1.trim()) await setUpShims($, cache, S.hostOs === 'Darwin')diff --git a/hooks/lib/settings.ts b/hooks/lib/settings.tsindex b6bbcc0..c77aa86 100644--- a/hooks/lib/settings.ts+++ b/hooks/lib/settings.ts@@ -118,10 +118,14 @@ export const heightText = (height: Height) =>: `${height} rows`// The grid setting as words.export const gridText = (grid: boolean) => (grid ? 'on (each line of text on whole terminal rows)' : 'off')-// `/iui select`: picture select (select.ts), on by default; it takes effect-// from the Claude Code version whose own selection skips pictures.-export const SELECT_SINCE = '2.1.305'-export const selectText = (on: boolean) => (on ? 'on (select and copy picture text with the mouse, fullscreen, Claude Code 2.1.305+)' : 'off')+// `/iui select`: picture select (select.ts), on by default, from the oldest+// Claude Code the mod supports (the Client, ui.message, ui.blit and ui.copy are there).+export const SELECT_SINCE = '2.1.298'+export const selectText = (on: boolean) => (on ? 'on (select and copy picture text with the mouse, fullscreen)' : 'off')+// The copy shims (pbcopy, xclip, wl-copy) that ask the mod for the text of+// picture cells (clipboard.ts). Off: no shims folder, no PATH change, no ask+// FIFO, no answers. IUI_COPY_SHIM=1 turns them on for one session (tests too).+export const USE_COPY_SHIM = falseexport const PICTURES_KEPT = 64// The file paths of the link rows under a picture: whether each one is a// file, kept for this many paths (the oldest go).diff --git a/hooks/register.tsx b/hooks/register.tsxindex dbdad9e..fa0ec1d 100644--- a/hooks/register.tsx+++ b/hooks/register.tsx@@ -680,7 +680,7 @@ export const register: Register = on => {await storeSet($, 'select', S.select)}const head = asked.on === undefined ? 'Picture select is' : 'Picture select is now'- return { text: `${head} ${selectText(S.select)}. When on, a mouse drag over a picture selects its text and copies it; Claude Code 2.1.305 and newer no longer select pictures by themselves. Use /iui select on (the default), or /iui select off.` }+ return { text: `${head} ${selectText(S.select)}. When on, a mouse drag over a picture selects its text and copies it. Use /iui select on (the default), or /iui select off.` }}if (asked.kind === 'updates') {await loadUpdates($)diff --git a/tests/copy.test.ts b/tests/copy.test.tsindex 6f35f98..9d69451 100644--- a/tests/copy.test.ts+++ b/tests/copy.test.ts@@ -512,7 +512,7 @@ function world(on: any, o: { failFirst?: boolean; noBridge?: boolean; env?: RecoforgetRedraws()mock.store(on)const clock = mock.clock(on)- const vars: Record<string, string | undefined> = { PATH: '/usr/bin:/bin', ...(o.env ?? { HOME: '/h', CLAUDE_CODE_FORCE_TERMINAL_IMAGES: '1' }) }+ const vars: Record<string, string | undefined> = { PATH: '/usr/bin:/bin', IUI_COPY_SHIM: '1', ...(o.env ?? { HOME: '/h', CLAUDE_CODE_FORCE_TERMINAL_IMAGES: '1' }) }const envSets: [string, string | undefined][] = []on('env.get', async ($: any, e: any) => ({ value: vars[e.name] }))on('env.set', async ($: any, e: any) => {@@ -1567,8 +1567,8 @@ test('picture select: with no IUI_DEBUG, a post writes no trace line', async ($,expect(w.traces.filter(t => t.includes('select: '))).toEqual([])})-test('picture select: none before Claude Code 2.1.305', async ($, on) => {- const old = world(on, { tty: TTY, version: '2.1.304' })+test('picture select: none before Claude Code 2.1.298', async ($, on) => {+ const old = world(on, { tty: TTY, version: '2.1.297' })await $.command.run({ command: 'iui', args: '' } as any)const ui = await drawAnswer($, old)expect(tree(await ui.drawn()).some(n => n.type === 'Client')).toBe(false)diff --git a/tests/linux.test.ts b/tests/linux.test.tsindex d346987..9c93de0 100644--- a/tests/linux.test.ts+++ b/tests/linux.test.ts@@ -237,7 +237,7 @@ function linuxWorld(on: any, o: { scheme?: number; noPortal?: boolean; env?: Recmock.store(on)const clock = mock.clock(on)const vars: Record<string, string | undefined> = {- PATH: '/usr/local/bin:/usr/bin', ...(o.env ?? { HOME: '/h', TERM: 'xterm-kitty', KITTY_WINDOW_ID: '1', WAYLAND_DISPLAY: 'wayland-1', XDG_CURRENT_DESKTOP: 'sway' }),+ PATH: '/usr/local/bin:/usr/bin', IUI_COPY_SHIM: '1', ...(o.env ?? { HOME: '/h', TERM: 'xterm-kitty', KITTY_WINDOW_ID: '1', WAYLAND_DISPLAY: 'wayland-1', XDG_CURRENT_DESKTOP: 'sway' }),}on('env.get', async ($: any, e: any) => ({ value: vars[e.name] }))on('env.set', async ($: any, e: any) => {diff --git a/tests/select.test.ts b/tests/select.test.tsindex 0b13a18..3e250bc 100644--- a/tests/select.test.ts+++ b/tests/select.test.ts@@ -139,12 +139,13 @@ test('a selection over two pages is the text of each, one line apart; a page wit// ---- The gate ---------------------------------------------------------------------test('picture select is for Claude Code 2.1.305 and newer (a dev build by its release)', () => {- expect(needsSelect('2.1.305')).toBe(true)+test('picture select is for Claude Code 2.1.298 and newer (a dev build by its release)', () => {+ expect(needsSelect('2.1.298')).toBe(true)+ expect(needsSelect('2.1.304')).toBe(true)expect(needsSelect('2.1.306')).toBe(true)expect(needsSelect('2.2.0')).toBe(true)expect(needsSelect('2.1.306-dev')).toBe(true)- expect(needsSelect('2.1.304')).toBe(false)+ expect(needsSelect('2.1.297')).toBe(false)expect(needsSelect('2.0.999')).toBe(false)expect(needsSelect('')).toBe(false)expect(needsSelect('dev')).toBe(false)diff --git a/tests/shims.test.ts b/tests/shims.test.tsindex a7c0ea9..e2667d4 100644--- a/tests/shims.test.ts+++ b/tests/shims.test.ts@@ -184,7 +184,7 @@ test('a cache or shims folder that is not private (exit 3 at find or at install)test('no private cache folder (the cache script failed): no shim step, PATH not changed; details say why', async ($, on) => {const runs: string[][] = []const sets: string[] = []- on('env.get', async ($: any, e: any) => ({ value: ({ HOME: '/h', PATH: '/usr/bin', TERM_PROGRAM: 'ghostty' } as Record<string, string>)[e.name] }))+ on('env.get', async ($: any, e: any) => ({ value: ({ HOME: '/h', PATH: '/usr/bin', TERM_PROGRAM: 'ghostty', IUI_COPY_SHIM: '1' } as Record<string, string>)[e.name] }))on('env.set', async ($: any, e: any) => (sets.push(e.name), { value: {} }))// The cache script gives only the OS name: the shared fallback is for Typst only.on('process.run', async ($: any, e: any) => (runs.push(e.argv), /cc-intelligent-ui-/.test(e.argv.join(' ')) ? ok('\nDarwin\n\n') : ok('', 1)))@@ -201,7 +201,7 @@ for (const [what, vars, off] of [test(`${what}: no shims, PATH not changed; details say why`, async ($, on) => {const runs: string[][] = []const sets: string[] = []- on('env.get', async ($: any, e: any) => ({ value: ({ HOME: '/h', PATH: '/usr/bin', ...vars } as Record<string, string>)[e.name] }))+ on('env.get', async ($: any, e: any) => ({ value: ({ HOME: '/h', PATH: '/usr/bin', IUI_COPY_SHIM: '1', ...vars } as Record<string, string>)[e.name] }))on('env.set', async ($: any, e: any) => (sets.push(e.name), { value: {} }))on('process.run', async ($: any, e: any) => (runs.push(e.argv), /cc-intelligent-ui-/.test(e.argv.join(' ')) ? ok('/c\nDarwin\n') : ok('', 1)))const ran = await $.command.run({ command: 'iui', args: 'details' } as any)