We present a method for the detection and real-time control of chemical releases in channel flow. Sensor arrays capable of detecting a broad menu of chemical agents are required at strategic locations of the channel. The sensors detect the instantaneous, spatially distributed concentration of the chemical agent and transmit the associated information to a predictive control model. The model provides optimal operation scenarios for computer controlled bleed valves mounted on the channel walls and connected to a common manifold. Control and elimination of the chemical cloud are achieved by optimal blowing and suction of ambient fluid. Gradient information is obtained by use of adjoint equations, so optimization of the control actions is achieved with the highest possible efficiency. The control is optimized over a finite prediction horizon and instructions are sent to the valve manifold. Next, the sensor arrays detect all changes effected by the control and report them to the control model, which advances the process over the next control horizon. Non-reflective boundary conditions for the adjoint equations are derived by a characteristic analysis, which minimizes spurious information in the computation of sensitivities.